From 0e4747df8e95ecbf4059e695c18af4cc0aa8925b Mon Sep 17 00:00:00 2001 From: millionart Date: Fri, 1 May 2026 21:52:45 +0800 Subject: [PATCH] fix: register Windows IME COM server system-wide --- .../app/src-tauri/src/windows_ime_profile.rs | 6 +++--- openless-all/app/windows-ime/src/registry.cpp | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/openless-all/app/src-tauri/src/windows_ime_profile.rs b/openless-all/app/src-tauri/src/windows_ime_profile.rs index 2b3444b7..ed1430f0 100644 --- a/openless-all/app/src-tauri/src/windows_ime_profile.rs +++ b/openless-all/app/src-tauri/src/windows_ime_profile.rs @@ -195,7 +195,7 @@ mod windows_impl { TF_INPUTPROCESSORPROFILE, TF_IPPMF_DONTCARECURRENTINPUTLANGUAGE, TF_IPPMF_FORSESSION, TF_PROFILETYPE_INPUTPROCESSOR, TF_PROFILETYPE_KEYBOARDLAYOUT, }; - use winreg::enums::{HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY}; + use winreg::enums::{HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_64KEY}; use winreg::RegKey; const OPENLESS_COM_INPROC_KEY: &str = @@ -347,9 +347,9 @@ mod windows_impl { } fn inspect_windows_ime_registration() -> RegistrationInspection { - let hkcu = RegKey::predef(HKEY_CURRENT_USER); let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); - let com_key = hkcu.open_subkey_with_flags(OPENLESS_COM_INPROC_KEY, KEY_READ); + let com_key = + hklm.open_subkey_with_flags(OPENLESS_COM_INPROC_KEY, KEY_READ | KEY_WOW64_64KEY); let tip_key_exists = hklm .open_subkey_with_flags(OPENLESS_TSF_PROFILE_KEY, KEY_READ | KEY_WOW64_64KEY) .is_ok(); diff --git a/openless-all/app/windows-ime/src/registry.cpp b/openless-all/app/windows-ime/src/registry.cpp index 61c99887..e403a0c9 100644 --- a/openless-all/app/windows-ime/src/registry.cpp +++ b/openless-all/app/windows-ime/src/registry.cpp @@ -11,6 +11,7 @@ constexpr wchar_t kClsidKey[] = L"Software\\Classes\\CLSID\\{6B9F3F4F-5EE7-42D6-9C61-9F80B03A5D7D}"; constexpr wchar_t kInprocServer32Key[] = L"Software\\Classes\\CLSID\\{6B9F3F4F-5EE7-42D6-9C61-9F80B03A5D7D}\\InprocServer32"; +constexpr REGSAM kRegistryWriteAccess = KEY_WRITE | KEY_WOW64_64KEY; HRESULT HResultFromWin32Error(LSTATUS status) { return status == ERROR_SUCCESS ? S_OK : HRESULT_FROM_WIN32(status); @@ -37,9 +38,9 @@ HRESULT RegisterComServer(HINSTANCE module) { HKEY clsid_key = nullptr; LSTATUS status = - RegCreateKeyExW(HKEY_CURRENT_USER, kClsidKey, 0, nullptr, - REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &clsid_key, - nullptr); + RegCreateKeyExW(HKEY_LOCAL_MACHINE, kClsidKey, 0, nullptr, + REG_OPTION_NON_VOLATILE, kRegistryWriteAccess, nullptr, + &clsid_key, nullptr); HRESULT hr = HResultFromWin32Error(status); if (FAILED(hr)) { return hr; @@ -52,8 +53,8 @@ HRESULT RegisterComServer(HINSTANCE module) { } HKEY inproc_key = nullptr; - status = RegCreateKeyExW(HKEY_CURRENT_USER, kInprocServer32Key, 0, nullptr, - REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, + status = RegCreateKeyExW(HKEY_LOCAL_MACHINE, kInprocServer32Key, 0, nullptr, + REG_OPTION_NON_VOLATILE, kRegistryWriteAccess, nullptr, &inproc_key, nullptr); hr = HResultFromWin32Error(status); if (FAILED(hr)) { @@ -69,7 +70,7 @@ HRESULT RegisterComServer(HINSTANCE module) { } HRESULT DeleteComServerRegistration() { - const LSTATUS status = RegDeleteTreeW(HKEY_CURRENT_USER, kClsidKey); + const LSTATUS status = RegDeleteTreeW(HKEY_LOCAL_MACHINE, kClsidKey); if (status == ERROR_FILE_NOT_FOUND) { return S_OK; } @@ -121,6 +122,8 @@ HRESULT RegisterLanguageProfile() { return hr; } + profiles->Unregister(CLSID_OpenLessTextService); + hr = profiles->Register(CLSID_OpenLessTextService); if (SUCCEEDED(hr)) { hr = profiles->AddLanguageProfile( @@ -151,6 +154,10 @@ HRESULT RegisterKeyboardCategory() { return hr; } + category_mgr->UnregisterCategory(CLSID_OpenLessTextService, + GUID_TFCAT_TIP_KEYBOARD, + CLSID_OpenLessTextService); + hr = category_mgr->RegisterCategory(CLSID_OpenLessTextService, GUID_TFCAT_TIP_KEYBOARD, CLSID_OpenLessTextService);