diff --git a/app/css/app.css b/app/css/app.css index dc997460..ce515728 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -49,3 +49,13 @@ table.sortable thead { table.sortable .sorttable_nosort { cursor: default; } + + +/* +* updater +*/ +.updatenotice { + position: fixed; + bottom: 5px; + right: 5px; +} diff --git a/app/index.html b/app/index.html index 0489ca18..77fb4447 100644 --- a/app/index.html +++ b/app/index.html @@ -20,8 +20,9 @@ -
-
+
+ + diff --git a/app/js/index.js b/app/js/index.js index b9141332..3a12ae8a 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -7,6 +7,31 @@ let firstRun = true; //events + + //update stuff + ipcRenderer.on('update', (event, state) => { + if (state.event === 'updateAvailable') { + $('.js-updatenotice').text(`New version ${state.version} available. Downloading...`); + $('.js-updatenotice').show(); + } + + if (state.event === 'updateReadyToInstall') { + $('.js-updatenotice').text(`New version ready to install. Click here to start installer.`); + $('.js-updatenotice').show(); + $('.js-updatenotice').prop('disabled', false); + $('.js-updatenotice').data('file', state.file); + } + }); + + $(document).on('click', '.js-updatenotice', (ev) => { + ev.preventDefault(); + $('.js-updatenotice').prop('disabled', true); + $('.js-updatenotice').text(`Launching installer...`); + ipcRenderer.send('installUpdate', $('.js-updatenotice').data('file')); + }); + //end update stuff + + ipcRenderer.on('fileList', (event, files) => { firstRun = false; if (files && files.length > 0) { diff --git a/app/main.js b/app/main.js index 6b9fb2ef..0eef20ad 100644 --- a/app/main.js +++ b/app/main.js @@ -3,6 +3,7 @@ const path = require('path'); const url = require('url'); const electronLocalshortcut = require('electron-localshortcut'); const exec = require('child_process').exec; +const gau = require('github-app-updater'); const args = require('minimist')(process.defaultApp ? process.argv.slice(3) : process.argv.slice(1), { default: { _: process.cwd() @@ -13,6 +14,40 @@ let win; let repoDir = path.resolve(path.normalize(args._.join(' '))); let repoRootDir = repoDir; +//auto update stuff +setTimeout(() => { + gau.checkForUpdate({ + currentVersion: '1.0.0', //app.getVersion(), + repo: 'https://api.github.com/repos/S2-/gitlit/releases/latest', + assetMatch: /.+setup.+exe/i + }); + + gau.onUpdateAvailable = (version, asset) => { + console.log('onUpdateAvailable'); + win.webContents.send('update', { + event: 'updateAvailable', + version: version + }); + gau.downloadNewVersion(asset); + }; + + gau.onNewVersionReadyToInstall = (file) => { + win.webContents.send('update', { + event: 'updateReadyToInstall', + file: file + }); + }; + + ipcMain.on('installUpdate', (event, file) => { + gau.executeUpdate(file); + win.webContents.send('update', { + event: 'updateInstalling' + }); + }); +}, 5000); + +//end update stuff + function getLfsFileList(dir, cb) { exec('git ls-files | git check-attr --stdin lockable', { maxBuffer: (1024 * 1024) * 10, //10MB diff --git a/package-lock.json b/package-lock.json index e0d71095..6a183ef7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1165,6 +1165,22 @@ "assert-plus": "^1.0.0" } }, + "github-app-updater": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/github-app-updater/-/github-app-updater-1.0.0.tgz", + "integrity": "sha512-GwWnHfJxqL+d/IdMyVLFqvP3NG8JFwBnd6obdAjjxl4YkWonRR/bK3WaCc+RnyMoUQUT63mz/cqTGpA4d7nOPQ==", + "requires": { + "node-fetch": "^2.6.0", + "semver": "^7.3.2" + }, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==" + } + } + }, "global-dirs": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz", @@ -1671,6 +1687,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, "nonblockjs": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/nonblockjs/-/nonblockjs-1.0.8.tgz", diff --git a/package.json b/package.json index e1bfe125..04f4e20f 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "ejs-render-remote": "^1.0.13", "electron-find": "^1.0.6", "electron-localshortcut": "^3.2.1", + "github-app-updater": "^1.0.0", "jquery": "^3.5.1", "material-design-icons": "^3.0.1", "minimist": "^1.2.5",