1
0
mirror of https://github.com/S2-/gitlit synced 2025-08-02 12:20:05 +02:00

auto update app

This commit is contained in:
s2
2020-06-07 19:37:56 +02:00
parent a6666452d7
commit 6c2bc3397e
6 changed files with 95 additions and 2 deletions

View File

@@ -49,3 +49,13 @@ table.sortable thead {
table.sortable .sorttable_nosort { table.sortable .sorttable_nosort {
cursor: default; cursor: default;
} }
/*
* updater
*/
.updatenotice {
position: fixed;
bottom: 5px;
right: 5px;
}

View File

@@ -20,8 +20,9 @@
<link href="css/app.css" rel="stylesheet"> <link href="css/app.css" rel="stylesheet">
</head> </head>
<body> <body>
<div class="js-container"> <div class="js-container"></div>
</div>
<script src="js/index.js"></script> <script src="js/index.js"></script>
<div class="js-updatenotice btn btn-warning btn-sm updatenotice" style="display:none" disabled>Update ready to install</div>
</body> </body>
</html> </html>

View File

@@ -7,6 +7,31 @@
let firstRun = true; let firstRun = true;
//events //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) => { ipcRenderer.on('fileList', (event, files) => {
firstRun = false; firstRun = false;
if (files && files.length > 0) { if (files && files.length > 0) {

View File

@@ -3,6 +3,7 @@ const path = require('path');
const url = require('url'); const url = require('url');
const electronLocalshortcut = require('electron-localshortcut'); const electronLocalshortcut = require('electron-localshortcut');
const exec = require('child_process').exec; 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), { const args = require('minimist')(process.defaultApp ? process.argv.slice(3) : process.argv.slice(1), {
default: { default: {
_: process.cwd() _: process.cwd()
@@ -13,6 +14,40 @@ let win;
let repoDir = path.resolve(path.normalize(args._.join(' '))); let repoDir = path.resolve(path.normalize(args._.join(' ')));
let repoRootDir = repoDir; 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) { function getLfsFileList(dir, cb) {
exec('git ls-files | git check-attr --stdin lockable', { exec('git ls-files | git check-attr --stdin lockable', {
maxBuffer: (1024 * 1024) * 10, //10MB maxBuffer: (1024 * 1024) * 10, //10MB

21
package-lock.json generated
View File

@@ -1165,6 +1165,22 @@
"assert-plus": "^1.0.0" "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": { "global-dirs": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz", "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", "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=="
}, },
"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": { "nonblockjs": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/nonblockjs/-/nonblockjs-1.0.8.tgz", "resolved": "https://registry.npmjs.org/nonblockjs/-/nonblockjs-1.0.8.tgz",

View File

@@ -33,6 +33,7 @@
"ejs-render-remote": "^1.0.13", "ejs-render-remote": "^1.0.13",
"electron-find": "^1.0.6", "electron-find": "^1.0.6",
"electron-localshortcut": "^3.2.1", "electron-localshortcut": "^3.2.1",
"github-app-updater": "^1.0.0",
"jquery": "^3.5.1", "jquery": "^3.5.1",
"material-design-icons": "^3.0.1", "material-design-icons": "^3.0.1",
"minimist": "^1.2.5", "minimist": "^1.2.5",