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:
parent
e2e8d14946
commit
5bf0c15d3e
@ -56,6 +56,7 @@
|
||||
"electron-is-dev": "^0.1.2",
|
||||
"execa": "^0.5.0",
|
||||
"file-type": "^4.1.0",
|
||||
"github-api": "^3.0.0",
|
||||
"jquery": "^3.1.1",
|
||||
"keyboardjs": "^2.3.3",
|
||||
"lodash": "^4.16.4",
|
||||
|
@ -5,6 +5,8 @@ const url = require('url');
|
||||
|
||||
const menu = require('./menu');
|
||||
|
||||
const { checkNewVersion } = require('./update-checker');
|
||||
|
||||
const app = electron.app;
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
|
||||
@ -37,9 +39,14 @@ function createWindow() {
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', () => {
|
||||
app.on('ready', async () => {
|
||||
createWindow();
|
||||
menu(app, mainWindow);
|
||||
|
||||
const newVersion = await checkNewVersion();
|
||||
if (newVersion) {
|
||||
menu(app, mainWindow, newVersion);
|
||||
}
|
||||
});
|
||||
|
||||
// Quit when all windows are closed.
|
||||
|
15
src/menu.js
15
src/menu.js
@ -5,8 +5,9 @@ const Menu = electron.Menu;
|
||||
const dialog = electron.dialog;
|
||||
|
||||
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 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));
|
||||
};
|
||||
|
26
src/update-checker.js
Normal file
26
src/update-checker.js
Normal 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 };
|
Loading…
Reference in New Issue
Block a user