-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.js
104 lines (86 loc) · 2.91 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const MIN_CONFIG_VERSION = 108; // this gui can manage versions in this range
const MAX_CONFIG_VERSION = 130; //128 ghost // 129 = bec support // 130 = octo fix & TBS gimbal PT
function getLanguage(callback) {
if (typeof chromeSerial !== 'undefined') {
chrome.storage.local.get('language', function (result) {
if (result.language !== undefined) {
callback(result.language);
} else {
callback("en");
}
});
} else {
if (window.localStorage.getItem('language') !== undefined) {
var lang = window.localStorage.getItem('language');
if (lang == null) lang = "en";
callback(lang);
} else {
callback("en");
}
}
}
function setLanguage(lang) {
if (typeof chromeSerial !== 'undefined') {
chrome.storage.local.set({
'language': lang
});
} else {
localStorage.setItem('language', lang);
}
}
function changeLanguage() {
getLanguage(function (lang) {
console.log("Switching to " + lang);
$.i18n({
locale: lang
});
$.i18n.locale = lang;
$.i18n().load('./i18n/' + lang + '.json', lang).done(
function () {
$("*").i18n();
});
});
}
function checkGithubRelease(currVersion) {
$.get('https://api.github.com/repos/flyduino/kissfc-chrome-gui/releases', function (releaseData) {
console.log('Loaded release information from GitHub.');
console.log('Latest release found: ' + releaseData[0].tag_name, ' parameter: ' + currVersion);
if (semver.gt(releaseData[0].tag_name, currVersion)) {
console.log('New version aviable!');
$("#dialogGUIupdate").dialog();
} else {
$("#dialogGUIupdate").hide();
console.log('Latest version!');
}
});
};
$(document).ready(function () {
$.i18n.debug = true;
changeLanguage();
// Check for update
checkGithubRelease(chrome.runtime.getManifest().version);
PortHandler.initialize();
CONTENT.welcome.initialize();
$('#navigation li.external').hide();
$('#navigation li:not(.external)').click(function () {
var self = this;
var content = $(self).attr('data-name');
$("#navigation").removeClass("active-menu");
function content_ready() {
GUI.contentSwitchInProgress = false;
}
if ($(self).hasClass('unlocked') && GUI.activeContent != content) {
GUI.contentSwitchInProgress = true;
GUI.contentSwitchCleanup(function () {
CONTENT[content].initialize();
});
}
});
$(".navigation-menu-button").on("click", function () {
$("#navigation").toggleClass("active-menu");
});
});
Number.prototype.clamp = function (min, max) {
return Math.min(Math.max(this, min), max);
};