From fbca818254a7303dea979b5257c705ec04bf0fa3 Mon Sep 17 00:00:00 2001 From: amorphobia Date: Mon, 30 Sep 2024 20:57:25 +0800 Subject: [PATCH] feat: support schema custom icons --- Lib/RabbitCommon.ahk | 21 +++++++++++++++++++++ Lib/RabbitTrayMenu.ahk | 5 ++++- Rabbit.ahk | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Lib/RabbitCommon.ahk b/Lib/RabbitCommon.ahk index 6dcab87..86ef898 100644 --- a/Lib/RabbitCommon.ahk +++ b/Lib/RabbitCommon.ahk @@ -61,6 +61,7 @@ class RabbitGlobals { static process_ascii := Map() static on_tray_icon_click := false static active_win := "" + static current_schema_icon := "" } class RabbitMutex { @@ -144,6 +145,7 @@ class RabbitConfig { static show_tips_time := 1200 static global_ascii := false static preset_process_ascii := Map() + static schema_icon := Map() static load() { global rime @@ -174,5 +176,24 @@ class RabbitConfig { } rime.config_close(config) + + if !schema_list := rime.get_schema_list() + return + + Loop schema_list.size { + local item := schema_list.list[A_Index] + if !schema := rime.schema_open(item.schema_id) + continue + + if rime.config_test_get_string(schema, "schema/icon", &icon) { + icon_path := RabbitUserDataPath() . "\" . LTrim(icon, "\") + RabbitConfig.schema_icon[item.schema_id] := icon_path + } else + RabbitConfig.schema_icon[item.schema_id] := "" + + rime.config_close(schema) + } + + rime.free_schema_list(schema_list) } } diff --git a/Lib/RabbitTrayMenu.ahk b/Lib/RabbitTrayMenu.ahk index fe897e9..1e81006 100644 --- a/Lib/RabbitTrayMenu.ahk +++ b/Lib/RabbitTrayMenu.ahk @@ -140,5 +140,8 @@ UpdateTrayTip(schema_name := TRAY_SCHEMA_NAME, ascii_mode := TRAY_ASCII_MODE, fu UpdateTrayIcon() { global TRAY_ASCII_MODE - TraySetIcon((A_IsSuspended || IN_MAINTENANCE) ? "Lib\rabbit-alt.ico" : (TRAY_ASCII_MODE ? "Lib\rabbit-ascii.ico" : "Lib\rabbit.ico"), , true) + icon_path := RabbitGlobals.current_schema_icon + if !IsSet(icon_path) || !icon_path + icon_path := "Lib\rabbit.ico" + TraySetIcon((A_IsSuspended || IN_MAINTENANCE) ? "Lib\rabbit-alt.ico" : (TRAY_ASCII_MODE ? "Lib\rabbit-ascii.ico" : icon_path), , true) } diff --git a/Rabbit.ahk b/Rabbit.ahk index a991e03..96fdef6 100644 --- a/Rabbit.ahk +++ b/Rabbit.ahk @@ -93,6 +93,7 @@ RabbitMain(args) { RegisterHotKeys() UpdateStateLabels() if status := rime.get_status(session_id) { + local schema_id := status.schema_id local schema_name := status.schema_name local ascii_mode := status.is_ascii_mode local full_shape := status.is_full_shape @@ -100,6 +101,10 @@ RabbitMain(args) { rime.free_status(status) UpdateTrayTip(schema_name, ascii_mode, full_shape, ascii_punct) + + if RabbitConfig.schema_icon.Has(schema_id) + if RabbitGlobals.current_schema_icon := RabbitConfig.schema_icon[schema_id] + UpdateTrayIcon() } SetupTrayMenu() OnMessage(AHK_NOTIFYICON, ClickHandler.Bind()) @@ -305,6 +310,10 @@ ProcessKey(key, mask, this_hotkey) { } UpdateTrayTip(new_schema_name, new_ascii_mode, new_full_shape, new_ascii_punct) + if old_schema_id !== new_schema_id && RabbitConfig.schema_icon.Has(new_schema_id) { + if RabbitGlobals.current_schema_icon := RabbitConfig.schema_icon[new_schema_id] + UpdateTrayIcon() + } local status_text := "" local status_changed := false