1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-25 19:52:44 +01:00
lossless-cut/public/update-checker.js
Mikael Finstad 8a9438847b fix menus and version check #239 #274
also improve help
2020-03-26 19:04:36 +08:00

35 lines
1.1 KiB
JavaScript

const GitHub = require('github-api');
// eslint-disable-next-line import/no-extraneous-dependencies
const electron = require('electron');
const semver = require('semver');
const { app } = electron;
const gh = new GitHub();
const repo = gh.getRepo('mifi', 'lossless-cut');
async function checkNewVersion() {
try {
// From API: https://developer.github.com/v3/repos/releases/#get-the-latest-release
// View the latest published full release for the repository.
// Draft releases and prereleases are not returned by this endpoint.
const res = (await repo.getRelease('latest')).data;
const newestVersion = res.tag_name.replace(/^v?/, '');
const currentVersion = app.getVersion();
// const currentVersion = '3.17.2';
console.log('Current version', currentVersion);
console.log('Newest version', newestVersion);
if (semver.lt(currentVersion, newestVersion)) return newestVersion;
return undefined;
} catch (e) {
console.error('Failed to check github version');
return undefined;
}
}
module.exports = { checkNewVersion };