为应用程序制作桌面安装程序?

时间:2015-11-06 00:00:22

标签: node.js electron

我一直在使用电子并且已经构建了几个应用程序,但是还没有弄清楚如何创建桌面图标和Windows安装程序(在电子主页上,它具体说明了制作Windows安装程序是&# 34;轻松"。)

我如何为Windows制作这样的安装程序,以及为典型电子设置中的应用程序自动安装桌面图标(GNOME的.desktop,Windows的快捷方式)?

我知道这可能看起来像一个愚蠢的问题,但我无法理解不太具体的说明(例如http://electron.atom.io/docs/v0.34.0/tutorial/application-distribution/有点帮助,但太模糊了。)

1 个答案:

答案 0 :(得分:1)

之前我做过一些研究,发现创建Windows安装程序并不容易。

  1. 使用grunt-electron-installer创建Windows安装程序。请注意,它只会在安装时显示gif。没有交互式对话框。它使用Squirrel.Windows

  2. 使用Update.exe --createShortcut=<comma separated locations> <your exe>创建快捷方式。可用的位置包括DesktopStartMenuStartupAppRoot

    安装时,

    Update.exe将与您的应用一起发货。我发现this article非常有帮助。简而言之,你需要这样的东西:

    var app = require('app');
    var path = require('path');
    var cp = require('child_process');
    
    var handleSquirrelEvent = function() {
       if (process.platform != 'win32') {
          return false;
       }
    
       function executeSquirrelCommand(args, done) {
          var updateDotExe = path.resolve(path.dirname(process.execPath), 
             '..', 'update.exe');
          var child = cp.spawn(updateDotExe, args, { detached: true });
          child.on('close', function(code) {
             done();
          });
       };
    
       function install(done) {
          var target = path.basename(process.execPath);
          executeSquirrelCommand(["--createShortcut", target], done);
       };
    
       function uninstall(done) {
          var target = path.basename(process.execPath);
          executeSquirrelCommand(["--removeShortcut", target], done);
       };
    
       var squirrelEvent = process.argv[1];
       switch (squirrelEvent) {
          case '--squirrel-install':
             install(app.quit);
             return true;
          case '--squirrel-updated':
             install(app.quit);
             return true;
          case '--squirrel-obsolete':
             app.quit();
             return true;
          case '--squirrel-uninstall':
             uninstall(app.quit);
             return true;
       }
    
       return false;
    };
    
    if (handleSquirrelEvent()) {
       return;
    }
    
  3. 请注意,在较新版本的Electron中,您可以使用auto-updater来处理Squirrel.Windows事件,但API有点不同,因此我不确定如何使用{{1}正确执行此操作}。

相关问题