2017-05-15 62 views
1

我有一個Electron應用程序,我正在爲Mac製作Windows安裝程序。通過與Electron的松鼠事件創建桌面快捷方式

現在我有一個/ installers目錄和一個setupEvents.js文件來處理所有的Squirrel事件。大部分是從Windows installer documentation

import { app } from 'electron'; 
module.exports = { 
    handleSquirrelEvent: function() { 
    if (process.argv.length === 1) { 
     return false; 
    } 

    const ChildProcess = require('child_process'); 
    const path = require('path'); 

    const appFolder = path.resolve(process.execPath, '..'); 
    const rootAtomFolder = path.resolve(appFolder, '..'); 
    const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe')); 
    const exeName = path.basename(process.execPath); 
    const spawn = function(command, args) { 
     let spawnedProcess, error; 

     try { 
     spawnedProcess = ChildProcess.spawn(command, args, {detached: true}); 
     } catch (error) {} 

     return spawnedProcess; 
    }; 

    const spawnUpdate = function(args) { 
     return spawn(updateDotExe, args); 
    }; 

    const squirrelEvent = process.argv[1]; 
    switch (squirrelEvent) { 
     case '--squirrel-install': 
     case '--squirrel-updated': 
     // Optionally do things such as: 
     // - Add your .exe to the PATH 
     // - Write to the registry for things like file associations and 
     // explorer context menus 

     // Install desktop and start menu shortcuts 
     spawnUpdate(['--createShortcut', exeName]); 

     setTimeout(app.quit, 1000); 
     return true; 

     case '--squirrel-uninstall': 
     // Undo anything you did in the --squirrel-install and 
     // --squirrel-updated handlers 

     // Remove desktop and start menu shortcuts 
     spawnUpdate(['--removeShortcut', exeName]); 

     setTimeout(app.quit, 1000); 
     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; 
    } 
    } 
} 

到目前爲止,這正常工作,不同之處在於添加到桌面的標題爲「電子」的快捷方式圖標,我不知道如何更改。我的package.json中有一個名稱,產品名稱:

{ 
    "name": "my app", 
    "description": "my app description", 
    "productName": "my app", 
    "appCopyright": "me", 
    "appCategoryType": "Productivity", 
... 

而且我安裝的配置是這樣的:

{ 
    appDirectory: path.join(outPath, 'myapp-win32-ia32/'), 
    authors: 'me', 
    noMsi: true, 
    outputDirectory: path.join(outPath, 'windows-installer'), 
    exe: 'myapp.exe', 
    setupExe: 'myappInstaller.exe', 
    setupIcon: path.join(rootPath, 'assets', 'win', 'icon.ico'), 
    skipUpdateIcon: true 
    } 

我不知道在哪裏可以告訴安裝程序的快捷方式圖標應該有我的應用程序的名稱,而不是「電子」。

在此先感謝!

回答

2

我終於明白了。

在您的project.json文件中,您用於構建應用程序的命令是代碼的執行位置。

你要找的那部分是--version-string.ProductName=\"My App Name\""scripts": { "build": "YOUR CODE HERE"}發現:

附註...我使用的是電子打包。

下面是一個例子使用我的代碼:
"pack:win64": "electron-packager ./ --overwrite --asar=true --platform=win32 --arch=x64 --ignore=assets --ignore=build --ignore=installers --icon=./images/icons/icon.ico --prune=true --out=build/win --version-string.ProductName=\"My App Name\""

+1

這個工作!謝謝!! –

+0

它現在變成'win32metadata' –

相關問題