在 Electron 应用程序上处理 Squirrel 的事件 [英] Handle Squirrel's event on an Electron app

查看:15
本文介绍了在 Electron 应用程序上处理 Squirrel 的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我正在玩弄 Electron 来为 Windows 构建一个小型原生应用程序,我'm 使用 Grunt Electron Installer 为我的应用程序创建安装程序.

These days I'm toyng around with Electron to build a small native app for Windows and I'm using Grunt Electron Installer to create an installer for my application.

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

The installer is created successfully but I don't know how ho handle Squirrel's events inside my app, as stated in the docs I've added this to the entry point of my app:

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 语句中要做什么,例如,为我的应用程序创建快捷方式.实际上我什至根本不知道这个开关是否有效,因为当我安装(或卸载)我的应用程序时,它会启动并且永远不会退出.

But I don't know what to do inside this switch statement to, for example, create shortcuts for my application. Actually I don't even know if this switch works at all because when I install (or uninstall) my application it get launched and never quits.

感谢任何帮助!

推荐答案

您可以处理每个 Squirrel 事件并创建快捷方式:

You could handle each Squirrel event and create shortcuts:

  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;

这篇关于在 Electron 应用程序上处理 Squirrel 的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆