diff --git a/README.md b/README.md index 62db6d9..884020a 100644 --- a/README.md +++ b/README.md @@ -35,24 +35,35 @@ If you can't use GitHub, you can use other providers: npm install -4. Generate a GitHub access token by going to . The access token should have the `repo` scope/permission. Once you have the token, assign it to an environment variable +4. Generate a GitHub access token by going to . The access token should have the `repo` scope/permission. Once you have the token, assign it to an environment variable - (on macOS/linux): + On macOS/linux: export GH_TOKEN="" - (on Windows, run in powershell): + On Windows, run in powershell: [Environment]::SetEnvironmentVariable("GH_TOKEN","","User") - make sure to restart IDE/Terminal to inherit latest env variable. + Make sure to restart IDE/Terminal to inherit latest env variable. -5. Publish with the `publish.sh` script: +5. Publish for your platform with: - ./publish.sh - In case of Windows, directly run the command: ```node_modules/.bin/build --win -p always``` + build -p always + + or + + npm run publish + + If you want to publish for more platforms, edit the `publish` script in `package.json`. For instance, to build for Windows and macOS: + + ... + "scripts": { + "publish": "build --mac --win -p always" + }, + ... -6. Release the release on GitHub by going to , editing the release and clicking "Publish release." +6. Release the release on GitHub by going to , editing the release and clicking "Publish release." 7. Download and install the app from . diff --git a/main.js b/main.js index c8d7b46..b5bd58a 100644 --- a/main.js +++ b/main.js @@ -77,7 +77,7 @@ autoUpdater.on('update-not-available', (info) => { sendStatusToWindow('Update not available.'); }) autoUpdater.on('error', (err) => { - sendStatusToWindow('Error in auto-updater.'); + sendStatusToWindow('Error in auto-updater. ' + err); }) autoUpdater.on('download-progress', (progressObj) => { let log_message = "Download speed: " + progressObj.bytesPerSecond; @@ -86,7 +86,7 @@ autoUpdater.on('download-progress', (progressObj) => { sendStatusToWindow(log_message); }) autoUpdater.on('update-downloaded', (info) => { - sendStatusToWindow('Update downloaded; will install in 5 seconds'); + sendStatusToWindow('Update downloaded'); }); app.on('ready', function() { // Create the Menu @@ -99,8 +99,22 @@ app.on('window-all-closed', () => { app.quit(); }); +// +// CHOOSE one of the following options for Auto updates +// + +//------------------------------------------------------------------- +// Auto updates - Option 1 - Simplest version +// +// This will immediately download an update, then install when the +// app quits. +//------------------------------------------------------------------- +app.on('ready', function() { + autoUpdater.checkForUpdatesAndNotify(); +}); + //------------------------------------------------------------------- -// Auto updates +// Auto updates - Option 2 - More control // // For details about these events, see the Wiki: // https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events @@ -110,6 +124,9 @@ app.on('window-all-closed', () => { // Uncomment any of the below events to listen for them. Also, // look in the previous section to see them being used. //------------------------------------------------------------------- +// app.on('ready', function() { +// autoUpdater.checkForUpdates(); +// }); // autoUpdater.on('checking-for-update', () => { // }) // autoUpdater.on('update-available', (info) => { @@ -120,20 +137,6 @@ app.on('window-all-closed', () => { // }) // autoUpdater.on('download-progress', (progressObj) => { // }) -autoUpdater.on('update-downloaded', (info) => { - // Wait 5 seconds, then quit and install - // In your application, you don't need to wait 5 seconds. - // You could call autoUpdater.quitAndInstall(); immediately - setTimeout(function() { - autoUpdater.quitAndInstall(); - }, 5000) -}) - -app.on('ready', function() { - autoUpdater.checkForUpdates(); -}); - -// Update will be downloaded now but installed only on the next launch of the app -// app.on('ready', function() { -// autoUpdater.checkForUpdatesAndNotify() -// }); \ No newline at end of file +// autoUpdater.on('update-downloaded', (info) => { +// autoUpdater.quitAndInstall(); +// }) diff --git a/package.json b/package.json index 26dc838..058c090 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,12 @@ { "name": "electron-updater-example", - "version": "0.4.2", + "version": "0.5.0", "main": "main.js", "description": "electron-updater example project", "author": "Matt Haggard", + "scripts": { + "publish": "build -p always" + }, "devDependencies": { "electron": "^1.7.9", "electron-builder": "^19.43.3" diff --git a/publish.sh b/publish.sh deleted file mode 100755 index eda2cd4..0000000 --- a/publish.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -if [ -z "$GH_TOKEN" ]; then - echo "You must set the GH_TOKEN environment variable." - echo "See README.md for more details." - exit 1 -fi - -# This will build, package and upload the app to GitHub. -node_modules/.bin/build --win --mac -p always