From c2a512883d0bcc1e7a61d35aba19910e2c12a173 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 6 Feb 2021 13:53:16 +0100 Subject: [PATCH] added auto updater --- package-lock.json | 32 ++++++++++++++++++++++++++++++-- package.json | 3 ++- src/server/main.js | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d1f32e..7f28eb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1399,6 +1399,11 @@ "extract-zip": "^1.0.3" } }, + "electron-is-dev": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.3.0.tgz", + "integrity": "sha1-FOb9pcaOnk7L7/nM8DfL18BcWv4=" + }, "electron-notarize": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz", @@ -2293,6 +2298,14 @@ "assert-plus": "^1.0.0" } }, + "github-url-to-object": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/github-url-to-object/-/github-url-to-object-4.0.4.tgz", + "integrity": "sha512-1Ri1pR8XTfzLpbtPz5MlW/amGNdNReuExPsbF9rxLsBfO1GH9RtDBamhJikd0knMWq3RTTQDbTtw0GGvvEAJEA==", + "requires": { + "is-url": "^1.1.0" + } + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -2624,6 +2637,11 @@ "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, + "is-url": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz", + "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==" + }, "is-utf8": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", @@ -3073,8 +3091,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mute-stream": { "version": "0.0.8", @@ -4503,6 +4520,17 @@ "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", "dev": true }, + "update-electron-app": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/update-electron-app/-/update-electron-app-2.0.1.tgz", + "integrity": "sha512-e4xEner89UZZaBGYJbYlMdL1uUrC0VjOsTAL2N4opPjzFtn+j7mdsJJsnyXZzUVeLY+8tuCX4XEsUM98oBHmZg==", + "requires": { + "electron-is-dev": "^0.3.0", + "github-url-to-object": "^4.0.4", + "is-url": "^1.2.4", + "ms": "^2.1.1" + } + }, "uri-js": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz", diff --git a/package.json b/package.json index dd3628a..9319e07 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ }, "dependencies": { "electron-squirrel-startup": "^1.0.0", - "minecraft-launcher-core": "^3.16.1" + "minecraft-launcher-core": "^3.16.1", + "update-electron-app": "^2.0.1" }, "config": { "forge": "./config.forge.js" diff --git a/src/server/main.js b/src/server/main.js index 83cc999..9c5817e 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -1,9 +1,42 @@ -const { app, BrowserWindow, Menu, ipcMain, Notification } = require('electron') +const { app, BrowserWindow, Menu, ipcMain, Notification, autoUpdater, dialog } = require('electron') const { join } = require('path') if (require('electron-squirrel-startup')) { require("./install.js").handleSquirrelEvent(app) app.quit() } +const server = 'https://update.electronjs.org' +const feed = `${server}/OWNER/REPO/${process.platform}-${process.arch}/${app.getVersion()}` +autoUpdater.setFeedURL(feed) +setInterval(() => { + autoUpdater.checkForUpdates() +}, 10 * 60 * 1000) // 10 minutes + +autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { + const dialogOpts = { + type: 'info', + buttons: ['Rédémarrer', 'Plus tard'], + title: 'Une mise à jour du launcher est disponible', + message: process.platform === 'win32' ? releaseNotes : releaseName, + detail: 'Une nouvelle version du launcher a été téléchargé. Redémarrez l\'application pour appliquer les mises à jour.' + } + + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) autoUpdater.quitAndInstall() + }) +}) + +autoUpdater.on('error', message => { + console.error('There was a problem updating the application') + console.error(message) + const dialogOpts = { + type: 'info', + buttons: ['Fermer'], + title: 'Erreur lors de la tentetive de mise à jour de l\'application', + message: "Une Erreur est survenur de lros de la mise à jour du launcher" + } + dialog.showMessageBox(dialogOpts) +}) + const { Client, Authenticator } = require('minecraft-launcher-core') const appdata = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share")