From 8a5e0b4e801c4ec167c32de26e13739c2d7e2924 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 7 Feb 2021 17:34:57 +0100 Subject: [PATCH] dump to snapshot --- package-lock.json | 35 ++++------------------ package.json | 7 +++-- src/server/main.js | 34 ++-------------------- src/server/updater.js | 68 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 src/server/updater.js diff --git a/package-lock.json b/package-lock.json index 7f28eb3..23c9c4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "altarik-launcher", - "version": "0.1.0", + "version": "0.1.1-SNPASHOT", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1400,9 +1400,9 @@ } }, "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=" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-1.2.0.tgz", + "integrity": "sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw==" }, "electron-notarize": { "version": "1.0.0", @@ -2298,14 +2298,6 @@ "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", @@ -2637,11 +2629,6 @@ "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", @@ -3091,7 +3078,8 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "mute-stream": { "version": "0.0.8", @@ -4520,17 +4508,6 @@ "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 9319e07..e1e819c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "altarik-launcher", - "version": "0.1.0", + "version": "0.1.1-SNAPSHOT", "description": "Altarik Launcher", "main": "src/server/main.js", + "repository": "AltarikMC/Launcher", "scripts": { "start": "electron-forge start", "test": "echo \"Error: no test specified\" && exit 1", @@ -18,9 +19,9 @@ "electron": "^11.2.3" }, "dependencies": { + "electron-is-dev": "^1.2.0", "electron-squirrel-startup": "^1.0.0", - "minecraft-launcher-core": "^3.16.1", - "update-electron-app": "^2.0.1" + "minecraft-launcher-core": "^3.16.1" }, "config": { "forge": "./config.forge.js" diff --git a/src/server/main.js b/src/server/main.js index 9c5817e..3010ac8 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -4,38 +4,8 @@ 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) -}) +// don't work +//require('./updater.js').configUpdater(app, autoUpdater, dialog) 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") diff --git a/src/server/updater.js b/src/server/updater.js new file mode 100644 index 0000000..e851a0a --- /dev/null +++ b/src/server/updater.js @@ -0,0 +1,68 @@ +const isDev = require('electron-is-dev') +const { Notification } = require('electron') +const os = require('os') +const pkg = require('../../package.json') +const { format } = require('util') +const server = 'https://update.electronjs.org' + +function initUpdater(autoUpdater) { + autoUpdater.checkForUpdates() + setInterval(() => { + autoUpdater.checkForUpdates() + }, 10 * 60 * 1000) // 10 minutes +} + +function configUpdater(app, autoUpdater, dialog) { + if(isDev) + return + const feed = `${server}/${pkg.repository}/${process.platform}-${process.arch}/${app.getVersion()}` + autoUpdater.setFeedURL(feed) + app.isReady ? initUpdater(autoUpdater) : app.on("ready", () => initUpdater(autoUpdater)) + + + autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName, releaseDate, updateURL) => { + showNotification(releaseNotes, updateURL) + 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) + showNotification(feed) + const dialogOpts = { + type: 'info', + buttons: ['Fermer'], + title: 'Erreur lors de la tentative de mise à jour du launcher', + message: "Une erreur est survenue lros de la tentative de mise à jour du launcher", + detail: message + } + + dialog.showMessageBox(dialogOpts) + }) + + autoUpdater.on('update-available', () => { + showNotification("Altarik launcher", "downloading update") + }) +} + +function showNotification(title, body="") { + const content = { + title: title, + body: body + } + new Notification(content).show() +} + +module.exports = { + configUpdater +}