Преглед изворни кода

wallet: add a beautiful popup telling the user to upgrade their app when the server version is higher than the app's version

darkfi пре 1 година
родитељ
комит
c903e0d3be
3 измењених фајлова са 99 додато и 23 уклоњено
  1. 68 0
      bin/darkwallet/src/app/schema.rs
  2. 13 2
      bin/darkwallet/src/darkirc2.rs
  3. 18 21
      bin/darkwallet/src/ui/layer.rs

+ 68 - 0
bin/darkwallet/src/app/schema.rs

@@ -811,4 +811,72 @@ pub(super) async fn make(app: &App, window: SceneNodePtr) {
 
     let node = node.setup(|me| Button::new(me, app.ex.clone())).await;
     layer_node.clone().link(node);
+
+    // Create a popup layer to show upgrade msg
+    let node = create_layer("upgrade_popup");
+    let prop = node.get_property("rect").unwrap();
+    prop.set_f32(Role::App, 0, 0.).unwrap();
+    prop.set_f32(Role::App, 1, 0.).unwrap();
+    prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
+    let code = cc.compile("h / 2").unwrap();
+    prop.set_expr(Role::App, 3, code).unwrap();
+    node.set_property_bool(Role::App, "is_visible", false).unwrap();
+    node.set_property_u32(Role::App, "z_index", 10).unwrap();
+    let popup_layer_node =
+        node.setup(|me| Layer::new(me, app.render_api.clone(), app.ex.clone())).await;
+    layer_node.clone().link(popup_layer_node.clone());
+
+    // Background for popup
+    let node = create_vector_art("upgradebg");
+    let prop = node.get_property("rect").unwrap();
+    prop.set_f32(Role::App, 0, 0.).unwrap();
+    prop.set_f32(Role::App, 1, 0.).unwrap();
+    prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
+    prop.set_expr(Role::App, 3, expr::load_var("h")).unwrap();
+    node.set_property_u32(Role::App, "z_index", 0).unwrap();
+
+    // Setup the pimpl
+    let verts = vec![
+        ShapeVertex::from_xy(0., 0., [1., 0., 0., 1.]),
+        ShapeVertex::new(expr::load_var("w"), expr::const_f32(0.), [1., 0., 1., 1.]),
+        ShapeVertex::new(expr::const_f32(0.), expr::load_var("h"), [0., 0., 1., 1.]),
+        ShapeVertex::new(expr::load_var("w"), expr::load_var("h"), [1., 1., 0., 1.]),
+    ];
+    let indices = vec![0, 2, 1, 1, 2, 3];
+    let shape = VectorShape { verts, indices };
+    let node =
+        node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
+    popup_layer_node.clone().link(node);
+
+    // Create some text
+    let node = create_text("send_label");
+    let prop = node.get_property("rect").unwrap();
+    prop.set_f32(Role::App, 0, 10.).unwrap();
+    prop.set_f32(Role::App, 1, 10.).unwrap();
+    prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
+    prop.set_expr(Role::App, 3, expr::load_var("h")).unwrap();
+    node.set_property_f32(Role::App, "baseline", TEXTBAR_BASELINE).unwrap();
+    node.set_property_f32(Role::App, "font_size", 2. * FONTSIZE).unwrap();
+    node.set_property_str(Role::App, "text", "YO THERE'S A NEW VERSION!!! UPGRADE TIEM!!!")
+        .unwrap();
+    //node.set_property_str(Role::App, "text", "anon1").unwrap();
+    let prop = node.get_property("text_color").unwrap();
+    prop.set_f32(Role::App, 0, 0.).unwrap();
+    prop.set_f32(Role::App, 1, 1.).unwrap();
+    prop.set_f32(Role::App, 2, 0.94).unwrap();
+    prop.set_f32(Role::App, 3, 1.).unwrap();
+    node.set_property_u32(Role::App, "z_index", 1).unwrap();
+
+    let node = node
+        .setup(|me| {
+            Text::new(
+                me,
+                window_scale.clone(),
+                app.render_api.clone(),
+                app.text_shaper.clone(),
+                app.ex.clone(),
+            )
+        })
+        .await;
+    popup_layer_node.clone().link(node);
 }

+ 13 - 2
bin/darkwallet/src/darkirc2.rs

@@ -48,7 +48,7 @@ use std::{
 use url::Url;
 
 use crate::{
-    prop::{PropertyStr, Role},
+    prop::{PropertyBool, PropertyStr, Role},
     scene::{SceneNodePtr, Slot},
 };
 
@@ -86,6 +86,7 @@ pub struct LocalDarkIRC {
     sendbtn_node: SceneNodePtr,
     editbox_node: SceneNodePtr,
     editbox_text: PropertyStr,
+    upgrade_popup_is_visible: PropertyBool,
 }
 
 impl LocalDarkIRC {
@@ -93,9 +94,13 @@ impl LocalDarkIRC {
         let chatview_node = sg_root.clone().lookup_node("/window/view/chatty").unwrap();
         let sendbtn_node = sg_root.clone().lookup_node("/window/view/send_btn").unwrap();
 
-        let editbox_node = sg_root.lookup_node("/window/view/editz").unwrap();
+        let editbox_node = sg_root.clone().lookup_node("/window/view/editz").unwrap();
         let editbox_text = PropertyStr::wrap(&editbox_node, Role::App, "text", 0).unwrap();
 
+        let upgrade_popup_node = sg_root.clone().lookup_node("/window/view/upgrade_popup").unwrap();
+        let upgrade_popup_is_visible =
+            PropertyBool::wrap(&upgrade_popup_node, Role::App, "is_visible", 0).unwrap();
+
         info!(target: "darkirc", "Instantiating DarkIRC event DAG");
         let datastore = expand_path(EVGRDB_PATH)?;
         fs::create_dir_all(&datastore).await?;
@@ -115,11 +120,13 @@ impl LocalDarkIRC {
             sendbtn_node,
             editbox_node,
             editbox_text,
+            upgrade_popup_is_visible,
         }))
     }
 
     async fn reconnect(&self) -> Result<()> {
         let endpoint = "tcp://127.0.0.1:5588";
+        let endpoint = "tcp://192.168.1.38:5588";
         let endpoint = Url::parse(endpoint)?;
 
         let dialer = Dialer::new(endpoint.clone(), None).await?;
@@ -198,6 +205,10 @@ impl LocalDarkIRC {
         let server_version = VersionMessage::decode_async(reader).await?;
         info!(target: "darkirc", "Backend server version: {}", server_version.protocol_version);
 
+        if server_version.protocol_version > evgrd::PROTOCOL_VERSION {
+            self.upgrade_popup_is_visible.set(true);
+        }
+
         let unref_tips = self.evgr.unreferenced_tips.read().await.clone();
         let fetchevs = FetchEventsMessage::new(unref_tips);
         MSG_FETCHEVENTS.encode_async(writer).await?;

+ 18 - 21
bin/darkwallet/src/ui/layer.rs

@@ -61,7 +61,9 @@ impl Layer {
 
         let self_ = Arc::new_cyclic(|me: &Weak<Self>| {
             let mut on_modify = OnModify::new(ex.clone(), node_name, node_id, me.clone());
+            on_modify.when_change(is_visible.prop(), Self::redraw);
             on_modify.when_change(rect.prop(), Self::redraw);
+            on_modify.when_change(z_index.prop(), Self::redraw);
 
             Self {
                 node,
@@ -108,23 +110,27 @@ impl Layer {
         let mut freed_textures = vec![];
         let mut freed_buffers = vec![];
 
-        for child in self.get_children() {
-            let obj = get_ui_object3(&child);
-            let Some(mut draw_update) = obj.draw(rect).await else {
-                debug!(target: "ui::layer", "Skipped draw() of {child:?}");
-                continue
-            };
-
-            draw_calls.append(&mut draw_update.draw_calls);
-            child_calls.push(draw_update.key);
-            freed_textures.append(&mut draw_update.freed_textures);
-            freed_buffers.append(&mut draw_update.freed_buffers);
+        // We should return a draw call so that if the layer is made visible, we can just
+        // recalculate it and update in place.
+        if self.is_visible.get() {
+            for child in self.get_children() {
+                let obj = get_ui_object3(&child);
+                let Some(mut draw_update) = obj.draw(rect).await else {
+                    debug!(target: "ui::layer", "Skipped draw() of {child:?}");
+                    continue
+                };
+
+                draw_calls.append(&mut draw_update.draw_calls);
+                child_calls.push(draw_update.key);
+                freed_textures.append(&mut draw_update.freed_textures);
+                freed_buffers.append(&mut draw_update.freed_buffers);
+            }
         }
 
         let dc = GfxDrawCall {
             instrs: vec![GfxDrawInstruction::ApplyView(rect)],
             dcs: child_calls,
-            z_index: 0,
+            z_index: self.z_index(),
         };
         draw_calls.push((self.dc_key, dc));
         Some(DrawUpdate { key: self.dc_key, draw_calls, freed_textures, freed_buffers })
@@ -141,15 +147,6 @@ impl UIObject for Layer {
         debug!(target: "ui::layer", "Layer::draw()");
         *self.parent_rect.lock().unwrap() = Some(parent_rect);
 
-        // If we are invisible, then when layer is made visible again, the children
-        // draw calls will be recalculated and they will get the updated parent_rect.
-        if !self.is_visible.get() {
-            debug!(target: "ui::layer", "invisible layer node");
-            return None
-        }
-
-        debug!(target: "ui::layer", "Parent rect: {:?}", parent_rect);
-
         /*
         if !parent_rect.dim().contains(&offset_rect) {
             error!(