Skip to content

Commit

Permalink
feature: Implement gox_mode (alternative system tray icon)
Browse files Browse the repository at this point in the history
To use this mode, manually edit the ~/.goxkey config file and add the following line:

  is_gox_mode_enabled = true

Then restart goxkey.
  • Loading branch information
huytd committed Apr 10, 2024
1 parent 5c63ccd commit 62cf1b5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
21 changes: 20 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct ConfigStore {
is_macro_enabled: bool,
macro_table: BTreeMap<String, String>,
is_auto_toggle_enabled: bool,
is_gox_mode_enabled: bool,
}

fn parse_vec_string(line: String) -> Vec<String> {
Expand Down Expand Up @@ -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(())
}

Expand All @@ -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();
Expand All @@ -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")
}
_ => {}
}
}
Expand Down Expand Up @@ -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) {

Check warning on line 192 in src/config.rs

View workflow job for this annotation

GitHub Actions / Test project

method `set_gox_mode_enabled` is never used

Check warning on line 192 in src/config.rs

View workflow job for this annotation

GitHub Actions / Build project

method `set_gox_mode_enabled` is never used
self.is_gox_mode_enabled = flag;
self.save();
}

pub fn is_macro_enabled(&self) -> bool {
self.is_macro_enabled
}
Expand Down Expand Up @@ -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";
6 changes: 6 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}

Expand All @@ -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
}
Expand Down
14 changes: 12 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 62cf1b5

Please sign in to comment.