forked from betaflight/blackbox-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (54 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
openLinksInExternalBrowserByDefault();
$(document).ready(function () {
// translate to user-selected language
localize();
});
function checkForConfiguratorUpdates() {
var releaseChecker = new ReleaseChecker('configurator', 'https://api.github.com/repos/betaflight/blackbox-log-viewer/releases');
releaseChecker.loadReleaseData(notifyOutdatedVersion);
}
function notifyOutdatedVersion(releaseData) {
chrome.storage.local.get('checkForUnstableVersions', function (result) {
var showUnstableReleases = false;
if (result.checkForConfiguratorUnstableVersions) {
showUnstableReleases = true;
}
var versions = releaseData.filter(function (version) {
var semVerVersion = semver.parse(version.tag_name);
if (semVerVersion && (showUnstableReleases || semVerVersion.prerelease.length === 0)) {
return version;
}
}).sort(function (v1, v2) {
try {
return semver.compare(v2.tag_name, v1.tag_name);
} catch (e) {
return false;
}
});
if (versions.length > 0 && semver.lt(getManifestVersion(), versions[0].tag_name)) {
GUI.log(chrome.i18n.getMessage('updateNotice', [versions[0].tag_name, versions[0].html_url]));
var dialog = $('.dialogUpdate')[0];
$('.dialogUpdate-content').html(chrome.i18n.getMessage('updateNotice', [versions[0].tag_name, versions[0].html_url]));
$('.dialogUpdate-closebtn').click(function () {
dialog.close();
});
$('.dialogUpdate-websitebtn').click(function () {
dialog.close();
window.open(versions[0].html_url);
});
dialog.showModal();
}
});
}
checkForConfiguratorUpdates();
function openLinksInExternalBrowserByDefault() {
const gui = require('nw.gui');
//Get the current window
const win = gui.Window.get();
win.on('new-win-policy', function(frame, url, policy) {
// do not open the window
policy.ignore();
// and open it in external browser
gui.Shell.openExternal(url);
});
}