Browse Source

add installer
remove obsolete build scripts, use npm scripts instead

Andrew Dolgov 7 months ago
parent
commit
15590a510f
7 changed files with 921 additions and 59 deletions
  1. 6 0
      README.md
  2. 7 0
      app.js
  3. 0 8
      build.cmd
  4. 26 0
      createInstaller.js
  5. 807 47
      package-lock.json
  6. 9 4
      package.json
  7. 66 0
      setupEvents.js

+ 6 - 0
README.md

@@ -3,6 +3,12 @@ Pow! Comics Reader (desktop)
 
 Minimalistic CBZ reader, quasi-desktop version using Electron. Supports network sync, etc.
 
+Building
+========
+
+ - ``npm run package-win``
+ - ``npm run create-installer-win``
+
 License
 =======
 

+ 7 - 0
app.js

@@ -1,3 +1,10 @@
+const setupEvents = require('./setupEvents')
+ 
+if (setupEvents.handleSquirrelEvent()) {
+	// squirrel event handled and app will exit in 1000ms, so don't do anything else
+	return;
+}
+
 // Modules to control application life and create native browser window
 const {app, BrowserWindow, Menu} = require('electron');
 

+ 0 - 8
build.cmd

@@ -1,8 +0,0 @@
-call npm install
-
-cd ..
-
-call npm install -g electron-packager
-
-call electron-packager tt-comics-desktop --platform win32 --arch x64 --icon tt-comics-desktop/img/ic_launcher.ico --overwrite
-	

+ 26 - 0
createInstaller.js

@@ -0,0 +1,26 @@
+const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
+
+const path = require('path')
+
+getInstallerConfig()
+  .then(createWindowsInstaller)
+  .catch((error) => {
+    console.error(error.message || error)
+    process.exit(1)
+  });
+
+function getInstallerConfig () {
+  console.log('creating windows installer')
+  const rootPath = path.join('./')
+  const outPath = path.join(rootPath, 'release-builds')
+
+  return Promise.resolve({
+    appDirectory: path.join(outPath, 'Pow! Comics Reader-win32-x64'),
+    authors: 'fox',
+    noMsi: true,
+    outputDirectory: path.join(outPath, 'installer'),
+    exe: 'Pow! Comics Reader.exe',
+    setupExe: 'setup.exe',
+    setupIcon: path.join(rootPath, 'img', 'ic_launcher.ico')
+  });
+}

File diff suppressed because it is too large
+ 807 - 47
package-lock.json


+ 9 - 4
package.json

@@ -1,16 +1,19 @@
 {
   "name": "tt-comics",
   "productName": "Pow! Comics Reader",
-  "version": "1.0",
+  "version": "1.0.1",
   "description": "Pow! Comics Reader",
   "main": "app.js",
   "license": "GPL-3.0",
   "scripts": {
-    "start": "electron ."
+    "start": "electron .",
+    "package-win": "electron-packager . --platform win32 --arch x64 --icon img/ic_launcher.ico --overwrite --prune=true --out=release-builds",
+    "create-installer-win": "node createInstaller.js"
   },
   "repository": "",
   "keywords": [
-    "Electron"
+    "Comics",
+    "CBZ"
   ],
   "author": "fox",
   "dependencies": {
@@ -19,6 +22,8 @@
     "js-sha1": "^0.6.0"
   },
   "devDependencies": {
-    "electron": "^4.0.7"
+    "electron": "^4.0.7",
+    "electron-packager": "^14.1.0",
+    "electron-winstaller": "^4.0.0"
   }
 }

+ 66 - 0
setupEvents.js

@@ -0,0 +1,66 @@
+const electron = require('electron')
+const app = electron.app
+
+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;
+		}
+	}
+}

Some files were not shown because too many files changed in this diff