Skip to content

Commit

Permalink
🎨 #11145
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 28, 2024
1 parent e7a1902 commit 340333e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
29 changes: 22 additions & 7 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,15 @@ const initMainWindow = () => {

// 主界面事件监听
currentWindow.once("ready-to-show", () => {
currentWindow.show();
if (windowState.isMaximized) {
currentWindow.maximize();
if (workspaces.length === 0 && openAsHidden) {
bootWindow.minimize();
} else {
currentWindow.unmaximize();
currentWindow.show();
if (windowState.isMaximized) {
currentWindow.maximize();
} else {
currentWindow.unmaximize();
}
}
if (bootWindow && !bootWindow.isDestroyed()) {
bootWindow.destroy();
Expand Down Expand Up @@ -451,7 +455,11 @@ const initKernel = (workspace, port, lang) => {
bootIndex = path.join(appDir, "electron", "boot.html");
}
bootWindow.loadFile(bootIndex, {query: {v: appVer}});
bootWindow.show();
if (openAsHidden) {
bootWindow.minimize();
} else {
bootWindow.show();
}

const kernelName = "win32" === process.platform ? "SiYuan-Kernel.exe" : "SiYuan-Kernel";
const kernelPath = path.join(appDir, "kernel", kernelName);
Expand Down Expand Up @@ -625,10 +633,14 @@ let argStart = 1;
if (!app.isPackaged) {
argStart = 2;
}
let openAsHidden = false;
for (let i = argStart; i < process.argv.length; i++) {
let arg = process.argv[i];
if (arg.startsWith("--workspace=") || arg.startsWith("--port=") || arg.startsWith("siyuan://")) {
if (arg.startsWith("--workspace=") || arg.startsWith("--openAsHidden") || arg.startsWith("--port=") || arg.startsWith("siyuan://")) {
// 跳过内置参数
if (arg.startsWith("--openAsHidden")) {
openAsHidden = true;
}
continue;
}

Expand Down Expand Up @@ -1118,7 +1130,10 @@ app.whenReady().then(() => {
});
});
ipcMain.on("siyuan-auto-launch", (event, data) => {
app.setLoginItemSettings({openAtLogin: data.openAtLogin});
app.setLoginItemSettings({
openAtLogin: data.openAtLogin,
args: data.openAsHidden ? ["--openAsHidden"] : ""
});
});

if (firstOpen) {
Expand Down
9 changes: 6 additions & 3 deletions app/src/config/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {fetchPost} from "../util/fetch";
import {setAccessAuthCode} from "./util/about";
import {exportLayout} from "../layout/util";
import {exitSiYuan, processSync} from "../dialog/processSystem";
import {isInAndroid, isInIOS, isIPad, openByMobile, writeText} from "../protyle/util/compatibility";
import {isInAndroid, isInIOS, isIPad, isMac, openByMobile, writeText} from "../protyle/util/compatibility";
import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {confirmDialog} from "../dialog/confirmDialog";
Expand All @@ -25,7 +25,7 @@ export const about = {
<select class="b3-select fn__flex-center fn__size200" id="autoLaunch">
<option value="0" ${window.siyuan.config.system.autoLaunch2 === 0 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode0}</option>
<option value="1" ${window.siyuan.config.system.autoLaunch2 === 1 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode1}</option>
<option value="2" ${window.siyuan.config.system.autoLaunch2 === 2 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode2}</option>
${isMac() ? "" : `<option value="2" ${window.siyuan.config.system.autoLaunch2 === 2 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode2}</option>`}
</select>
</div>
<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore || window.siyuan.config.system.container !== "std" ? " fn__none" : ""}">
Expand Down Expand Up @@ -355,7 +355,10 @@ export const about = {
const autoLaunchMode = parseInt(autoLaunchElement.value)
fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchMode}, () => {
window.siyuan.config.system.autoLaunch2 = autoLaunchMode;
ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, {openAtLogin: 0 != autoLaunchMode});
ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, {
openAtLogin: 0 !== autoLaunchMode,
openAsHidden: 2 === autoLaunchMode
});
});
});
/// #endif
Expand Down

0 comments on commit 340333e

Please sign in to comment.