最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Electron app auto launch shows an additional window due to incorrect app path - Stack Overflow

programmeradmin2浏览0评论

I'm using the app.setLoginItemSettings(settings) for auto launching the app when system starts. The example given in the Electron API doc page is for Windows I believe. When adding the following in the Electron main.js, the app auto launches just fine but also shows an additional window that says the following which I don't want:

To run a local app, execute the following on the mand line:
Users/abc/Documents/Repositories/app/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron path-to-app

main.js

const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
const exeName = path.basename(process.execPath)

import { app } from "electron";

app.on("ready", async() => {
  app.setLoginItemSettings({
    openAtLogin: true,
    path: updateExe,
    args: [
      '--processStart', `"${exeName}"`,
      '--process-start-args', `"--hidden"`
    ]
  });
});

I also tried with the following path but that also didn't work:

const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
const exeName = path.basename(process.execPath)

import { app } from "electron";

app.on("ready", async() => {
  app.setLoginItemSettings({
    openAtLogin: true,
    path: "/Applications/MyApp.app",
    args: [
      '--processStart', `"${exeName}"`,
      '--process-start-args', `"--hidden"`
    ]
  });
});

In addition, also tried with the Electron Root Path package but still no luck:

const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
const exeName = path.basename(process.execPath)

import { app } from "electron";
import { rootPath } from "electron-root-path";

app.on("ready", async() => {
  app.setLoginItemSettings({
    openAtLogin: true,
    path: rootPath,
    args: [
      '--processStart', `"${exeName}"`,
      '--process-start-args', `"--hidden"`
    ]
  });
});

Last but not least

发布评论

评论列表(0)

  1. 暂无评论