windows – 在Electron应用程序上处理Squirrel的活动

这些天我用 Electron来为Windows构建一个小的本机应用程序,我正在使用 Grunt Electron Installer为我的应用程序创建一个安装程序.

安装程序已成功创建,但我不知道如何在我的应用程序中处理Squirrel的事件,如我在应用程序的入口点添加此文档中所述:

var handleStartupEvent = function() {
    if (process.platform !== 'win32') {
        return false;
    }

    var squirrelCommand = process.argv[1];
    switch (squirrelCommand) {
        case '--squirrel-install':
        case '--squirrel-updated':

            // Optionally do things such as:
            //
            // - Install desktop and start menu shortcuts
            // - Add your .exe to the PATH
            // - Write to the registry for things like file associations and
            //   explorer context menus

            // Always quit when done
            app.quit();

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

            // Always quit when done
            app.quit();

            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;
    }
};

if (handleStartupEvent()) {
    return;
}

但我不知道在这个switch语句中要做什么,例如,为我的应用程序创建快捷方式.实际上我甚至不知道这个开关是否有效,因为当我安装(或卸载)我的应用程序时它会启动并且永不退出.

任何帮助表示赞赏!

您可以处理每个Squirrel事件并创建快捷方式:
case '--squirrel-install':
          target = path.basename(process.execPath);
          updateDotExe = path.resolve(path.dirname(process.execPath),'..','update.exe');
          var createShortcut = updateDotExe + ' --createShortcut=' + target + ' --shortcut-locations=Desktop,StartMenu' ;
          console.log (createShortcut);
          exec(createShortcut);
          // Always quit when done
          app.quit();
          return true;

case '--squirrel-uninstall':
            // Undo anything you did in the --squirrel-install and
            // --squirrel-updated handlers
            target = path.basename(process.execPath);
            updateDotExe = path.resolve(path.dirname(process.execPath),'update.exe');
            var createShortcut = updateDotExe + ' --removeShortcut=' + target ;
            console.log (createShortcut);
            exec(createShortcut);
            // Always quit when done
            app.quit();
            return true;

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...