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

wallet: display a message for first time users telling them to be patient

darkfi пре 1 година
родитељ
комит
a6da48e254

+ 21 - 5
bin/darkwallet/src/app/schema/chat.rs

@@ -37,12 +37,12 @@ use crate::{
     prop::{
     prop::{
         Property, PropertyBool, PropertyFloat32, PropertyStr, PropertySubType, PropertyType, Role,
         Property, PropertyBool, PropertyFloat32, PropertyStr, PropertySubType, PropertyType, Role,
     },
     },
-    scene::{SceneNodePtr, Slot},
+    scene::{Pimpl, SceneNodePtr, Slot},
     shape,
     shape,
     text::TextShaperPtr,
     text::TextShaperPtr,
     ui::{
     ui::{
-        emoji_picker, Button, ChatEdit, ChatView, EditBox, EmojiPicker, Image, Layer, ShapeVertex,
-        Shortcut, Text, VectorArt, VectorShape, Window,
+        chatview, emoji_picker, Button, ChatEdit, ChatView, EditBox, EmojiPicker, Image, Layer,
+        ShapeVertex, Shortcut, Text, VectorArt, VectorShape, Window,
     },
     },
     util::{unixtime, Clipboard},
     util::{unixtime, Clipboard},
     ExecutorPtr,
     ExecutorPtr,
@@ -187,6 +187,7 @@ pub async fn make(
     channel: &str,
     channel: &str,
     db: &sled::Db,
     db: &sled::Db,
     emoji_meshes: emoji_picker::EmojiMeshesPtr,
     emoji_meshes: emoji_picker::EmojiMeshesPtr,
+    is_first_time: bool,
 ) {
 ) {
     let window_scale = PropertyFloat32::wrap(&window, Role::Internal, "scale", 0).unwrap();
     let window_scale = PropertyFloat32::wrap(&window, Role::Internal, "scale", 0).unwrap();
 
 
@@ -314,6 +315,8 @@ pub async fn make(
     node.set_property_str(Role::App, "key", "back").unwrap();
     node.set_property_str(Role::App, "key", "back").unwrap();
     #[cfg(not(target_os = "android"))]
     #[cfg(not(target_os = "android"))]
     node.set_property_str(Role::App, "key", "alt+left").unwrap();
     node.set_property_str(Role::App, "key", "alt+left").unwrap();
+    // Not sure what was eating my keys. This is a workaround.
+    node.set_property_u32(Role::App, "priority", 10).unwrap();
 
 
     let (slot, recvr) = Slot::new("back_pressed");
     let (slot, recvr) = Slot::new("back_pressed");
     node.register("shortcut", slot).unwrap();
     node.register("shortcut", slot).unwrap();
@@ -562,6 +565,19 @@ pub async fn make(
         .await;
         .await;
     layer_node.clone().link(chatview_node.clone());
     layer_node.clone().link(chatview_node.clone());
 
 
+    if is_first_time {
+        let chatview = match &chatview_node.pimpl {
+            Pimpl::ChatView(obj) => obj.as_ref(),
+            _ => panic!("wrong pimpl for chatview"),
+        };
+        chatview.handle_insert_line(
+            unixtime(),
+            chatview::MessageId(rand::random()),
+            "NOTICE".to_string(),
+            "This is your first time connecting. Please be patient while the network syncs. We will fix this in future releases".to_string()
+        ).await;
+    }
+
     // Create the editbox bg
     // Create the editbox bg
     let node = create_vector_art("editbox_bg");
     let node = create_vector_art("editbox_bg");
     let prop = node.get_property("rect").unwrap();
     let prop = node.get_property("rect").unwrap();
@@ -1626,8 +1642,8 @@ pub async fn make(
             // We want to avoid setting the property multiple times to the same value
             // We want to avoid setting the property multiple times to the same value
             // because then it triggers unnecessary redraw work.
             // because then it triggers unnecessary redraw work.
 
 
-            // Only show popup for "/ni", "/nick", but not for: "/nick ", "/nick foo"
-            if "/nick".starts_with(&text) && text.len() <= "/nick".len() {
+            // Only show popup for "/ni", "/nick", but not for: "", "/nick ", "/nick foo"
+            if !text.is_empty() && "/nick".starts_with(&text) && text.len() <= "/nick".len() {
                 if !cmd_hint_is_visible.get() {
                 if !cmd_hint_is_visible.get() {
                     cmd_hint_is_visible.set(true);
                     cmd_hint_is_visible.set(true);
                 }
                 }

+ 22 - 12
bin/darkwallet/src/app/schema/mod.rs

@@ -17,6 +17,7 @@
  */
  */
 
 
 use sled_overlay::sled;
 use sled_overlay::sled;
+use std::fs::File;
 
 
 use crate::{
 use crate::{
     app::{
     app::{
@@ -55,27 +56,37 @@ mod android_ui_consts {
 
 
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
 mod ui_consts {
 mod ui_consts {
+    use crate::android::get_appdata_path;
     use std::path::PathBuf;
     use std::path::PathBuf;
 
 
     pub const BG_PATH: &str = "bg.png";
     pub const BG_PATH: &str = "bg.png";
     pub use super::android_ui_consts::*;
     pub use super::android_ui_consts::*;
 
 
     pub fn get_chatdb_path() -> PathBuf {
     pub fn get_chatdb_path() -> PathBuf {
-        use crate::android::get_appdata_path;
         get_appdata_path().join("chatdb")
         get_appdata_path().join("chatdb")
     }
     }
+    pub fn get_first_time_filename() -> PathBuf {
+        get_appdata_path().join("first_time")
+    }
 }
 }
 
 
-#[cfg(feature = "emulate-android")]
-mod ui_consts {
+#[cfg(not(target_os = "android"))]
+mod desktop_paths {
     use std::path::PathBuf;
     use std::path::PathBuf;
 
 
     pub const BG_PATH: &str = "assets/bg.png";
     pub const BG_PATH: &str = "assets/bg.png";
-    pub use super::android_ui_consts::*;
 
 
     pub fn get_chatdb_path() -> PathBuf {
     pub fn get_chatdb_path() -> PathBuf {
         dirs::cache_dir().unwrap().join("darkfi/chatdb")
         dirs::cache_dir().unwrap().join("darkfi/chatdb")
     }
     }
+    pub fn get_first_time_filename() -> PathBuf {
+        dirs::cache_dir().unwrap().join("darkfi/first_time")
+    }
+}
+
+#[cfg(feature = "emulate-android")]
+mod ui_consts {
+    pub use super::{android_ui_consts::*, desktop_paths::*};
 }
 }
 
 
 #[cfg(all(
 #[cfg(all(
@@ -83,14 +94,8 @@ mod ui_consts {
     not(feature = "emulate-android")
     not(feature = "emulate-android")
 ))]
 ))]
 mod ui_consts {
 mod ui_consts {
-    use std::path::PathBuf;
-
-    pub const BG_PATH: &str = "assets/bg.png";
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 40.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 40.;
-
-    pub fn get_chatdb_path() -> PathBuf {
-        dirs::cache_dir().unwrap().join("darkfi/chatdb")
-    }
+    pub use super::desktop_paths::*;
 }
 }
 
 
 use ui_consts::*;
 use ui_consts::*;
@@ -230,10 +235,15 @@ pub async fn make(app: &App, window: SceneNodePtr) {
         }
         }
     });
     });
 
 
+    let is_first_time = !get_first_time_filename().exists();
+    if is_first_time {
+        let _ = File::create(get_first_time_filename());
+    }
+
     let chatdb_path = get_chatdb_path();
     let chatdb_path = get_chatdb_path();
     let db = sled::open(chatdb_path).expect("cannot open sleddb");
     let db = sled::open(chatdb_path).expect("cannot open sleddb");
     for channel in CHANNELS {
     for channel in CHANNELS {
-        chat::make(app, window.clone(), channel, &db, emoji_meshes.clone()).await;
+        chat::make(app, window.clone(), channel, &db, emoji_meshes.clone(), is_first_time).await;
     }
     }
     menu::make(app, window.clone()).await;
     menu::make(app, window.clone()).await;
 
 

+ 1 - 1
bin/darkwallet/src/ui/chatview/mod.rs

@@ -420,7 +420,7 @@ impl ChatView {
         let _ = self.tree.flush_async().await;
         let _ = self.tree.flush_async().await;
         true
         true
     }
     }
-    async fn handle_insert_line(
+    pub async fn handle_insert_line(
         &self,
         &self,
         timest: Timestamp,
         timest: Timestamp,
         msg_id: MessageId,
         msg_id: MessageId,