1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00

Implement version check

This commit is contained in:
Mikael Finstad 2018-02-17 15:15:30 +01:00
parent e2e8d14946
commit 5bf0c15d3e
4 changed files with 49 additions and 2 deletions

View File

@ -56,6 +56,7 @@
"electron-is-dev": "^0.1.2", "electron-is-dev": "^0.1.2",
"execa": "^0.5.0", "execa": "^0.5.0",
"file-type": "^4.1.0", "file-type": "^4.1.0",
"github-api": "^3.0.0",
"jquery": "^3.1.1", "jquery": "^3.1.1",
"keyboardjs": "^2.3.3", "keyboardjs": "^2.3.3",
"lodash": "^4.16.4", "lodash": "^4.16.4",

View File

@ -5,6 +5,8 @@ const url = require('url');
const menu = require('./menu'); const menu = require('./menu');
const { checkNewVersion } = require('./update-checker');
const app = electron.app; const app = electron.app;
const BrowserWindow = electron.BrowserWindow; const BrowserWindow = electron.BrowserWindow;
@ -37,9 +39,14 @@ function createWindow() {
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', () => { app.on('ready', async () => {
createWindow(); createWindow();
menu(app, mainWindow); menu(app, mainWindow);
const newVersion = await checkNewVersion();
if (newVersion) {
menu(app, mainWindow, newVersion);
}
}); });
// Quit when all windows are closed. // Quit when all windows are closed.

View File

@ -5,8 +5,9 @@ const Menu = electron.Menu;
const dialog = electron.dialog; const dialog = electron.dialog;
const homepage = 'https://github.com/mifi/lossless-cut'; const homepage = 'https://github.com/mifi/lossless-cut';
const releasesPage = 'https://github.com/mifi/lossless-cut/releases';
module.exports = (app, mainWindow) => { module.exports = (app, mainWindow, newVersion) => {
const menu = defaultMenu(app, electron.shell); const menu = defaultMenu(app, electron.shell);
const editMenuIndex = menu.findIndex(item => item.Label === 'Edit'); const editMenuIndex = menu.findIndex(item => item.Label === 'Edit');
@ -40,5 +41,17 @@ module.exports = (app, mainWindow) => {
}); });
} }
if (newVersion) {
menu.push({
label: 'New version!',
submenu: [
{
label: `Download ${newVersion}`,
click() { electron.shell.openExternal(releasesPage); },
},
],
});
}
Menu.setApplicationMenu(Menu.buildFromTemplate(menu)); Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}; };

26
src/update-checker.js Normal file
View File

@ -0,0 +1,26 @@
const GitHub = require('github-api');
const electron = require('electron');
const app = electron.app;
const gh = new GitHub();
const repo = gh.getRepo('mifi', 'lossless-cut');
async function checkNewVersion() {
try {
const res = (await repo.getRelease('latest')).data;
const tagName = res.tag_name;
console.log(tagName);
const currentVersion = app.getVersion();
// const currentVersion = '1.8.0';
if (tagName !== `v${currentVersion}`) return tagName;
return undefined;
} catch (e) {
console.error('Failed to check github version');
return undefined;
}
}
module.exports = { checkNewVersion };