From 1cd2af23a0fe950e083ef0595e36e00d98fb46f5 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Tue, 18 Nov 2025 23:07:06 -0500 Subject: [PATCH] get current im id for switching back on update --- assets/CMakeLists.txt | 2 ++ assets/get_im.swift | 11 +++++++++++ assets/update.sh | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 assets/get_im.swift diff --git a/assets/CMakeLists.txt b/assets/CMakeLists.txt index 7b94c4f..4753f61 100644 --- a/assets/CMakeLists.txt +++ b/assets/CMakeLists.txt @@ -1,3 +1,4 @@ +add_executable(get_im get_im.swift) add_executable(switch_im switch_im.swift) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/fcitx.icns" @@ -33,6 +34,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/menu_icon_15.pdf" # Preserve execution permission install(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/uninstall.sh" "${CMAKE_CURRENT_SOURCE_DIR}/update.sh" + "${CMAKE_CURRENT_BINARY_DIR}/get_im" "${CMAKE_CURRENT_BINARY_DIR}/switch_im" DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources" ) diff --git a/assets/get_im.swift b/assets/get_im.swift new file mode 100644 index 0000000..e9f1448 --- /dev/null +++ b/assets/get_im.swift @@ -0,0 +1,11 @@ +import Carbon + +let enId = "org.fcitx.inputmethod.Fcitx5.fcitx5" + +let inputSource = TISCopyCurrentKeyboardInputSource().takeRetainedValue() +let id = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID) +if let id = id { + print(Unmanaged.fromOpaque(id).takeUnretainedValue() as? String ?? enId) +} else { + print(enId) +} diff --git a/assets/update.sh b/assets/update.sh index b4b64e8..a318b0c 100755 --- a/assets/update.sh +++ b/assets/update.sh @@ -26,6 +26,7 @@ xattr -dr com.apple.quarantine "$APP_DIR" codesign --force --sign - --deep "$APP_DIR" cd "$RESOURCES_DIR" +im=$(su -m "$user" -c "./get_im") # Switching out is necessary, otherwise it doesn't show menu # Not sure which one so try both. su -m "$user" -c "./switch_im com.apple.keylayout.ABC" @@ -53,6 +54,5 @@ killall Fcitx5 # org.fcitx.inputmethod.Fcitx5 is our CFBundleIdentifier; # The rest is the keys under tsInputModeListKey trimming the org.fcitx.inputmethod. -# Not sure which one so try both. -su -m "$user" -c "./switch_im org.fcitx.inputmethod.Fcitx5.fcitx5" -su -m "$user" -c "./switch_im org.fcitx.inputmethod.Fcitx5.zhHans" +# Switch back. +su -m "$user" -c "./switch_im $im"