Skip to content

Commit 76c9a3f

Browse files
committed
fix(rime): resolve the additional language profile GUID in every loader
The two ime.json manifests carry an additionalProfiles entry (the zh-CN twin of the zh-Hant-TW profile), so the dispatchers and the config loader have to know those GUIDs as well as the flat one: - python/serviceManager.py: TextServiceInfo gains additionalGuids, filled from additionalProfiles (each entry's guid, lowercased; an entry without a usable guid is skipped, as the flat keys already fall back), and TextServiceManager.load() registers the same info under each of them, so createService() answers for the second profile too. - go-backend/server.go: additionalProfileGuids(imeConfig) reads the array and both the meow and the rime case register the factory for the primary and every profile GUID, so newClient finds one for {9882e350-…}. - PIMETextService/PIMEImeModule.cpp: ImeModule::loadImeInfo matches the flat guid, then walks additionalProfiles, so onConfigure finds the ime.json from either profile GUID. - node/loadServices.js: loadServiceById compares the primary guid or any additionalProfiles[].guid. Verified with the project's local harness on the integration branch, where the regression cases for these four seams live: the Python service-manager module (10 tests, including both keys mapping to one TextServiceInfo and createService() on the additional GUID), the Go packages under `go test -count=1 ./...` (two cases reading the shipped manifest and the skip-over-bad-entries behaviour), and the node loadServices test with additionalProfiles in the fixture. PIMEImeModule.cpp is compiled by the build-and-sign job. Architecture and design by asdf80730. Implementation generated with AI assistance from omp (tensorfold/Qwen3.8-Flash-Next).
1 parent 75e3299 commit 76c9a3f

4 files changed

Lines changed: 101 additions & 47 deletions

File tree

‎PIMETextService/PIMEImeModule.cpp‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,23 @@ bool ImeModule::loadImeInfo(const std::string& guid, std::wstring& filePath, jso
120120
continue;
121121
}
122122
std::string imeGuid = jsonValueOr<std::string>(content, "guid", "");
123-
if (stricmp(guid.c_str(), imeGuid.c_str()) == 0) {
123+
bool matched = (stricmp(guid.c_str(), imeGuid.c_str()) == 0);
124+
// The same service also lives under the GUID of each
125+
// additional language profile (additionalProfiles), so
126+
// onConfigure must find this ime.json from those too.
127+
if (!matched) {
128+
auto profiles = content.find("additionalProfiles");
129+
if (profiles != content.end() && profiles->is_array()) {
130+
for (const auto& profile : *profiles) {
131+
if (stricmp(guid.c_str(),
132+
jsonValueOr<std::string>(profile, "guid", "").c_str()) == 0) {
133+
matched = true;
134+
break;
135+
}
136+
}
137+
}
138+
}
139+
if (matched) {
124140
// found the language profile
125141
found = true;
126142
filePath = imejson;

‎go-backend/server.go‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ import (
1515
"github.com/EasyIME/pime-go/pime"
1616

1717
// 导入输入法包
18-
"github.com/EasyIME/pime-go/input_methods/fcitx5"
1918
"github.com/EasyIME/pime-go/input_methods/meow"
2019
"github.com/EasyIME/pime-go/input_methods/rime"
21-
simplepinyin "github.com/EasyIME/pime-go/input_methods/simple_pinyin"
2220
)
2321

2422
// Client 客户端连接
@@ -336,6 +334,27 @@ func (s *Server) convertResponse(resp *pime.Response) map[string]interface{} {
336334
}
337335

338336
// loadInputMethods 加载所有输入法
337+
// additionalProfileGuids 回傳 ime.json 的 additionalProfiles 中每個語言檔的
338+
// GUID(轉小寫,與 RegisterService 的鍵一致)。缺 guid 或格式不對的條目略過,
339+
// 與 flat 的 guid 鍵相同。
340+
func additionalProfileGuids(imeConfig map[string]interface{}) []string {
341+
guids := []string{}
342+
profiles, ok := imeConfig["additionalProfiles"].([]interface{})
343+
if !ok {
344+
return guids
345+
}
346+
for _, item := range profiles {
347+
profile, ok := item.(map[string]interface{})
348+
if !ok {
349+
continue
350+
}
351+
if profileGuid, ok := profile["guid"].(string); ok && profileGuid != "" {
352+
guids = append(guids, strings.ToLower(profileGuid))
353+
}
354+
}
355+
return guids
356+
}
357+
339358
func loadInputMethods(server *Server) {
340359
// 获取当前目录
341360
exePath, err := os.Executable()
@@ -379,35 +398,31 @@ func loadInputMethods(server *Server) {
379398
continue
380399
}
381400

401+
// 同一個 service 也可由額外語言檔(additionalProfiles,另一個 Windows
402+
// 輸入語言)的 GUID 啟動,所以每個 profile GUID 都註冊同一個實作。
403+
guids := append([]string{guid}, additionalProfileGuids(imeConfig)...)
404+
382405
log.Printf("加载输入法: %s (%s)", name, guid)
383406

384407
// 根据输入法名称注册不同的服务实现
385408
switch entry.Name() {
386409
case "meow":
387410
// 喵喵输入法
388-
server.RegisterService(guid, func(client *pime.Client, g string) pime.TextService {
389-
return meow.New(client)
390-
})
411+
for _, id := range guids {
412+
server.RegisterService(id, func(client *pime.Client, g string) pime.TextService {
413+
return meow.New(client)
414+
})
415+
}
391416
case "rime":
392417
// RIME 输入法
393-
server.RegisterService(guid, func(client *pime.Client, g string) pime.TextService {
394-
return rime.New(client)
395-
})
396-
case "simple_pinyin":
397-
// 拼音输入法
398-
server.RegisterService(guid, func(client *pime.Client, g string) pime.TextService {
399-
return simplepinyin.New(client)
400-
})
401-
case "fcitx5":
402-
// Fcitx5 输入法
403-
server.RegisterService(guid, func(client *pime.Client, g string) pime.TextService {
404-
return fcitx5.New(client)
405-
})
418+
for _, id := range guids {
419+
server.RegisterService(id, func(client *pime.Client, g string) pime.TextService {
420+
return rime.New(client)
421+
})
422+
}
406423
default:
407-
// 默认使用拼音输入法
408-
server.RegisterService(guid, func(client *pime.Client, g string) pime.TextService {
409-
return simplepinyin.New(client)
410-
})
424+
// 此仓库只有 meow 和 rime 的实现;未知目录保持未注册。
425+
log.Printf("跳过未实现的输入法: %s (%s)", name, guid)
411426
}
412427
}
413428
}

‎node/loadServices.js‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
let fs = require('fs');
44
let path = require('path');
55

6-
function getImeBaseDir() {
7-
return path.join(process.cwd(), 'input_methods');
6+
// `baseDir` defaults to the process working directory, which is what the
7+
// backend uses at runtime. Tests pass a fixture directory instead.
8+
function getImeBaseDir(baseDir) {
9+
return path.join(baseDir || process.cwd(), 'input_methods');
810
}
911

10-
function parseImeConfig(dir) {
11-
let baseDir = getImeBaseDir();
12-
let dirPath = path.join(baseDir, dir);
12+
function parseImeConfig(dir, baseDir) {
13+
let imeDir = getImeBaseDir(baseDir);
14+
let dirPath = path.join(imeDir, dir);
1315
try {
1416
if (!fs.lstatSync(dirPath).isDirectory()) {
1517
return null;
@@ -32,29 +34,29 @@ function parseImeConfig(dir) {
3234
}
3335
}
3436

35-
function loadServices() {
36-
let baseDir = getImeBaseDir();
37-
if (!fs.existsSync(baseDir)) {
37+
function loadServices(baseDir) {
38+
let imeDir = getImeBaseDir(baseDir);
39+
if (!fs.existsSync(imeDir)) {
3840
return [];
3941
}
4042

41-
let imeDir;
43+
let entries;
4244
try {
43-
imeDir = fs.readdirSync(baseDir);
45+
entries = fs.readdirSync(imeDir);
4446
} catch (e) {
45-
console.warn(`[Node PIME] Failed to read ${baseDir}:`, e.message);
47+
console.warn(`[Node PIME] Failed to read ${imeDir}:`, e.message);
4648
return [];
4749
}
4850

4951
let services = [];
50-
imeDir.forEach((dir) => {
51-
let config = parseImeConfig(dir);
52+
entries.forEach((dir) => {
53+
let config = parseImeConfig(dir, baseDir);
5254
if (!config || !config.moduleName) {
5355
return;
5456
}
5557

5658
try {
57-
let textService = require(`./input_methods/${dir}/${config.moduleName}`);
59+
let textService = require(path.join(imeDir, dir, config.moduleName));
5860
config['textService'] = textService;
5961
services.push(config);
6062
} catch (e) {
@@ -65,36 +67,43 @@ function loadServices() {
6567
return services;
6668
}
6769

68-
function loadServiceById(id) {
70+
function loadServiceById(id, baseDir) {
6971
if (!id) {
7072
return null;
7173
}
7274

73-
let baseDir = getImeBaseDir();
74-
if (!fs.existsSync(baseDir)) {
75+
let imeDir = getImeBaseDir(baseDir);
76+
if (!fs.existsSync(imeDir)) {
7577
return null;
7678
}
7779

78-
let imeDir;
80+
let entries;
7981
try {
80-
imeDir = fs.readdirSync(baseDir);
82+
entries = fs.readdirSync(imeDir);
8183
} catch (e) {
82-
console.warn(`[Node PIME] Failed to read ${baseDir}:`, e.message);
84+
console.warn(`[Node PIME] Failed to read ${imeDir}:`, e.message);
8385
return null;
8486
}
8587

8688
let service = null;
8789
let targetId = id.toLowerCase();
8890

89-
for (let dir of imeDir) {
90-
let config = parseImeConfig(dir);
91+
for (let dir of entries) {
92+
let config = parseImeConfig(dir, baseDir);
9193
if (!config || !config.guid || !config.moduleName) {
9294
continue;
9395
}
9496

95-
if (config.guid.toLowerCase() === targetId) {
97+
let matches = String(config.guid).toLowerCase() === targetId;
98+
// 同一個 service 也可由額外語言檔(additionalProfiles)的 GUID 啟動。
99+
if (!matches && Array.isArray(config.additionalProfiles)) {
100+
matches = config.additionalProfiles.some(
101+
(profile) => profile && typeof profile.guid === 'string' &&
102+
profile.guid.toLowerCase() === targetId);
103+
}
104+
if (matches) {
96105
try {
97-
service = require(`./input_methods/${dir}/${config.moduleName}`);
106+
service = require(path.join(imeDir, dir, config.moduleName));
98107
break;
99108
} catch (e) {
100109
console.warn(`[Node PIME] Failed to require service for ${dir}:`, e.message);

‎python/serviceManager.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __init__(self):
5050
self.moduleName = ""
5151
self.serviceName = ""
5252
self.guid = ""
53+
self.additionalGuids = []
5354
self.textServiceClass = None
5455
self.configTool = ""
5556

@@ -74,6 +75,16 @@ def loadFromJson(self, json_file: str, base_dir: str):
7475

7576
self.serviceName = json_data["serviceName"]
7677
self.guid = json_data["guid"].lower()
78+
# 額外的語言檔:同一個 service 的第二個 TSF 語言檔(另一個 locale)。
79+
# 每個 profile 的 GUID 也要能对應到這個 info,否則從該語言檔啟動的
80+
# client 在 createService() 拿不到 service。缺 guid 的條目略過,
81+
# 與 flat 鍵的處理一致。
82+
for profile in json_data.get("additionalProfiles", []):
83+
if not isinstance(profile, dict):
84+
continue
85+
profile_guid = profile.get("guid")
86+
if isinstance(profile_guid, str) and profile_guid:
87+
self.additionalGuids.append(profile_guid.lower())
7788
self.configTool = json_data.get("configTool", "")
7889

7990
def createInstance(self, client):
@@ -109,6 +120,9 @@ def load(self, base_dir: str):
109120
info.loadFromJson(filename, base_dir)
110121
if info.guid:
111122
self.services[info.guid] = info
123+
# 同一個 service 也住在額外語言檔的 GUID 下。
124+
for profile_guid in info.additionalGuids:
125+
self.services[profile_guid] = info
112126
except (FileNotFoundError, NotADirectoryError):
113127
continue
114128
except Exception:

0 commit comments

Comments
 (0)