Skip to content

Commit

Permalink
feat: support schema custom icons
Browse files Browse the repository at this point in the history
  • Loading branch information
amorphobia committed Sep 30, 2024
1 parent 5440cdc commit fbca818
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Lib/RabbitCommon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
5 changes: 4 additions & 1 deletion Lib/RabbitTrayMenu.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 9 additions & 0 deletions Rabbit.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@ 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
local ascii_punct := status.is_ascii_punct
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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fbca818

Please sign in to comment.