Hew*_*bot 5 build node.js electron
我使用 Electron 创建了一个应用程序,并将其捆绑在一个.exe带有electron-builder.
electron-builder当我运行生成的可执行文件时,应用程序按照预期以所使用的默认安装 GIF 启动。
GIF 完成后,应用程序将重新启动并正常工作。它甚至出现在控制面板的程序列表中。
但是,如果我在开始菜单应用程序中查找它,它不在那里(并且按其名称搜索它只会返回上述.exe安装程序)。
因此,一旦应用程序关闭,重新打开它的唯一方法就是再次运行安装程序。
为什么会出现这种情况?有什么办法让它和其他程序一起出现吗?
electro-builder 安装程序(和 electro-windows-installer)使用Squirrel来处理安装。Squirrel 在安装时启动您的应用程序,并带有您需要处理的参数。可以在Windows 安装程序 github 文档中找到示例
处理松鼠事件
Squirrel 将在首次运行、更新和卸载时使用命令行标志生成您的应用程序。您的应用程序尽早处理这些事件并在处理后立即退出非常重要。Squirrel 将为您的应用程序提供较短的时间(约 15 秒)来应用这些操作并退出。
electro-squirrel-startup 模块将为您处理最常见的事件,例如管理桌面快捷方式。只需将以下内容添加到 main.js 的顶部即可:
Run Code Online (Sandbox Code Playgroud)if (require('electron-squirrel-startup')) return;您应该在应用程序的主入口点中使用以下内容处理这些事件:
Run Code Online (Sandbox Code Playgroud)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; } };请注意,安装程序第一次启动您的应用程序时,您的应用程序将看到 --squirrel-firstrun 标志。这允许您执行一些操作,例如显示启动屏幕或呈现设置 UI。另一件需要注意的事情是,由于应用程序是由 squirrel 生成的,并且 squirrel 在安装过程中获取了文件锁,因此直到几秒钟后 squirrel 释放锁时,您才能成功检查应用程序更新。
在此示例中,您可以看到它使用参数 --create-shortcut 运行 Update.exe(一个 squirrel 可执行文件),该参数添加了开始菜单和桌面快捷方式。