I am trying to create an electron app that will auto-update new releases from github. Trying to do this for mac and windows right now.
I have been able to successfully create and sign a mac os .dmg programs by following this tutorial. The result is an electron app that when I am on my mac laptop and run npm run deploy
for a new version, it will build and package the program by running this command: electron-builder build --mac --win --publish always
The mac os .dmg file works like the tutorial instructs, it checks for updates in my main.js file and if a new version is published it will prompt the user to restart the app.
The tutorial is supposed to also work for windows, but the windows.exe that gets generated and upload to my github repo releases tab does not seem to auto-update. I test this by running my app windows portable .exe file: electron-auto-updater-1.0.2
after I have already released v1.0.3, so it should autoupdate but never does, and doesnt throw any err in my electron app window console.
Do I need to sign my windows exe for electron in a different way? Ultimately I am trying to create a bare minimum electron app for windows 10 with auto-updating. I have been looking online and following various old tutorial blog posts, the one i linked seems like the most recent (2019), and I followed every instruction for the signing procedure on a mac os laptop, but my code is not working on windows:
package.json
{
"name": "electron-auto-updater",
"productName": "Electron tutorial app",
"description": "Application for electron tutorials",
"version": "1.0.4",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-builder build --mac --win --publish never",
"deploy": "electron-builder build --mac --win --publish always",
"deploy-win": "electron-builder build --win --publish always",
"build-win": "electron-builder build --win --publish never"
},
"build": {
"appId": "yourAppId",
"afterSign": "scripts/notarize.js",
"mac": {
"icon": "build/icon.png",
"hardenedRuntime": true,
"gatekeeperAssess": false,
"entitlements": "build/entitlements.mac.plist",
"entitlementsInherit": "build/entitlements.mac.plist",
"target": [
"dmg",
"zip"
]
},
"dmg": {
"sign": false
},
"linux": {
"category": "TODO: fill here the category of your app",
"icon": "build/icon.png",
"target": [
"AppImage",
"deb"
]
},
"win": {
"target": "portable",
"icon": "build/icon.png"
}
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^11.0.3",
"electron-builder": "^22.9.1",
"electron-notarize": "^1.0.0",
"electron-winstaller": "^4.0.1"
},
"dependencies": {
"dotenv": "^8.2.0",
"electron-updater": "^4.3.5"
},
"repository": {
"type": "git",
"url": "https://github.com/MartinBarker/electron-auto-updater.git"
}
}
main.js
const { app, BrowserWindow, ipcMain } = require('electron');
const { autoUpdater } = require('electron-updater');
require('dotenv').config();
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadFile('index.html');
mainWindow.on('closed', function () {
mainWindow = null;
});
mainWindow.once('ready-to-show', () => {
try{
autoUpdater.checkForUpdatesAndNotify();
}catch(err){
console.log('autoUpdater.checkForUpdatesAndNotify(); err = ', err)
}
});
}
app.on('ready', () => {
createWindow();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
ipcMain.on('app_version', (event) => {
event.sender.send('app_version', { version: app.getVersion() });
});
ipcMain.on('restart_app', () => {
autoUpdater.quitAndInstall();
});
autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update_available');
console.log('update avail')
});
autoUpdater.on('update-downloaded', () => {
console.log('update downlaoded')
mainWindow.webContents.send('update_downloaded');
});
If I build on command prompt on my wind 10 computer I get this output in ym console: no error messages:
$1.0.4 deploy-win C:\Users\marti\Documents\projects\electron-auto-updater
electron-builder build --win --publish always
electron-builder version=22.9.1 os=10.0.18363
loaded configuration file=package.json ("build" field)
writing effective config file=dist\builder-effective-config.yaml
packaging platform=win32 arch=x64 electron=11.0.3 appOutDir=dist\win-unpacked
building target=portable file=dist\Electron tutorial app 1.0.4.exe archs=x64
s