From 41dfa03379359655c59eeb1dfbc256e742df3d89 Mon Sep 17 00:00:00 2001 From: Paul Sori Date: Sun, 20 Oct 2019 01:36:02 -0700 Subject: [PATCH] auto update --- README.md | 5 +++- mstream-electron.js | 59 +++++++++++++++++++++++++++++++++++++++------ package.json | 14 +++++------ 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6a641ed..9c30ae8 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,14 @@ federation: { Without this, Federation will be disabled. +## Contributing + +Interested in getting in contact? [Check out our Discord channel](https://discordapp.com/channels/614134709248589845/614134709248589847) + ## The Docs [All the details about mStream are available in the docs folder](docs/) - ## Credits mStream is is built on top some great open-source libraries: diff --git a/mstream-electron.js b/mstream-electron.js index 994a51a..1f67fd4 100644 --- a/mstream-electron.js +++ b/mstream-electron.js @@ -9,6 +9,7 @@ const {autoUpdater} = require("electron-updater"); const mstreamAutoLaunch = new AutoLaunch({ name: 'mStream' }); const configFile = fe.join(app.getPath('userData'), 'save/server-config.json'); let appIcon; +let trayTemplate; if (!fs.existsSync(fe.join(app.getPath('userData'), 'image-cache'))) { mkdirp(fe.join(app.getPath('userData'), 'image-cache')); @@ -110,7 +111,7 @@ function createMainWindow() { mainWindow = null; }); - autoUpdater.checkForUpdatesAndNotify(); + autoUpdater.checkForUpdates(); } // Boot Server Event @@ -135,12 +136,18 @@ function bootServer(program) { // Tray Template Object const protocol = program.ssl && program.ssl.cert && program.ssl.key ? 'https' : 'http'; - var trayTemplate = [ + trayTemplate = [ { label: 'mStream Server v' + app.getVersion(), click: function () { - shell.openExternal('http://mstream.io/mstream-express'); + shell.openExternal('http://mstream.io/'); } }, + { + label: 'Check For Updates', click: function () { + autoUpdater.checkForUpdates(); + } + }, + { type: 'separator' }, { label: 'Links', submenu: [ { label: protocol + '://localhost:' + program.port, click: function () { @@ -153,7 +160,6 @@ function bootServer(program) { } }, ] }, - { type: 'separator' }, { label: 'Restart and Reconfigure', click: function () { fs.writeFileSync(fe.join(app.getPath('userData'), 'save/temp-boot-disable.json'), JSON.stringify({ disable: true }), 'utf8'); @@ -178,8 +184,8 @@ function bootServer(program) { // Check if Auto DNS is logged in if(program.ddns.tested === true) { - trayTemplate[1].submenu.push({ type: 'separator' }); - trayTemplate[1].submenu.push({ + trayTemplate[3].submenu.push({ type: 'separator' }); + trayTemplate[3].submenu.push({ label: 'https://' + program.ddns.url, click: function () { shell.openExternal('https://' + program.ddns.url) } @@ -195,5 +201,44 @@ function bootServer(program) { server = require('./mstream.js'); server.serveIt(program); - setInterval(() => { autoUpdater.checkForUpdatesAndNotify(); }, 86400000); + setInterval(() => { autoUpdater.checkForUpdates(); }, 86400000); } + +// Handle Auto Updates +autoUpdater.on('checking-for-update', () => { + trayTemplate[1] = { + label: 'Checking For Updates...', click: function () { } + } +}) +autoUpdater.on('update-available', (info) => { + trayTemplate[1] = { + label: 'Downloading Update (0%)', click: function () { } + } +}); +autoUpdater.on('update-not-available', (info) => { + trayTemplate[1] = { + label: 'Check For Updates', click: function () { + autoUpdater.checkForUpdates(); + } + } +}); +autoUpdater.on('error', (err) => { + console.log(err); + trayTemplate[1] = { + label: 'Update Error. Try Again', click: function () { + autoUpdater.checkForUpdates(); + } + } +}); +autoUpdater.on('download-progress', (progressObj) => { + trayTemplate[1] = { + label: `Downloading Update (${progressObj.percent}%)`, click: function () { } + } +}) +autoUpdater.on('update-downloaded', (info) => { + trayTemplate[1] = { + label: 'Update Downloaded - Click to install', click: function () { + autoUpdater.quitAndInstall(); + } + }; +}) diff --git a/package.json b/package.json index a25b8a6..58ca6f5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/IrosTheBeggar/mstream-node" + "url": "https://github.com/IrosTheBeggar/mStream" }, "author": { "name": "Paul Sori", @@ -37,26 +37,26 @@ "!image-cache/*", "!save/*", "!frp/*", - "!sync/*", + "!sync/*", "!.git/*", "!.vscode/*", "frp/readme.md" ], "publish": [ { - "provider": "github", - "owner": "IrosTheBeggar", - "repo": "mStream" + "provider": "github" } ], "mac": { + "target":"dmg", "files": [ "frp/mstream-ddns-osx", "sync/syncthing-osx" ], "category": "public.app-category.music", "binaries": [ - "frp/mstream-ddns-osx" + "frp/mstream-ddns-osx", + "sync/syncthing-osx" ] }, "win": { @@ -81,7 +81,7 @@ "busboy": "^0.3.1", "colors": "^1.3.3", "commander": "^3.0.1", - "electron-updater": "4.0.14", + "electron-updater": "^4.0.14", "express": "^4.17.1", "fast-xml-parser": "^3.13.0", "inquirer": "^7.0.0",