3

当我安装或更新我的 Electron 应用程序时,我正在尝试为它创建快捷方式,但是我在执行用于创建快捷方式的命令时遇到了一些问题。默认情况下,Electron 应用程序是“SquirrelAware”,因此我必须指定我想在哪里创建快捷方式。

我的问题与这个问题的公认答案有关。

在 Electron 应用程序上处理 Squirrel 的事件

我曾尝试使用exec模块和child_process模块,但两者似乎都不起作用。我现在正在尝试(并且失败)启动 PowerShell 并在其中运行一个脚本,该脚本将在我的开始菜单和桌面上创建快捷方式,但是我觉得这相当长,并且必须有一个更简单的方法。

这是我目前使用 child_process 模块和 PowerShell 的尝试:

 var spawn = require('child_process').spawn, child;
 child = spawn("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",["C:\\ElectronSquirrelDemo\\AddAppShortcuts.ps1 -SourceExe "+ executionPath] );
                child.stdout.on('data', function(data){
                    console.log("PowerShell Data: " + data);
                });
                child.stdout.on('data', function(data){
                    console.log("PowerShell Error: " + data);
                });
                child.stdout.on('exit', function(){
                   console.log('PowerShell script finished'); 
                });

对此的任何帮助将不胜感激

4

1 回答 1

4

我花了一段时间才明白如何自己做这件事。Squirrel.Windows Update.exe 能够为您创建应用程序的快捷方式。我写了一篇名为使用 Squirrel 创建 Electron 应用程序的 Windows 发行版的博客文章,其中我让 Squirrel 为我创建了快捷方式。如果您想走这条路,这是如何让 Squirrel 为您创建快捷方式的简化版本:

var cp = require('child_process');    
var updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--createShortcut", target], { detached: true });
child.on('close', function(code) {
    app.quit();
});

您需要使用 Resource Hacker、rcedit 或其他应用程序破解电子可执行文件,以更改 ProductName 和 Icon 资源。您需要在安装和更新的 Squirrel 事件中调用上述代码。

于 2015-06-13T13:43:34.810 回答