2015-11-06 94 views
1

我已经使用了一段时间的电子,并且已经构建了几个应用程序,但还没有弄清楚如何去创建桌面图标和Windows安装程序(在电子主页上,它特别指出,使Windows安装程序“变得轻松“)制作应用程序的桌面安装程序?

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

我知道这似乎是一个愚蠢的问题,但我只是不明白少特定指令(如http://electron.atom.io/docs/v0.34.0/tutorial/application-distribution/有点帮助,但太模糊。)

回答

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

注意,在电子的新版本,你可以使用auto-updater处理Squirrel.Windows事件,但API是一个有点不同,所以我不知道如何正确使用auto-updater

相关问题