Я пробовал electron-basic-updater, electron-asar-updater, electron-installer-windows
и др. и потратили часы, пытаясь выпустить/обновить мое приложение, прежде чем оседать с electron-packager
для упаковки и Squirrel
для автообновлений. У них есть свои преимущества.
Я предполагаю, что у читателя есть базовое ноу-хау по работе с приложениями Electron, и поэтому я не вдаваюсь в основы.
Важное примечание: Необходимо создать пакет/установщик в окнах и установить приложение для автоматического обновления.
В вас основном app.js, добавить IPC для обработки сценария обновления:
ipcMain.on('check-for-update', function(event, arg) {
/* AUTO UPDATER */
const autoUpdater = electron.autoUpdater;
const os = require('os');
const {dialog} = require('electron');
/* For Windows, PATH to DIRECTORY that has nupkg and RELEASES files (Windows alone) */
/* And add "Options Indexes" to htaccess if you want listing on that dir [email protected] */
var releaseDIR = config.webURL + '/releases/win' + (os.arch() === 'x64' ? '64' : '32');
autoUpdater.setFeedURL(releaseDIR);
autoUpdater
.on('error', function(error){
loggit(error);
return dialog.showMessageBox(mainWindow, {
type: 'info',
icon: basePath + "/assets/refico32.ico",
buttons: ['Dang!'],
title: appName + ": Update Error",
message: "Something's not right out there. Please try again later.",
detail: "Umm... \nIt's not you, it's the server"
});
})
.on('checking-for-update', function(e) {
loggit('Checking for update at ' + releaseDIR);
})
.on('update-available', function(e) {
var downloadConfirmation = dialog.showMessageBox(mainWindow, {
type: 'info',
icon: basePath + "/assets/refico32.ico",
buttons: ['Proceed'],
title: appName + ": Update Available",
message: 'An update is available. The update will be downloaded in the background.',
detail: "Size: ~42 MB"
});
loggit('Downloading update');
if (downloadConfirmation === 0) {
return;
}
})
.on('update-not-available', function(e) {
loggit('Update not available');
return dialog.showMessageBox(mainWindow, {
type: 'info',
icon: basePath + "/assets/refico32.ico",
buttons: ['Cool'],
title: appName + ": No update available",
message: "It seems you're running the latest and greatest version",
detail: "Woot, woot! \nTalk about being tech-savvy"
});
})
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
var index = dialog.showMessageBox(mainWindow, {
type: 'info',
icon: basePath + "/assets/refico32.ico",
buttons: ['Install Update','Later'],
title: appName + ": Latest version downloaded",
message: 'Please restart the app to apply the update',
detail: releaseName + "\n\n" + releaseNotes
});
if (index === 1) return;
force_quit = true;
autoUpdater.quitAndInstall();
});
autoUpdater.checkForUpdates();
event.returnValue = "Checking for updates: " + releaseDIR + " Install Path: " + appPath;
});
Дополнительных примечания: 1] Ваш app.js должны обрабатывать беличье событие в самом начале. Вы можете написать собственные обработчики для handleSquirrelEvent или просто сделать if (require('electron-squirrel-startup')) return;
. 2] На момент написания этого сообщения, как только процесс автоматического обновления был инициирован, пользователь не может отменить процесс обновления.
Для создания вашего установщика, ваш Gruntfile.js (после npm install grunt, npm install grunt-cli
) должно быть что-то вроде
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-electron-installer');
grunt.initConfig({
'create-windows-installer': {
'ia32': {
appDirectory: "C:\\refreshie\\app\\build\\Refreshie-win32-ia32",
outputDirectory: "C:\\refreshie\\app\\build\\Distro\\Refreshie-Win-ia32",
loadingGif: "C:\\refreshie\\app\\assets\\images\\install.splash.gif",
iconUrl: "C:\\refreshie\\app\\assets\\refico.ico",
setupIcon: "C:\\refreshie\\app\\assets\\refico.ico",
signWithParams: "/a /f C:\\refreshie\\app\\build\\tools\\cert.signingkey.pfx /p F5",
noMsi: true
}
}
});
grunt.registerTask('default', ['create-windows-installer']);
};