gpt4 book ai didi

node.js - 已安装 Electron 应用程序但未出现在开始菜单中

转载 作者:搜寻专家 更新时间:2023-10-31 23:24:04 25 4
gpt4 key购买 nike

我使用 Electron 创建了一个应用程序,并将其捆绑在 .exe 文件中 electron-builder .

当我运行生成的可执行文件时,应用程序以 electron-builder 使用的默认安装 GIF 启动,正如预期的那样。

Default installation GIF

GIF 完成后,应用程序会重新启动并正常运行。它甚至出现在控制面板的程序列表中

但是,如果我在开始菜单应用程序中查找它,它不存在(并且按名称搜索它只会返回上述 .exe 安装程序)。
因此,一旦应用程序关闭,重新打开它的唯一方法就是再次运行安装程序。

为什么会这样?有什么办法让它与其他程序一起出现吗?

最佳答案

electron-builder 安装程序(和 electron-windows-installer)使用 Squirrel用于处理安装。 Squirrel 在安装时使用您需要处理的参数启动您的应用程序。可以在 windows installer github docs 上找到示例

Handling Squirrel Events

Squirrel will spawn your app with command line flags on first run, updates, and uninstalls. it is very important that your app handle these events as early as possible, and quit immediately after handling them. Squirrel will give your app a short amount of time (~15sec) to apply these operations and quit.

The electron-squirrel-startup module will handle the most common events for you, such as managing desktop shortcuts. Just add the following to the top of your main.js and you're good to go:

if (require('electron-squirrel-startup')) return;

You should handle these events in your app's main entry point with something such as:

const app = require('app');

// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}

function handleSquirrelEvent() {
if (process.argv.length === 1) {
return false;
}

const ChildProcess = require('child_process');
const path = require('path');

const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);

const spawn = function(command, args) {
let spawnedProcess, error;

try {
spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
} catch (error) {}

return spawnedProcess;
};

const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};

const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus

// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);

setTimeout(app.quit, 1000);
return true;

case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers

// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);

setTimeout(app.quit, 1000);
return true;

case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated

app.quit();
return true;
}
};

Notice that the first time the installer launches your app, your app will see a --squirrel-firstrun flag. This allows you to do things like showing up a splash screen or presenting a settings UI. Another thing to be aware of is that, since the app is spawned by squirrel and squirrel acquires a file lock during installation, you won't be able to successfully check for app updates till a few seconds later when squirrel releases the lock.

在此示例中,您可以看到它使用添加开始菜单和桌面快捷方式的参数 --create-shortcut 运行 Update.exe(松鼠可执行文件)。

关于node.js - 已安装 Electron 应用程序但未出现在开始菜单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com