Skip to content

The swiss army knife of lossless video/audio editing

Implement version check ✅

Mikael Finstad5bf0c15d3e96
diff --git a/package.json b/package.json
index c226a734..8f6d6284 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/index.js b/src/index.js
index 2011c6d4..6383322b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -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.
diff --git a/src/menu.js b/src/menu.js
index da8b4fa5..3fee38d1 100644
--- a/src/menu.js
+++ b/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));
};
diff --git a/src/update-checker.js b/src/update-checker.js
new file mode 100644
index 00000000..5c689eaa
--- /dev/null
+++ b/src/update-checker.js
@@ -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 };