gpt4 book ai didi

node.js - 在 Electron 应用程序的 Squirrel 事件中执行 createShortcut

转载 作者:可可西里 更新时间:2023-11-01 09:20:00 27 4
gpt4 key购买 nike

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

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

Handle Squirrel's event on an Electron app

我曾尝试使用 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');
});

如有任何帮助,我们将不胜感激

最佳答案

我自己花了一段时间才明白如何做到这一点。 Squirrel.Windows Update.exe 能够为您创建应用程序的快捷方式。我写了一篇名为 Creating a Windows Distribution of an Electron App using Squirrel 的博文在其中我让 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 或其他应用程序破解 electron 可执行文件以更改 ProductName 和 Icon 资源。您需要在安装和更新的 Squirrel 事件中调用上述代码。

关于node.js - 在 Electron 应用程序的 Squirrel 事件中执行 createShortcut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com