feat(core): wire up Welcome screen
This commit is contained in:
		
							parent
							
								
									a6ca1ee4c2
								
							
						
					
					
						commit
						ce3a1c456c
					
				|  | @ -35,6 +35,7 @@ use crate::{VERSION, exit_code::{ | |||
| use super::{CliModule, CliModuleArgs}; | ||||
| 
 | ||||
| mod ipc; | ||||
| mod ui; | ||||
| mod watcher; | ||||
| 
 | ||||
| pub fn new() -> CliModule { | ||||
|  | @ -55,6 +56,8 @@ fn daemon_main(args: CliModuleArgs) -> i32 { | |||
|   let config_store = args | ||||
|     .config_store | ||||
|     .expect("missing config store in worker main"); | ||||
|   let preferences = crate::preferences::get_default(&paths.runtime).expect("unable to obtain preferences"); | ||||
|   let cli_args = args.cli_args.expect("missing cli_args in daemon main"); | ||||
| 
 | ||||
|   // Make sure only one instance of the daemon is running
 | ||||
|   let lock_file = acquire_daemon_lock(&paths.runtime); | ||||
|  | @ -95,6 +98,10 @@ fn daemon_main(args: CliModuleArgs) -> i32 { | |||
|       .expect("unable to initialize config watcher thread"); | ||||
|   } | ||||
| 
 | ||||
|   if cli_args.is_present("show-welcome") { | ||||
|     ui::show_welcome_screen(&preferences); | ||||
|   } | ||||
| 
 | ||||
|   loop { | ||||
|     select! { | ||||
|       recv(watcher_signal) -> _ => { | ||||
|  |  | |||
							
								
								
									
										36
									
								
								espanso/src/cli/daemon/ui.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								espanso/src/cli/daemon/ui.rs
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | |||
| /* | ||||
|  * This file is part of espanso. | ||||
|  * | ||||
|  * Copyright (C) 2019-2021 Federico Terzi | ||||
|  * | ||||
|  * espanso is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * espanso is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with espanso.  If not, see <https://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| use crate::preferences::Preferences; | ||||
| 
 | ||||
| #[cfg(feature = "modulo")] | ||||
| pub fn show_welcome_screen(preferences: &impl Preferences) { | ||||
|   if preferences.should_display_welcome() { | ||||
|     let espanso_exe_path = std::env::current_exe().expect("unable to determine executable path"); | ||||
|     let mut command = std::process::Command::new(&espanso_exe_path.to_string_lossy().to_string()); | ||||
|     command.args(&["modulo", "welcome"]); | ||||
| 
 | ||||
|     command.spawn().expect("unable to show welcome screen"); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| #[cfg(not(feature = "modulo"))] | ||||
| pub fn show_welcome_screen(_: &impl Preferences) { | ||||
|   // NOOP  
 | ||||
| } | ||||
|  | @ -23,6 +23,8 @@ use super::{CliModule, CliModuleArgs}; | |||
| mod form; | ||||
| #[cfg(feature = "modulo")] | ||||
| mod search; | ||||
| #[cfg(feature = "modulo")] | ||||
| mod welcome; | ||||
| 
 | ||||
| pub fn new() -> CliModule { | ||||
|   #[allow(clippy::needless_update)] | ||||
|  | @ -49,6 +51,10 @@ fn modulo_main(args: CliModuleArgs) -> i32 { | |||
|     return search::search_main(matches, &icon_paths); | ||||
|   } | ||||
| 
 | ||||
|   if let Some(_) = cli_args.subcommand_matches("welcome") { | ||||
|     return welcome::welcome_main(&paths, &icon_paths); | ||||
|   } | ||||
| 
 | ||||
|   0 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										48
									
								
								espanso/src/cli/modulo/welcome.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								espanso/src/cli/modulo/welcome.rs
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,48 @@ | |||
| /* | ||||
|  * This file is part of espanso. | ||||
|  * | ||||
|  * Copyright (C) 2019-2021 Federico Terzi | ||||
|  * | ||||
|  * espanso is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * espanso is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with espanso.  If not, see <https://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| use crate::icon::IconPaths; | ||||
| use crate::preferences::Preferences; | ||||
| use espanso_modulo::welcome::*; | ||||
| use espanso_path::Paths; | ||||
| 
 | ||||
| pub fn welcome_main(paths: &Paths, icon_paths: &IconPaths) -> i32 { | ||||
|   let preferences = | ||||
|     crate::preferences::get_default(&paths.runtime).expect("unable to initialize preferences"); | ||||
| 
 | ||||
|   let dont_show_again_handler = Box::new(move |dont_show: bool| { | ||||
|     preferences.set_should_display_welcome(!dont_show); | ||||
|   }); | ||||
| 
 | ||||
|   espanso_modulo::welcome::show(WelcomeOptions{ | ||||
|     window_icon_path: icon_paths | ||||
|       .wizard_icon | ||||
|       .as_ref() | ||||
|       .map(|path| path.to_string_lossy().to_string()), | ||||
|     tray_image_path: icon_paths | ||||
|       .tray_explain_image | ||||
|       .as_ref() | ||||
|       .map(|path| path.to_string_lossy().to_string()), | ||||
|     handlers: WelcomeHandlers { | ||||
|       dont_show_again_changed: Some(dont_show_again_handler), | ||||
|     }, | ||||
|   }); | ||||
| 
 | ||||
|   0 | ||||
| } | ||||
|  | @ -30,6 +30,8 @@ const WINDOWS_NORMAL_DARK_ICO_BINARY: &[u8] = include_bytes!("res/windows/normal | |||
| const WINDOWS_DISABLED_DARK_ICO_BINARY: &[u8] = include_bytes!("res/windows/disabled_dark.ico"); | ||||
| #[cfg(target_os = "windows")] | ||||
| const WINDOWS_LOGO_ICO_BINARY: &[u8] = include_bytes!("res/windows/logo.ico"); | ||||
| #[cfg(target_os = "windows")] | ||||
| const WINDOWS_TRAY_EXPLAIN_IMAGE: &[u8] = include_bytes!("res/windows/tray_explain_image.png"); | ||||
| 
 | ||||
| 
 | ||||
| #[cfg(target_os = "macos")] | ||||
|  | @ -55,6 +57,7 @@ pub struct IconPaths { | |||
| 
 | ||||
|   pub accessibility_image_1: Option<PathBuf>, | ||||
|   pub accessibility_image_2: Option<PathBuf>, | ||||
|   pub tray_explain_image: Option<PathBuf>, | ||||
| 
 | ||||
|   pub logo: Option<PathBuf>, 
 | ||||
|   pub logo_no_background: Option<PathBuf>, | ||||
|  | @ -70,6 +73,7 @@ pub fn load_icon_paths(runtime_dir: &Path) -> Result<IconPaths> { | |||
|     tray_icon_disabled: Some(extract_icon(WINDOWS_DISABLED_DARK_ICO_BINARY, &runtime_dir.join("disabled.ico"))?), | ||||
|     logo: Some(extract_icon(ICON_BINARY, &runtime_dir.join("icon.png"))?), | ||||
|     logo_no_background: Some(extract_icon(LOGO_NO_BACKGROUND_BINARY, &runtime_dir.join("icon_no_background.png"))?), | ||||
|     tray_explain_image: Some(extract_icon(WINDOWS_TRAY_EXPLAIN_IMAGE, &runtime_dir.join("tray_explain_image.png"))?), | ||||
|     ..Default::default() | ||||
|   }) | ||||
| } | ||||
|  |  | |||
|  | @ -163,6 +163,12 @@ fn main() { | |||
|     .subcommand( | ||||
|       SubCommand::with_name("daemon") | ||||
|         .setting(AppSettings::Hidden) | ||||
|         .arg( | ||||
|           Arg::with_name("show-welcome") | ||||
|             .long("show-welcome") | ||||
|             .required(false) | ||||
|             .takes_value(false) | ||||
|         ) | ||||
|         .about("Start the daemon without spawning a new process."), | ||||
|     ) | ||||
|     // .subcommand(SubCommand::with_name("register")
 | ||||
|  | @ -207,6 +213,10 @@ fn main() { | |||
|                 .takes_value(false) | ||||
|                 .help("Interpret the input data as JSON"), | ||||
|             ), | ||||
|         ) | ||||
|         .subcommand( | ||||
|           SubCommand::with_name("welcome") | ||||
|             .about("Display the welcome screen") | ||||
|         ), | ||||
|     ) | ||||
|     // .subcommand(SubCommand::with_name("start")
 | ||||
|  |  | |||
|  | @ -19,13 +19,13 @@ | |||
| 
 | ||||
| use espanso_kvs::KVS; | ||||
| use serde::{de::DeserializeOwned, Serialize}; | ||||
| use std::path::Path; | ||||
| 
 | ||||
| use anyhow::Result; | ||||
| 
 | ||||
| use super::Preferences; | ||||
| 
 | ||||
| const HAS_COMPLETED_WIZARD_KEY: &str = "has_completed_wizard"; | ||||
| const SHOULD_DISPLAY_WELCOME_KEY: &str = "should_display_welcome"; | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub struct DefaultPreferences<KVSType: KVS> { | ||||
|  | @ -33,7 +33,7 @@ pub struct DefaultPreferences<KVSType: KVS> { | |||
| } | ||||
| 
 | ||||
| impl<KVSType: KVS> DefaultPreferences<KVSType> { | ||||
|   pub fn new(runtime_dir: &Path, kvs: KVSType) -> Result<Self> { | ||||
|   pub fn new(kvs: KVSType) -> Result<Self> { | ||||
|     Ok(Self { kvs }) | ||||
|   } | ||||
| 
 | ||||
|  | @ -61,4 +61,12 @@ impl<KVSType: KVS> Preferences for DefaultPreferences<KVSType> { | |||
|   fn set_completed_wizard(&self, value: bool) { | ||||
|     self.set(HAS_COMPLETED_WIZARD_KEY, value); | ||||
|   } | ||||
| 
 | ||||
|   fn should_display_welcome(&self) -> bool { | ||||
|     self.get(SHOULD_DISPLAY_WELCOME_KEY).unwrap_or(true) | ||||
|   } | ||||
| 
 | ||||
|   fn set_should_display_welcome(&self, value: bool) { | ||||
|     self.set(SHOULD_DISPLAY_WELCOME_KEY, value); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -25,9 +25,12 @@ mod default; | |||
| pub trait Preferences: Send + Sync + Clone { | ||||
|   fn has_completed_wizard(&self) -> bool; | ||||
|   fn set_completed_wizard(&self, value: bool); | ||||
| 
 | ||||
|   fn should_display_welcome(&self) -> bool; | ||||
|   fn set_should_display_welcome(&self, value: bool); | ||||
| } | ||||
| 
 | ||||
| pub fn get_default(runtime_dir: &Path) -> Result<impl Preferences> { | ||||
|   let kvs = espanso_kvs::get_persistent(runtime_dir)?; | ||||
|   default::DefaultPreferences::new(runtime_dir, kvs) | ||||
|   default::DefaultPreferences::new(kvs) | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								espanso/src/res/windows/tray_explain_image.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								espanso/src/res/windows/tray_explain_image.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 15 KiB | 
		Loading…
	
		Reference in New Issue
	
	Block a user