feat(core): show welcome UI only once after the engine has successfuly initialized

This commit is contained in:
Federico Terzi 2021-07-27 23:12:22 +02:00
parent c82690ba61
commit 6a558f74c7
10 changed files with 33 additions and 53 deletions

View File

@ -42,7 +42,6 @@ use super::{CliModule, CliModuleArgs, PathsOverrides};
mod ipc;
mod troubleshoot;
mod ui;
mod watcher;
pub fn new() -> CliModule {
@ -62,9 +61,6 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
let paths_overrides = args
.paths_overrides
.expect("missing paths_overrides in daemon 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);
@ -132,10 +128,6 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
ipc::initialize_and_spawn(&paths.runtime, exit_notify.clone())
.expect("unable to initialize ipc server for daemon");
if cli_args.is_present("show-welcome") {
ui::show_welcome_screen(&preferences);
}
loop {
select! {
recv(watcher_signal) -> _ => {

View File

@ -25,14 +25,10 @@ use thiserror::Error;
use crate::cli::PathsOverrides;
use crate::cli::util::CommandExt;
pub fn launch_daemon(paths_overrides: &PathsOverrides, show_welcome: bool) -> Result<()> {
pub fn launch_daemon(paths_overrides: &PathsOverrides) -> Result<()> {
let espanso_exe_path = std::env::current_exe()?;
let mut command = Command::new(&espanso_exe_path.to_string_lossy().to_string());
let mut args = vec!["daemon"];
if show_welcome {
args.push("--show-welcome");
}
command.args(&args);
command.args(&["daemon"]);
command.with_paths_overrides(paths_overrides);
let mut child = command.spawn()?;

View File

@ -64,7 +64,6 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
let preferences =
crate::preferences::get_default(&paths.runtime).expect("unable to initialize preferences");
let is_first_start = !preferences.has_completed_wizard();
let is_welcome_page_enabled = !preferences.has_completed_wizard();
@ -184,7 +183,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
espanso_mac_utils::convert_to_background_app();
}
daemon::launch_daemon(&paths_overrides, is_first_start).expect("failed to launch daemon");
daemon::launch_daemon(&paths_overrides).expect("failed to launch daemon");
}
LAUNCHER_SUCCESS

View File

@ -19,16 +19,13 @@
use clap::{ArgMatches};
use crate::icon::IconPaths;
use crate::preferences::Preferences;
use espanso_modulo::welcome::*;
use espanso_path::Paths;
pub fn welcome_main(matches: &ArgMatches, 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);
//preferences.set_should_display_welcome(!dont_show);
// TODO: this should probably be deleted if not used?
});
let is_already_running = matches.is_present("already-running");

View File

@ -28,8 +28,7 @@ use espanso_path::Paths;
use espanso_ui::{event::UIEvent, UIRemote};
use log::{debug, error, info, warn};
use crate::{
cli::worker::{
use crate::{cli::worker::{
engine::{
dispatch::executor::{
clipboard_injector::ClipboardInjectorAdapter, context_menu::ContextMenuHandlerAdapter,
@ -52,9 +51,7 @@ use crate::{
},
},
match_cache::MatchCache,
},
engine::event::ExitMode,
};
}, engine::event::ExitMode, preferences::Preferences};
use super::secure_input::SecureInputEvent;
@ -79,6 +76,7 @@ pub fn initialize_and_spawn(
.name("engine thread".to_string())
.spawn(move || {
// TODO: properly order the initializations if necessary
let preferences = crate::preferences::get_default(&paths.runtime).expect("unable to load preferences");
let app_info_provider =
espanso_info::get_provider().expect("unable to initialize app info provider");
@ -215,7 +213,14 @@ pub fn initialize_and_spawn(
// TODO: check config
match run_count {
0 => ui_remote.show_notification("Espanso is running!"),
0 => {
ui_remote.show_notification("Espanso is running!");
if !preferences.has_displayed_welcome() {
super::ui::welcome::show_welcome_screen();
preferences.set_has_displayed_welcome(true);
}
},
n => {
if has_been_started_manually {
ui_remote.show_notification("Configuration reloaded!");

View File

@ -17,4 +17,5 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
pub mod util;
pub mod util;
pub mod welcome;

View File

@ -17,20 +17,16 @@
* 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"]);
pub fn show_welcome_screen() {
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");
}
command.spawn().expect("unable to show welcome screen");
}
#[cfg(not(feature = "modulo"))]
pub fn show_welcome_screen(_: &impl Preferences) {
// NOOP
}
pub fn show_welcome_screen() {
// NOOP
}

View File

@ -192,12 +192,6 @@ 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")

View File

@ -25,7 +25,7 @@ use anyhow::Result;
use super::Preferences;
const HAS_COMPLETED_WIZARD_KEY: &str = "has_completed_wizard";
const SHOULD_DISPLAY_WELCOME_KEY: &str = "should_display_welcome";
const HAS_DISPLAYED_WELCOME_KEY: &str = "has_displayed_welcome";
const SHOULD_DISPLAY_TROUBLESHOOT_FOR_NON_FATAL_ERRORS: &str =
"should_display_troubleshoot_for_non_fatal_errors";
@ -64,12 +64,12 @@ impl<KVSType: KVS> Preferences for DefaultPreferences<KVSType> {
self.set(HAS_COMPLETED_WIZARD_KEY, value);
}
fn should_display_welcome(&self) -> bool {
self.get(SHOULD_DISPLAY_WELCOME_KEY).unwrap_or(true)
fn has_displayed_welcome(&self) -> bool {
self.get(HAS_DISPLAYED_WELCOME_KEY).unwrap_or(false)
}
fn set_should_display_welcome(&self, value: bool) {
self.set(SHOULD_DISPLAY_WELCOME_KEY, value);
fn set_has_displayed_welcome(&self, value: bool) {
self.set(HAS_DISPLAYED_WELCOME_KEY, value);
}
fn should_display_troubleshoot_for_non_fatal_errors(&self) -> bool {

View File

@ -26,8 +26,8 @@ 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);
fn has_displayed_welcome(&self) -> bool;
fn set_has_displayed_welcome(&self, value: bool);
fn should_display_troubleshoot_for_non_fatal_errors(&self) -> bool;
fn set_should_display_troubleshoot_for_non_fatal_errors(&self, value: bool);