英文:
electron app should run as a background process in windows after startup
问题
以下是您要翻译的内容:
"openAsHidden attribute of app.setLoginItemSettings work only with MAC. Then how does electron built apps like Slack startup as hidden and only shows up in the system tray on windows? Which method do they use?
Is there a way with which I can determine if the app is opened by system startup or by the user, so I can use the window.hide() and window.show() accordingly with dom-ready event.
I have tried following way to achieve it:
app.on("ready", async () => {
app.setLoginItemSettings({
openAtLogin: true,
openAsHidden: true,
path: exeName,
args: [
"--processStart",
`"${exeName}"`,
"--process-start-args",
`"--hidden"`
]
});
})
```"
<details>
<summary>英文:</summary>
openAsHidden attribute of app.setLoginItemSettings work only with MAC. Then how does electron built apps like Slack startup as hidden and only shows up in the system tray on windows? Which method do they use?
Is there a way with which I can determine if the app is opened by system startup or by the user, so I can use the window.hide() and window.show() accordingly with dom-ready event.
I have tried following way to achieve it:
```javascript
app.on("ready", async () => {
app.setLoginItemSettings({
openAtLogin: true,
openAsHidden: true,
path: exeName,
args: [
"--processStart",
`"${exeName}"`,
"--process-start-args",
`"--hidden"`
]
});
})
答案1
得分: 0
这个检查有效:
var isLaunchedOnStartup = process.argv.indexOf("--hidden") !== -1;
在app.ready
内部:
if (isLaunchedOnStartup === true) {
createWindow();
mainWindow?.hide();
} else {
createWindow();
mainWindow?.show();
}
默认情况下,BrowserWindow
应该是隐藏的:
mainWindow = new BrowserWindow({show: false});
英文:
This check works:
var isLaunchedOnStartup = process.argv.indexOf("--hidden") !== -1;
and inside app.ready
if (isLaunchedOnStartup === true) {
createWindow();
mainWindow?.hide();
} else {
createWindow();
mainWindow?.show();
}
and by default BrowserWindow should be hidden:
mainWindow = new BrowserWindow({show: false});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论