i am using electron forge, auto-updater for auto updating electron app but after running electron forge publish its working fine but not getting any updates. Below are the package.json, main.js and forge.config.js files which i am using
main.js
const { BrowserWindow, app, ipcMain, autoUpdater ,Notification, dialog, Menu } = require('electron');
const path = require('path');
let win = null;
let version = app.getVersion()
console.log(version)
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true;
const isDev = !app.isPackaged;
function createWindow() {
win = new BrowserWindow({
width: 1200,
height: 800,
backgroundColor: "white",
webPreferences: {
nodeIntegration: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
sandbox: false
}
})
win.loadFile('index.html');
if (isDev) win.webContents.openDevTools()
}
if (isDev) {
const ignoredPattern = /Input|Output|node_modules|[\/\\]\./;
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
ignored: ignoredPattern
})
}
const template = [
{
id: "home",
label: "Home",
submenu: [
{
label: `Current Version v${app.getVersion()}`,
click: async() => {
new Notification({title: 'Current Version', body: app.getVersion()}).show()
await autoUpdater.checkForUpdates()
}
},
{
label: "Exit",
click() {
app.quit();
}
}
]
}
]
//if mac add empty object to menuTemplate
if (process.platform == "darwin") {
template.unshift({ label: "" }); //adding it to the beggining of the array
}
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
ipcMain.on('notify', (_, message) => {
new Notification({ title: 'Notifiation', body: message }).show();
})
ipcMain.handle('get-app-path', () => {
return app.getAppPath();
});
app.whenReady().then( () => { createWindow() })
// ********
const server = `https://github.com/Bhavik2205/Dicom_Viewer.git` //'https://github.com/ANIRBARASKAR/xray_dicon_hospital_project'
const url = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL({ url })
setInterval(() => {
autoUpdater.checkForUpdates()
}, 1000)
autoUpdater.on('update-available', (info) => {
new Notification({ title: 'Notifiation', body: info }).show();
dialog.showMessageBox({
type: 'info',
message: `Current version ${app.getVersion()} .A new update is available. Do you want to download and install it now?`,
buttons: ['Yes', 'No'],
}).then((result) => {
if(result.response === 0) {
let la = template2[0];
la.submenu[0].label = 'Downloading latest version';
autoUpdater.downloadUpdate();
}
});
// autoUpdater.downloadUpdate();
});
autoUpdater.on('update-not-available', (info) => {
new Notification({ title: 'Notifiation', body: info }).show();
dialog.showMessageBox({
type: 'info',
message: 'You are already using the latest version of the app.',
});
});
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
new Notification({ title: 'Notifiation', body: releaseName }).show();
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail:
'A new version has been downloaded. Restart the application to apply the updates.'
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
})
autoUpdater.on('error', (message) => {
new Notification({error: message})
console.error('There was a problem updating the application')
console.error("Hello", message)
})
forge.config.js
module.exports = {
packagerConfig: {
icon: './img/logo.icns',
ignore: ["^/src($|/)"],
},
rebuildConfig: {},
makers: [
{
name: "@electron-forge/maker-squirrel",
config: {},
},
{
name: "@electron-forge/maker-zip",
platforms: ["darwin"],
},
{
name: "@electron-forge/maker-deb",
config: {},
},
{
name: "@electron-forge/maker-rpm",
config: {},
},
],
publishers: [
{
name: "@electron-forge/publisher-github",
config: {
repository: {
owner: "Bhavik2205",
name: "Dicom_Viewer",
},
prerelease: true,
},
},
],
};
package.json
{
"name": "electron-react-app",
"version": "1.0.2",
"description": "the sample description",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --config webpack.src.js --watch",
"dev": "electron .",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"anir": "concurrently \"npm run watch\" \"npm start\""
},
"keywords": [],
"author": "Bhavik Patel",
"license": "ISC",
"dependencies": {
"@electron-forge/publisher-github": "^6.4.2",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"axios": "^1.4.0",
"concurrently": "^8.2.0",
"cornerstone-core": "^2.6.1",
"cornerstone-file-image-loader": "^0.2.0",
"dotenv": "^16.0.3",
"electron-squirrel-startup": "^1.0.0",
"electron-updater": "^5.3.0",
"fs-extra": "^11.1.0",
"hammerjs": "^2.0.8",
"localforage": "^1.10.0",
"moment": "^2.29.4",
"smalltalk": "^4.1.1",
"socket.io-client": "^4.6.1",
"styled-components": "^6.0.7",
"ulid": "^2.3.0",
"update-electron-app": "^2.0.1"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-deb": "^6.0.4",
"@electron-forge/maker-rpm": "^6.0.4",
"@electron-forge/maker-squirrel": "^6.0.4",
"@electron-forge/maker-zip": "^6.0.4",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@material-ui/core": "^4.12.4",
"@material-ui/styles": "^4.11.5",
"@mui/core": "^5.0.0-alpha.54",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.4",
"@mui/styled-engine-sc": "^5.11.0",
"babel-loader": "^8.1.0",
"css-loader": "^4.3.0",
"electron": "^22.2.0",
"electron-reload": "^1.5.0",
"eslint-plugin-react-hooks": "^4.6.0",
"file-loader": "^6.2.0",
"notistack": "^3.0.1",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-cornerstone-viewport": "^4.1.4",
"react-dom": "^17.0.2",
"sass": "^1.26.11",
"sass-loader": "^10.0.2",
"style-loader": "^1.2.1",
"url-loader": "^4.1.1",
"webpack": "^5.82.1",
"webpack-cli": "5.0.1"
}
}
i want to implement autoupdate by which i can regularly send the updates to my all the clients by releasing the latest version on github.