feat: 实现 Linux Fcitx5 实时输入链路

加入 Unix Socket v2 协议、会话状态机、动态快捷键、完整 preedit 更新、结束提交以及断线重连和安全取消。

AI-assisted-by: Codex
AI-model: gpt-5.6-sol
AI-reasoning-effort: medium
Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
2026-08-23 02:34:14 +08:00
co-authored by Codex
parent f1f41f4f48
commit 6ff1d3bf77
13 changed files with 1265 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { JsonLineDecoder, defaultSocketPath } from '../src/main/fcitx-bridge';
test('Socket 路径只使用当前用户运行时目录', () => {
assert.equal(defaultSocketPath({ XDG_RUNTIME_DIR: '/run/user/1000' }), '/run/user/1000/meloasr/fcitx5.sock');
assert.throws(() => defaultSocketPath({}), /XDG_RUNTIME_DIR/);
});
test('JSONL 解码器支持拆包、粘包与无效 JSON', () => {
const messages: unknown[] = [];
const errors: Error[] = [];
const decoder = new JsonLineDecoder((message) => messages.push(message), (error) => errors.push(error));
decoder.push('{"type":"hel');
decoder.push('lo","protocol":2}\n{"type":"request-start"}\nnot-json\n');
assert.deepEqual(messages, [{ type: 'hello', protocol: 2 }, { type: 'request-start' }]);
assert.equal(errors.length, 1);
});