Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-03-06 10:28:08 +08:00
parent c39b25f1ef
commit 0080deca32
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -63,8 +63,39 @@ if (!app.requestSingleInstanceLock()) {
}
if (process.platform === "linux") {
app.commandLine.appendSwitch("enable-wayland-ime");
app.commandLine.appendSwitch("wayland-text-input-version", "3");
// Linux 平台回退到 x11/XWayland 以解决某些系统上无法输入中文的问题
// 如果需要使用原生 Wayland 可以通过启动参数 --ozone-platform=wayland 进行覆盖
app.commandLine.appendSwitch('ozone-platform', 'x11');
}
app.setAsDefaultProtocolClient("siyuan");
app.commandLine.appendSwitch("disable-web-security");
app.commandLine.appendSwitch("auto-detect", "false");
app.commandLine.appendSwitch("no-proxy-server");
app.commandLine.appendSwitch("enable-features", "PlatformHEVCDecoderSupport");
app.commandLine.appendSwitch("xdg-portal-required-version", "4");
// Support set Chromium command line arguments on the desktop https://github.com/siyuan-note/siyuan/issues/9696
writeLog("app is packaged [" + app.isPackaged + "], command line args [" + process.argv.join(", ") + "]");
let argStart = 1;
if (!app.isPackaged) {
argStart = 2;
}
for (let i = argStart; i < process.argv.length; i++) {
let arg = process.argv[i];
if (arg.startsWith("--workspace=") || arg.startsWith("--openAsHidden") || arg.startsWith("--port=") || arg.startsWith("siyuan://")) {
// 跳过内置参数
if (arg.startsWith("--openAsHidden")) {
openAsHidden = true;
writeLog("open as hidden");
}
continue;
}
app.commandLine.appendSwitch(arg);
writeLog("command line switch [" + arg + "]");
}
try {
@ -297,28 +328,6 @@ const showErrorWindow = (titleZh, titleEn, content, emoji = "⚠️") => {
return errWindow.id;
};
const writeLog = (out) => {
console.log(out);
const logFile = path.join(confDir, "app.log");
let log = "";
const maxLogLines = 1024;
try {
if (fs.existsSync(logFile)) {
log = fs.readFileSync(logFile).toString();
let lines = log.split("\n");
if (maxLogLines < lines.length) {
log = lines.slice(maxLogLines / 2, maxLogLines).join("\n") + "\n";
}
}
out = out.toString();
out = new Date().toISOString().replace(/T/, " ").replace(/\..+/, "") + " " + out;
log += out + "\n";
fs.writeFileSync(logFile, log);
} catch (e) {
console.error(e);
}
};
let openAsHidden = false;
const isOpenAsHidden = function () {
return 1 === workspaces.length && openAsHidden;
@ -730,36 +739,6 @@ const initKernel = (workspace, port, lang) => {
});
};
app.setAsDefaultProtocolClient("siyuan");
app.commandLine.appendSwitch("disable-web-security");
app.commandLine.appendSwitch("auto-detect", "false");
app.commandLine.appendSwitch("no-proxy-server");
app.commandLine.appendSwitch("enable-features", "PlatformHEVCDecoderSupport");
app.commandLine.appendSwitch("xdg-portal-required-version", "4");
// Support set Chromium command line arguments on the desktop https://github.com/siyuan-note/siyuan/issues/9696
writeLog("app is packaged [" + app.isPackaged + "], command line args [" + process.argv.join(", ") + "]");
let argStart = 1;
if (!app.isPackaged) {
argStart = 2;
}
for (let i = argStart; i < process.argv.length; i++) {
let arg = process.argv[i];
if (arg.startsWith("--workspace=") || arg.startsWith("--openAsHidden") || arg.startsWith("--port=") || arg.startsWith("siyuan://")) {
// 跳过内置参数
if (arg.startsWith("--openAsHidden")) {
openAsHidden = true;
writeLog("open as hidden");
}
continue;
}
app.commandLine.appendSwitch(arg);
writeLog("command line switch [" + arg + "]");
}
app.whenReady().then(() => {
const resetTrayMenu = (tray, lang, mainWindow) => {
if (!mainWindow || mainWindow.isDestroyed()) {
@ -1542,3 +1521,26 @@ app.on("before-quit", (event) => {
}
});
});
function writeLog(out) {
console.log(out);
const logFile = path.join(confDir, "app.log");
let log = "";
const maxLogLines = 1024;
try {
if (fs.existsSync(logFile)) {
log = fs.readFileSync(logFile).toString();
let lines = log.split("\n");
if (maxLogLines < lines.length) {
log = lines.slice(maxLogLines / 2, maxLogLines).join("\n") + "\n";
}
}
out = out.toString();
out = new Date().toISOString().replace(/T/, " ").replace(/\..+/, "") + " " + out;
log += out + "\n";
fs.writeFileSync(logFile, log);
} catch (e) {
console.error(e);
}
}