diff --git a/Cargo.lock b/Cargo.lock index 2f334a9..2469ede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,7 +805,7 @@ dependencies = [ [[package]] name = "goxkey" -version = "0.2.4" +version = "0.2.5" dependencies = [ "accessibility", "accessibility-sys", diff --git a/Cargo.toml b/Cargo.toml index c73a2eb..43a0fd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Bộ gõ tiếng Việt mã nguồn mở đa hệ điều hành Gõ Key" edition = "2021" name = "goxkey" -version = "0.2.4" +version = "0.2.5" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -33,4 +33,4 @@ copyright = "Copyright (c) Huy Tran 2023. All rights reserved." icon = ["icons/icon.icns", "icons/icon.png"] identifier = "com.goxkey.app" name = "GoKey" -version = "0.2.4" +version = "0.2.5" diff --git a/src/config.rs b/src/config.rs index 7feeb47..a40a2d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ pub struct ConfigStore { is_macro_enabled: bool, macro_table: BTreeMap, is_auto_toggle_enabled: bool, + is_gox_mode_enabled: bool, } fn parse_vec_string(line: String) -> Vec { @@ -75,7 +76,11 @@ impl ConfigStore { for (k, v) in self.macro_table.iter() { writeln!(file, "{} = {}", MACROS_CONFIG_KEY, build_kv_string(k, &v))?; } - + writeln!( + file, + "{} = {}", + GOX_MODE_CONFIG_KEY, self.is_gox_mode_enabled + )?; Ok(()) } @@ -88,6 +93,7 @@ impl ConfigStore { is_macro_enabled: false, macro_table: BTreeMap::new(), is_auto_toggle_enabled: false, + is_gox_mode_enabled: false, }; let config_path = ConfigStore::get_config_path(); @@ -112,6 +118,9 @@ impl ConfigStore { config.macro_table.insert(k, v); } } + GOX_MODE_CONFIG_KEY => { + config.is_gox_mode_enabled = matches!(right.trim(), "true") + } _ => {} } } @@ -176,6 +185,15 @@ impl ConfigStore { self.save(); } + pub fn is_gox_mode_enabled(&self) -> bool { + self.is_gox_mode_enabled + } + + pub fn set_gox_mode_enabled(&mut self, flag: bool) { + self.is_gox_mode_enabled = flag; + self.save(); + } + pub fn is_macro_enabled(&self) -> bool { self.is_macro_enabled } @@ -212,3 +230,4 @@ const EN_APPS_CONFIG_KEY: &str = "en-apps"; const MACRO_ENABLED_CONFIG_KEY: &str = "is_macro_enabled"; const AUTOS_TOGGLE_ENABLED_CONFIG_KEY: &str = "is_auto_toggle_enabled"; const MACROS_CONFIG_KEY: &str = "macros"; +const GOX_MODE_CONFIG_KEY: &str = "is_gox_mode_enabled"; diff --git a/src/input.rs b/src/input.rs index af6ab0d..6d35259 100644 --- a/src/input.rs +++ b/src/input.rs @@ -165,6 +165,7 @@ pub struct InputState { temporary_disabled: bool, previous_modifiers: KeyModifier, is_auto_toggle_enabled: bool, + is_gox_mode_enabled: bool, } impl InputState { @@ -184,6 +185,7 @@ impl InputState { temporary_disabled: false, previous_modifiers: KeyModifier::empty(), is_auto_toggle_enabled: config.is_auto_toggle_enabled(), + is_gox_mode_enabled: config.is_gox_mode_enabled(), } } @@ -209,6 +211,10 @@ impl InputState { self.temporary_disabled = true; } + pub fn is_gox_mode_enabled(&self) -> bool { + self.is_gox_mode_enabled + } + pub fn is_enabled(&self) -> bool { !self.temporary_disabled && self.enabled } diff --git a/src/ui.rs b/src/ui.rs index db8877f..c2f2886 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -158,12 +158,22 @@ impl UIDataAdapter { match self.is_enabled { true => { - self.systray.set_title("VN"); + self.systray + .set_title(if INPUT_STATE.is_gox_mode_enabled() { + "gõ" + } else { + "VN" + }); self.systray .set_menu_item_title(SystemTrayMenuItemKey::Enable, "Tắt gõ tiếng việt"); } false => { - self.systray.set_title("EN"); + self.systray + .set_title(if INPUT_STATE.is_gox_mode_enabled() { + "gox" + } else { + "EN" + }); self.systray .set_menu_item_title(SystemTrayMenuItemKey::Enable, "Bật gõ tiếng việt"); }