Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Apply Linux input method compatibility before native startup https://github.com/siyuan-note/siyuan/issues/20549

Daniel1eccc4a73529
diff --git a/app/electron/fixtures/linuxInputMethodStartup.cjs b/app/electron/fixtures/linuxInputMethodStartup.cjs
new file mode 100644
index 0000000000..c42552de71
--- /dev/null
+++ b/app/electron/fixtures/linuxInputMethodStartup.cjs
@@ -0,0 +1,47 @@
+const fs = require("node:fs");
+const {spawnSync} = require("node:child_process");
+const {app, BrowserWindow} = require("electron");
+const {
+ readLinuxInputMethodSetting, writeLinuxInputMethodSetting, readLinuxInputMethodArguments,
+ prepareLinuxInputMethodLaunch, linuxInputMethodRelaunchEnvironment,
+} = require("../linuxInputMethod");
+
+const directory = process.env.SIYUAN_TEST_IME_DIRECTORY;
+const settingFile = directory + "/setting.json";
+const traceFile = directory + "/trace.jsonl";
+app.setPath("userData", directory + "/user-data");
+const record = (data) => fs.appendFileSync(traceFile, JSON.stringify({pid: process.pid, ...data}) + "\n");
+const originalArgs = readLinuxInputMethodArguments();
+const launch = prepareLinuxInputMethodLaunch(originalArgs,
+ readLinuxInputMethodSetting(settingFile), process.platform, process.env[linuxInputMethodRelaunchEnvironment]);
+record({event: "launch", override: launch.override, relaunch: launch.relaunchArgs !== null,
+ originalArgs, currentArgs: process.argv, hasToken: Boolean(process.env[linuxInputMethodRelaunchEnvironment]),
+ nativeSwitch: app.commandLine.getSwitchValue("ozone-platform")});
+if (launch.relaunchArgs) {
+ if (launch.relaunchToken) {
+ process.env[linuxInputMethodRelaunchEnvironment] = launch.relaunchToken;
+ } else {
+ delete process.env[linuxInputMethodRelaunchEnvironment];
+ }
+ app.relaunch({args: launch.relaunchArgs});
+ app.exit(0);
+} else {
+ app.whenReady().then(() => {
+ const window = new BrowserWindow({show: false});
+ const handle = window.getNativeWindowHandle();
+ const id = handle.length === 8 ? handle.readBigUInt64LE(0) : BigInt(handle.readUInt32LE(0));
+ const x11 = spawnSync("xwininfo", ["-id", id.toString()], {timeout: 2000}).status === 0;
+ record({event: "backend", x11, override: launch.override});
+ window.destroy();
+ if (process.env.SIYUAN_TEST_IME_DISABLE === "true" && readLinuxInputMethodSetting(settingFile)) {
+ writeLinuxInputMethodSetting(settingFile, false);
+ app.relaunch();
+ } else {
+ record({event: "complete"});
+ }
+ app.exit(0);
+ }).catch(error => {
+ record({event: "error", message: error.message});
+ app.exit(1);
+ });
+}
diff --git a/app/electron/linuxInputMethod.js b/app/electron/linuxInputMethod.js
index e976da0181..a9c7d8f236 100644
--- a/app/electron/linuxInputMethod.js
+++ b/app/electron/linuxInputMethod.js
@@ -2,6 +2,9 @@ const fs = require("node:fs");
const path = require("node:path");
const crypto = require("node:crypto");
+const linuxInputMethodRelaunchEnvironment = "SIYUAN_LINUX_INPUT_METHOD_RELAUNCH";
+const linuxInputMethodRelaunchSwitch = "--siyuan-linux-input-method-relaunch=";
+
const readLinuxInputMethodSetting = (file) => {
try {
const data = JSON.parse(fs.readFileSync(file, "utf8"));
@@ -33,13 +36,13 @@ const writeLinuxInputMethodSetting = (file, enabled) => {
}
};
-// 读取内核保存的启动参数,排除 Chromium 和本机设置在进程内追加的参数。
-const readLinuxInputMethodArguments = () => {
- const content = fs.readFileSync("/proc/self/cmdline", "utf8");
- if (!content || !content.endsWith("\0")) {
- throw new Error("Invalid Linux process command line");
+// Electron 保留原始启动参数快照,不包含 Chromium 后续补入的开关。
+// 复制快照,避免进程标题改写命令行或后续参数修改影响启动判定。
+const readLinuxInputMethodArguments = (args = process.argv) => {
+ if (!Array.isArray(args) || args.length === 0 || args.some(arg => typeof arg !== "string")) {
+ throw new Error("Invalid Linux launch arguments");
}
- return content.slice(0, -1).split("\0");
+ return args.slice();
};
// 显式显示后端参数优先于本机兼容设置,重复参数采用最后一次指定的值。
@@ -60,17 +63,47 @@ const getLinuxInputMethodOverride = (args) => {
return backend === null ? null : backend === "x11";
};
-const configureLinuxInputMethod = (commandLine, enabled, platform, args) => {
+// 原生后端在应用脚本加载前选定,通过重启把兼容参数交给下一进程的原生启动阶段。
+// 随机标记仅在进程环境中传递,用于区分本机设置生成的参数和用户显式参数。
+const prepareLinuxInputMethodLaunch = (args, enabled, platform, relaunchToken) => {
+ const original = args.slice();
+ const result = {args: original, override: null, relaunchArgs: null, relaunchToken: null};
if (platform !== "linux") {
- return;
+ return result;
}
- const backend = getLinuxInputMethodBackend(args);
- if (backend !== null || enabled) {
- commandLine.appendSwitch("ozone-platform", backend ?? "x11");
+ let managed = false;
+ if (/^[a-f0-9]{48}$/.test(relaunchToken || "")) {
+ for (let i = 2; i < original.length && original[i] !== "--"; i++) {
+ if (original[i] === linuxInputMethodRelaunchSwitch + relaunchToken &&
+ original[i - 1] === "--ozone-platform=x11") {
+ original.splice(i - 1, 2);
+ managed = true;
+ break;
+ }
+ }
+ }
+ const backend = getLinuxInputMethodBackend(original);
+ result.override = getLinuxInputMethodOverride(original);
+ if (backend !== null) {
+ if (managed && getLinuxInputMethodBackend(args) !== backend) {
+ result.relaunchArgs = original.slice(1);
+ }
+ return result;
+ }
+ if (enabled && !managed) {
+ const next = original.slice();
+ const terminator = next.indexOf("--", 1);
+ result.relaunchToken = crypto.randomBytes(24).toString("hex");
+ next.splice(terminator < 0 ? next.length : terminator, 0,
+ "--ozone-platform=x11", linuxInputMethodRelaunchSwitch + result.relaunchToken);
+ result.relaunchArgs = next.slice(1);
+ } else if (!enabled && managed) {
+ result.relaunchArgs = original.slice(1);
}
+ return result;
};
module.exports = {
readLinuxInputMethodSetting, writeLinuxInputMethodSetting, readLinuxInputMethodArguments,
- getLinuxInputMethodOverride, configureLinuxInputMethod,
+ getLinuxInputMethodOverride, prepareLinuxInputMethodLaunch, linuxInputMethodRelaunchEnvironment,
};
diff --git a/app/electron/linuxInputMethod.native.test.js b/app/electron/linuxInputMethod.native.test.js
new file mode 100644
index 0000000000..822fa8e788
--- /dev/null
+++ b/app/electron/linuxInputMethod.native.test.js
@@ -0,0 +1,69 @@
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+const {spawn, spawnSync} = require("node:child_process");
+const {setTimeout: delay} = require("node:timers/promises");
+const {test} = require("node:test");
+const {writeLinuxInputMethodSetting} = require("./linuxInputMethod");
+
+const supported = process.platform === "linux" && process.env.WAYLAND_DISPLAY &&
+ fs.existsSync(path.join(process.env.XDG_RUNTIME_DIR || "", process.env.WAYLAND_DISPLAY)) &&
+ spawnSync("xwininfo", ["-version"]).status === 0;
+
+for (const scenario of [
+ {name: "enabled", enabled: true, x11: [true], launches: 2, override: null},
+ {name: "disabled", enabled: false, x11: [false], launches: 1, override: null},
+ {name: "explicit-x11", enabled: false, args: ["--ozone-platform=x11"], x11: [true], launches: 1, override: true},
+ {name: "explicit-wayland", enabled: true, args: ["--ozone-platform=wayland"], x11: [false], launches: 1, override: false},
+ {name: "disable-after-relaunch", enabled: true, disable: true, x11: [true, false], launches: 4, override: null},
+]) {
+ test(`native Linux input method startup: ${scenario.name}`, {skip: !supported, timeout: 30000}, async (t) => {
+ const binary = process.env.SIYUAN_TEST_ELECTRON_BINARY || require("electron");
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-native-ime-"));
+ const traceFile = path.join(directory, "trace.jsonl");
+ writeLinuxInputMethodSetting(path.join(directory, "setting.json"), scenario.enabled);
+ const child = spawn(binary, [path.join(__dirname, "fixtures/linuxInputMethodStartup.cjs"),
+ "--no-sandbox", "--disable-gpu", ...scenario.args || []], {
+ env: {...process.env, XDG_SESSION_TYPE: "wayland", SIYUAN_TEST_IME_DIRECTORY: directory,
+ SIYUAN_TEST_IME_DISABLE: String(scenario.disable || false), SIYUAN_LINUX_INPUT_METHOD_RELAUNCH: ""},
+ stdio: ["ignore", "ignore", "pipe"], windowsHide: true,
+ });
+ let stderr = "";
+ child.stderr.on("data", chunk => { stderr += chunk.toString(); });
+ let launchError;
+ child.on("error", error => { launchError = error; });
+ let trace = [];
+ t.after(() => {
+ for (const pid of new Set([child.pid, ...trace.map(row => row.pid)])) {
+ if (pid) {
+ try { process.kill(pid, "SIGKILL"); } catch (error) {
+ if (error.code !== "ESRCH") {
+ throw error;
+ }
+ }
+ }
+ }
+ fs.rmSync(directory, {recursive: true, force: true});
+ });
+ const deadline = Date.now() + 20000;
+ while (Date.now() < deadline) {
+ if (launchError) {
+ throw launchError;
+ }
+ if (fs.existsSync(traceFile)) {
+ const content = fs.readFileSync(traceFile, "utf8");
+ trace = content.slice(0, content.lastIndexOf("\n")).split("\n").filter(Boolean).map(line => JSON.parse(line));
+ if (trace.some(row => row.event === "complete" || row.event === "error")) {
+ break;
+ }
+ }
+ await delay(50);
+ }
+ assert.ok(trace.some(row => row.event === "complete"), JSON.stringify(trace) + stderr);
+ assert.equal(trace.filter(row => row.event === "launch").length, scenario.launches);
+ const backends = trace.filter(row => row.event === "backend");
+ assert.deepEqual(backends.map(row => row.x11), scenario.x11);
+ assert.ok(backends.every(row => row.override === scenario.override));
+ });
+}
diff --git a/app/electron/linuxInputMethod.test.js b/app/electron/linuxInputMethod.test.js
index 94ae2acb3f..14368f1265 100644
--- a/app/electron/linuxInputMethod.test.js
+++ b/app/electron/linuxInputMethod.test.js
@@ -3,20 +3,12 @@ const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const {test} = require("node:test");
+const {runInNewContext} = require("node:vm");
const {
readLinuxInputMethodSetting, writeLinuxInputMethodSetting, readLinuxInputMethodArguments,
- getLinuxInputMethodOverride, configureLinuxInputMethod,
+ getLinuxInputMethodOverride, prepareLinuxInputMethodLaunch, linuxInputMethodRelaunchEnvironment,
} = require("./linuxInputMethod");
-const commandLine = (platform) => {
- const switches = new Map(platform === undefined ? [] : [["ozone-platform", platform]]);
- return {
- hasSwitch: (name) => switches.has(name),
- getSwitchValue: (name) => switches.get(name),
- appendSwitch: (name, value) => switches.set(name, value),
- };
-};
-
test("compatibility mode persists across launches and can be disabled", (t) => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-ime-"));
t.after(() => fs.rmSync(directory, {recursive: true, force: true}));
@@ -24,9 +16,8 @@ test("compatibility mode persists across launches and can be disabled", (t) => {
assert.equal(readLinuxInputMethodSetting(file), false);
for (const enabled of [true, false]) {
writeLinuxInputMethodSetting(file, enabled);
- const launch = commandLine();
- configureLinuxInputMethod(launch, readLinuxInputMethodSetting(file), "linux", ["siyuan"]);
- assert.equal(launch.getSwitchValue("ozone-platform"), enabled ? "x11" : undefined);
+ const launch = prepareLinuxInputMethodLaunch(["siyuan"], readLinuxInputMethodSetting(file), "linux");
+ assert.equal(launch.relaunchArgs?.includes("--ozone-platform=x11") || false, enabled);
}
assert.deepEqual(fs.readdirSync(path.dirname(file)), ["linux-input-method.json"]);
});
@@ -34,35 +25,39 @@ test("compatibility mode persists across launches and can be disabled", (t) => {
test("explicit display backend overrides either saved choice", () => {
for (const backend of ["x11", "wayland", "auto", ""]) {
for (const enabled of [false, true]) {
- const launch = commandLine(backend);
const args = ["siyuan", "--ozone-platform=" + backend];
assert.equal(getLinuxInputMethodOverride(args), backend === "x11");
- configureLinuxInputMethod(launch, enabled, "linux", args);
- assert.equal(launch.getSwitchValue("ozone-platform"), backend);
+ const launch = prepareLinuxInputMethodLaunch(args, enabled, "linux");
+ assert.equal(launch.relaunchArgs, null);
+ assert.equal(launch.override, backend === "x11");
}
}
assert.equal(getLinuxInputMethodOverride(["siyuan"]), null);
});
-test("automatically selected backends do not lock the preference across launches", () => {
- const args = ["siyuan"];
- for (const backend of ["wayland", "x11"]) {
- for (const enabled of [false, true]) {
- const launch = commandLine(backend);
- configureLinuxInputMethod(launch, enabled, "linux", args);
- assert.equal(launch.getSwitchValue("ozone-platform"), enabled ? "x11" : backend);
- assert.equal(getLinuxInputMethodOverride(args), null);
- }
- }
+test("managed backend reaches native startup without locking the preference or looping", () => {
+ const original = ["siyuan", "--workspace=/path with spaces", "--lang=zh-CN"];
+ const first = prepareLinuxInputMethodLaunch(original, true, "linux");
+ const nativeArgs = [original[0], ...first.relaunchArgs];
+ assert.equal(getLinuxInputMethodOverride(nativeArgs), true);
+ const second = prepareLinuxInputMethodLaunch(nativeArgs, true, "linux", first.relaunchToken);
+ assert.equal(second.override, null);
+ assert.equal(second.relaunchArgs, null);
+ assert.deepEqual(second.args, original);
+ const disabled = prepareLinuxInputMethodLaunch(nativeArgs, false, "linux", first.relaunchToken);
+ assert.deepEqual(disabled.relaunchArgs, original.slice(1));
+ const third = prepareLinuxInputMethodLaunch([original[0], ...disabled.relaunchArgs], false, "linux");
+ assert.equal(third.override, null);
+ assert.equal(third.relaunchArgs, null);
});
test("explicit backends support separate values, repeated switches and the argument terminator", () => {
for (const backend of ["wayland", "x11", "auto", ""]) {
const args = ["siyuan", "--ozone-platform", backend];
- const launch = commandLine("");
- configureLinuxInputMethod(launch, true, "linux", args);
+ const launch = prepareLinuxInputMethodLaunch(args, true, "linux");
assert.equal(getLinuxInputMethodOverride(args), backend === "x11");
- assert.equal(launch.getSwitchValue("ozone-platform"), backend);
+ assert.equal(launch.override, backend === "x11");
+ assert.equal(launch.relaunchArgs, null);
}
assert.equal(getLinuxInputMethodOverride(["siyuan", "--ozone-platform=x11", "--ozone-platform=wayland"]), false);
assert.equal(getLinuxInputMethodOverride(["siyuan", "--", "--ozone-platform=x11"]), null);
@@ -70,31 +65,73 @@ test("explicit backends support separate values, repeated switches and the argum
assert.equal(getLinuxInputMethodOverride(["siyuan", "--ozone-platform", "--other"]), false);
});
-test("original process arguments exclude appended switches and preserve empty arguments", (t) => {
- t.mock.method(fs, "readFileSync", (file, encoding) => {
- assert.equal(file, "/proc/self/cmdline");
- assert.equal(encoding, "utf8");
- return "siyuan\0--workspace=/path with spaces\0\0";
+test("managed flags precede the terminator and preserve development and positional arguments", () => {
+ const original = ["electron", "/path with spaces/main.js", "--", "--ozone-platform=wayland", "document"];
+ const launch = prepareLinuxInputMethodLaunch(original, true, "linux");
+ assert.ok(launch.relaunchArgs.indexOf("--ozone-platform=x11") < launch.relaunchArgs.indexOf("--"));
+ const restarted = prepareLinuxInputMethodLaunch(["electron", ...launch.relaunchArgs], true, "linux", launch.relaunchToken);
+ assert.deepEqual(restarted.args, original);
+ assert.equal(restarted.override, null);
+ assert.equal(restarted.relaunchArgs, null);
+});
+
+test("an unmatched relaunch marker cannot hide an explicit backend", () => {
+ const launch = prepareLinuxInputMethodLaunch(["siyuan"], true, "linux");
+ const args = ["siyuan", ...launch.relaunchArgs];
+ for (const token of [undefined, "invalid", "0".repeat(48)]) {
+ const result = prepareLinuxInputMethodLaunch(args, true, "linux", token);
+ assert.equal(result.override, true);
+ assert.equal(result.relaunchArgs, null);
+ }
+ const explicit = prepareLinuxInputMethodLaunch(["siyuan", "--ozone-platform=wayland", ...launch.relaunchArgs],
+ true, "linux", launch.relaunchToken);
+ assert.equal(explicit.override, false);
+ assert.deepEqual(explicit.relaunchArgs, ["--ozone-platform=wayland"]);
+});
+
+test("main relaunches before claiming the instance or creating windows and kernels", () => {
+ const source = fs.readFileSync(path.join(__dirname, "main.js"), "utf8");
+ const start = source.indexOf("let linuxInputMethodOverride = null;");
+ const end = source.indexOf("const appCrashLogPath = ", start);
+ assert.ok(start > 0 && end > start);
+ assert.ok(end < source.indexOf("app.requestSingleInstanceLock()"));
+ assert.ok(end < source.indexOf("new BrowserWindow("));
+ assert.ok(end < source.indexOf("childProcess.spawn(kernelPath"));
+ const calls = [];
+ const env = {};
+ runInNewContext(source.slice(start, end), {
+ process: {platform: "linux", argv: ["siyuan"], env},
+ linuxInputMethodSettingPath: "setting.json", linuxInputMethodRelaunchEnvironment,
+ readLinuxInputMethodSetting: () => true,
+ readLinuxInputMethodArguments: () => ["siyuan"], prepareLinuxInputMethodLaunch,
+ app: {relaunch: options => calls.push(options), exit: code => calls.push(code)},
+ writeLog: message => { throw new Error(message); },
});
- const args = readLinuxInputMethodArguments();
+ assert.equal(calls.length, 2);
+ assert.ok(calls[0].args.includes("--ozone-platform=x11"));
+ assert.equal(calls[1], 0);
+ assert.match(env[linuxInputMethodRelaunchEnvironment], /^[a-f0-9]{48}$/);
+});
+
+test("Electron launch arguments are copied without reading a mutable process title", (t) => {
+ t.mock.method(fs, "readFileSync", () => { throw new Error("Process title is not an argument source"); });
+ const original = ["siyuan", "--workspace=/path with spaces", ""];
+ const args = readLinuxInputMethodArguments(original);
+ original.push("--ozone-platform=wayland");
assert.deepEqual(args, ["siyuan", "--workspace=/path with spaces", ""]);
assert.equal(getLinuxInputMethodOverride(args), null);
});
-test("unavailable or invalid original arguments are reported instead of guessing an override", (t) => {
- const read = t.mock.method(fs, "readFileSync", () => { throw new Error("Access denied"); });
- assert.throws(() => readLinuxInputMethodArguments(), /Access denied/);
- for (const content of ["", "siyuan"]) {
- read.mock.mockImplementation(() => content);
- assert.throws(() => readLinuxInputMethodArguments(), /Invalid Linux process command line/);
+test("invalid original arguments are reported instead of guessing an override", () => {
+ for (const args of [null, [], "siyuan", ["siyuan", null]]) {
+ assert.throws(() => readLinuxInputMethodArguments(args), /Invalid Linux launch arguments/);
}
});
test("compatibility mode does not alter other platforms", () => {
for (const platform of ["win32", "darwin"]) {
- const launch = commandLine();
- configureLinuxInputMethod(launch, true, platform);
- assert.equal(launch.hasSwitch("ozone-platform"), false);
+ const launch = prepareLinuxInputMethodLaunch(["siyuan"], true, platform);
+ assert.equal(launch.relaunchArgs, null);
}
});
diff --git a/app/electron/main.js b/app/electron/main.js
index 0f7e9284e9..81775060f9 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -91,7 +91,7 @@ const {
const {
readLinuxInputMethodSetting, writeLinuxInputMethodSetting, readLinuxInputMethodArguments,
- getLinuxInputMethodOverride, configureLinuxInputMethod,
+ prepareLinuxInputMethodLaunch, linuxInputMethodRelaunchEnvironment,
} = require("./linuxInputMethod");
process.noAsar = true;
@@ -103,6 +103,40 @@ const confDir = path.join(app.getPath("home"), ".config", "siyuan");
const windowStatePath = path.join(confDir, "windowState.json");
const linuxInputMethodSettingPath = path.join(confDir, "linux-input-method.json");
const accessibilitySettingPath = path.join(confDir, "accessibility.json");
+
+// 在单实例锁、窗口和内核启动前完成兼容模式重启,不修改已经选定的原生后端。
+let linuxInputMethodOverride = null;
+let linuxInputMethodArgumentsError = null;
+let linuxInputMethodEnabled = false;
+let linuxInputMethodLaunchArguments = process.argv;
+if (process.platform === "linux") {
+ try {
+ linuxInputMethodEnabled = readLinuxInputMethodSetting(linuxInputMethodSettingPath);
+ } catch (error) {
+ writeLog("read Linux input method setting failed: " + error.message);
+ }
+ try {
+ const launch = prepareLinuxInputMethodLaunch(readLinuxInputMethodArguments(), linuxInputMethodEnabled,
+ process.platform, process.env[linuxInputMethodRelaunchEnvironment]);
+ linuxInputMethodOverride = launch.override;
+ linuxInputMethodLaunchArguments = launch.args;
+ if (launch.relaunchArgs) {
+ if (launch.relaunchToken) {
+ process.env[linuxInputMethodRelaunchEnvironment] = launch.relaunchToken;
+ } else {
+ delete process.env[linuxInputMethodRelaunchEnvironment];
+ }
+ if (app.relaunch({args: launch.relaunchArgs}) === false) {
+ throw new Error("Linux input method relaunch failed");
+ }
+ app.exit(0);
+ }
+ } catch (error) {
+ linuxInputMethodArgumentsError = error;
+ writeLog("prepare Linux input method launch failed: " + error.message);
+ }
+}
+
const appCrashLogPath = path.join(confDir, "app.crash.log");
const appCrashMarkerPath = path.join(confDir, "app.crash.json");
const systemShutdownNone = 0;
@@ -774,8 +808,11 @@ if (!app.isPackaged) {
argStart = 2;
}
-for (let i = argStart; i < process.argv.length; i++) {
- let arg = process.argv[i];
+for (let i = argStart; i < linuxInputMethodLaunchArguments.length; i++) {
+ let arg = linuxInputMethodLaunchArguments[i];
+ if (arg === "--") {
+ break;
+ }
if (arg.startsWith("--workspace=") || arg.startsWith("--openAsHidden") || arg.startsWith("--port=") ||
arg.startsWith("--safe-mode=") || arg.startsWith("--lang=") || arg.startsWith("--connection-session=") || arg === "--remote" ||
arg.startsWith("--remote=") || arg === "--trust-remote-extensions" ||
@@ -809,26 +846,6 @@ try {
}
configureAccessibility(app.commandLine, accessibilityEnabled);
-// Linux 输入法兼容设置在窗口创建前应用,显式显示后端参数保持优先。
-let linuxInputMethodOverride = null;
-let linuxInputMethodArgumentsError = null;
-let linuxInputMethodEnabled = false;
-if (process.platform === "linux") {
- try {
- linuxInputMethodEnabled = readLinuxInputMethodSetting(linuxInputMethodSettingPath);
- } catch (error) {
- writeLog("read Linux input method setting failed: " + error.message);
- }
- try {
- const args = readLinuxInputMethodArguments();
- linuxInputMethodOverride = getLinuxInputMethodOverride(args);
- configureLinuxInputMethod(app.commandLine, linuxInputMethodEnabled, process.platform, args);
- } catch (error) {
- linuxInputMethodArgumentsError = error;
- writeLog("read Linux process command line failed: " + error.message);
- }
-}
-
try {
firstOpen = !remoteKernelTarget && !fs.existsSync(path.join(confDir, "workspace.json"));
if (!fs.existsSync(confDir)) {
@@ -3118,7 +3135,7 @@ app.whenReady().then(() => {
if (pendingConnectionArgs || updateInstallPromise || systemShutdownState !== systemShutdownNone) {
return;
}
- pendingConnectionArgs = connectionArgs(process.argv.slice(1), target, remoteKernelTarget?.origin);
+ pendingConnectionArgs = connectionArgs(linuxInputMethodLaunchArguments.slice(1), target, remoteKernelTarget?.origin);
try {
await closeConnectionWindows(BrowserWindow.getAllWindows().filter(window =>
windowKernelTargets.has(window.webContents.id) &&