Selaa lähdekoodia

Installer looking good on windows

Andrew Chalkley 9 vuotta sitten
vanhempi
commit
370306004c
2 muutettua tiedostoa jossa 74 lisäystä ja 3 poistoa
  1. 71 1
      index.js
  2. 3 2
      package.json

+ 71 - 1
index.js

@@ -1,4 +1,11 @@
 'use strict';
+if (require('electron-squirrel-startup')) return;
+
+// this should be placed at top of main.js to handle setup events quickly
+if (handleSquirrelEvent()) {
+  // squirrel event handled and app will exit in 1000ms, so don't do anything else
+  return;
+}
 
 const electron = require('electron');
 const app = electron.app;  // Module to control application life.
@@ -43,4 +50,67 @@ app.on('ready', function() {
     // when you should delete the corresponding element.
     mainWindow = null;
   });
-});
+});
+
+
+function handleSquirrelEvent() {
+  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;
+  }
+};

+ 3 - 2
package.json

@@ -7,7 +7,7 @@
     "start": "electron index.js",
     "rebuild": "electron-rebuild",
     "sign-mac": "electron-osx-sign out/flasher.js-darwin-x64/flasher.js.app",
-    "pack-win": "electron-packager . flasher.js --asar  --overwrite --platform=win32 --arch=x64 --icon=resources/icon.ico --prune=true --out=out --version-string.CompanyName='Andrew Chalkley' --version-string.FileDescription='Flasher.js' --version-string.ProductName='Flasher.js'",
+    "pack-win": "electron-packager . flasher.js --asar  --overwrite --platform=win32 --arch=x64 --icon=resources/icon.ico --prune=true --out=out --version-string.CompanyName=ThingsSDK --version-string.FileDescription=Flasher.js --version-string.ProductName=Flasher.js",
     "pack-mac": "electron-packager . --asar --overwrite --platform=darwin --arch=x64 --icon=resources/icon.icns --prune=true --out=out --osx-sign.identity='Developer ID Application: Secret Monkey Science'",
     "installer-win": "node ./scripts/windows-installer.js",
     "test": "mocha"
@@ -37,6 +37,7 @@
   "homepage": "https://github.com/thingsSDK/flasher.js#readme",
   "dependencies": {
     "bunyan": "^1.8.0",
+    "electron-squirrel-startup": "^1.0.0",
     "node-binary": "^1.1.0",
     "request": "^2.72.0",
     "serialport": "^2.0.7-beta1",
@@ -49,7 +50,7 @@
     "electron-prebuilt": "^0.36.9",
     "electron-rebuild": "^1.1.3",
     "electron-osx-sign": "^0.4.0-beta4",
-    "electron-winstaller":  "^2.2.0",
+    "electron-winstaller": "^2.2.0",
     "mocha": "^2.4.5"
   }
 }