2018-02-17 15:15:30 +01:00
|
|
|
const GitHub = require('github-api');
|
2020-03-04 11:41:40 +01:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2018-02-17 15:15:30 +01:00
|
|
|
const electron = require('electron');
|
2020-03-26 12:04:36 +01:00
|
|
|
const semver = require('semver');
|
|
|
|
|
2022-09-04 16:44:48 +02:00
|
|
|
const logger = require('./logger');
|
|
|
|
|
2018-02-17 15:15:30 +01:00
|
|
|
|
2018-09-30 22:08:36 +02:00
|
|
|
const { app } = electron;
|
2018-02-17 15:15:30 +01:00
|
|
|
|
|
|
|
const gh = new GitHub();
|
|
|
|
const repo = gh.getRepo('mifi', 'lossless-cut');
|
|
|
|
|
|
|
|
async function checkNewVersion() {
|
|
|
|
try {
|
2018-05-22 19:04:56 +02:00
|
|
|
// 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.
|
2018-02-17 15:15:30 +01:00
|
|
|
const res = (await repo.getRelease('latest')).data;
|
2020-03-26 12:04:36 +01:00
|
|
|
const newestVersion = res.tag_name.replace(/^v?/, '');
|
2018-02-17 15:15:30 +01:00
|
|
|
|
|
|
|
const currentVersion = app.getVersion();
|
2020-03-26 12:04:36 +01:00
|
|
|
// const currentVersion = '3.17.2';
|
2018-02-17 15:15:30 +01:00
|
|
|
|
2022-09-04 16:44:48 +02:00
|
|
|
logger.info('Current version', currentVersion);
|
|
|
|
logger.info('Newest version', newestVersion);
|
2019-11-04 12:29:56 +01:00
|
|
|
|
2020-03-26 12:04:36 +01:00
|
|
|
if (semver.lt(currentVersion, newestVersion)) return newestVersion;
|
2018-02-17 15:15:30 +01:00
|
|
|
return undefined;
|
2022-09-04 16:44:48 +02:00
|
|
|
} catch (err) {
|
|
|
|
logger.error('Failed to check github version', err.message);
|
2018-02-17 15:15:30 +01:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { checkNewVersion };
|