Skip to content

Commit a189747

Browse files
mikellerhaslinghuis
authored andcommitted
Fixes missing semicolon
2 parents 1e58308 + b874358 commit a189747

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

cordova/package_template.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"cordova-plugin-splashscreen": "^5.0.3",
2626
"cordova-plugin-usb-event": "^1.0.2",
2727
"cordova-plugin-whitelist": "^1.3.4",
28+
"cordova-plugin-theme-detection": "^1.2.1",
2829
"bf-cordovarduino": "^1.0.0"
2930
},
3031
"cordova": {
@@ -48,6 +49,7 @@
4849
"cordova-plugin-screen-orientation": {},
4950
"cordova-plugin-market": {},
5051
"bf-cordova-open-native-settings": {},
52+
"cordova-plugin-theme-detection": {},
5153
"bf-cordova-plugin-appavailability": {}
5254
}
5355
}

cordova/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ cordova-plugin-splashscreen@^5.0.3:
675675
resolved "https://registry.yarnpkg.com/cordova-plugin-splashscreen/-/cordova-plugin-splashscreen-5.0.3.tgz#02820472771c3e10b43ceedd54b0a1e4674efa6d"
676676
integrity sha512-rnoDXMDfzoeHDBvsnu6JmzDE/pV5YJCAfc5hYX/Mb2BIXGgSjFJheByt0tU6kp3Wl40tSyFX4pYfBwFblBGyRg==
677677

678+
cordova-plugin-theme-detection@^1.2.1:
679+
version "1.2.1"
680+
resolved "https://registry.yarnpkg.com/cordova-plugin-theme-detection/-/cordova-plugin-theme-detection-1.2.1.tgz#8ff887a27fd25d497e82660c971b26086a3c54f6"
681+
integrity sha512-UsvXFKbbBqLuFkk6cQ1s+uIvLvXxNN3y4zwgBmTr5JwzCf8HlrHH4f6IWTsLLfRIsbfM6KdO7xvQ5EwDgS1LhQ==
682+
678683
cordova-plugin-usb-event@^1.0.2:
679684
version "1.0.2"
680685
resolved "https://registry.yarnpkg.com/cordova-plugin-usb-event/-/cordova-plugin-usb-event-1.0.2.tgz#68182ae8d56d42236524753a1dbb711ce285e03a"

src/js/DarkTheme.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,39 @@ var DarkTheme = {
88
configEnabled: undefined,
99
};
1010

11-
DarkTheme.isDarkThemeEnabled = function (val) {
12-
return val === 0 || val === 2 && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
11+
DarkTheme.isDarkThemeEnabled = function (callback) {
12+
if (this.configEnabled === 0) {
13+
callback(true);
14+
} else if (this.configEnabled === 2) {
15+
if (GUI.isCordova()) {
16+
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
17+
callback(success.value);
18+
}, function(error) {
19+
console.log(`cordova-plugin-theme-detection: ${error}`);
20+
callback(false);
21+
});
22+
} else {
23+
const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
24+
callback(isEnabled);
25+
}
26+
} else {
27+
callback(false);
28+
}
1329
};
1430

1531
DarkTheme.apply = function() {
16-
if (this.isDarkThemeEnabled(this.configEnabled)) {
17-
this.applyDark();
18-
} else {
19-
this.applyNormal();
20-
}
32+
const self = this;
33+
this.isDarkThemeEnabled(function(isEnabled) {
34+
if (isEnabled) {
35+
self.applyDark();
36+
} else {
37+
self.applyNormal();
38+
}
2139

22-
if (chrome.app.window !== undefined) {
23-
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', this.isDarkThemeEnabled(this.configEnabled));
24-
}
40+
if (chrome.app.window !== undefined) {
41+
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', isEnabled);
42+
}
43+
});
2544
};
2645

2746
DarkTheme.autoSet = function() {
@@ -31,7 +50,7 @@ DarkTheme.autoSet = function() {
3150
};
3251

3352
DarkTheme.setConfig = function (result) {
34-
if (this.configEnabled != result) {
53+
if (this.configEnabled !== result) {
3554
this.configEnabled = result;
3655
this.apply();
3756
}

src/js/main.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,23 @@ function closeSerial() {
148148
}
149149
}
150150

151-
function closeHandler() {
151+
async function closeHandler() {
152152
if (!GUI.isCordova()) {
153153
this.hide();
154154
}
155155

156156
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' });
157157

158-
closeSerial();
158+
const delay = millis => new Promise((settle) => {
159+
setTimeout(_ => settle, millis);
160+
});
161+
162+
function onFinishCallback() {
163+
closeSerial();
164+
}
165+
166+
mspHelper.setArmingEnabled(false, false, onFinishCallback);
167+
await delay(3000);
159168

160169
if (!GUI.isCordova()) {
161170
this.close(true);
@@ -514,9 +523,22 @@ function startProcess() {
514523
setDarkTheme(result.darkTheme);
515524
}
516525
});
517-
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
518-
DarkTheme.autoSet();
519-
});
526+
if (GUI.isCordova()) {
527+
let darkMode = false;
528+
const checkDarkMode = function() {
529+
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
530+
if (success.value !== darkMode) {
531+
darkMode = success.value;
532+
DarkTheme.autoSet();
533+
}
534+
});
535+
};
536+
setInterval(checkDarkMode, 500);
537+
} else {
538+
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
539+
DarkTheme.autoSet();
540+
});
541+
}
520542
}
521543

522544
function setDarkTheme(enabled) {

src/js/tabs/pid_tuning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TABS.pid_tuning.initialize = function (callback) {
4141
return MSP.promise(MSPCodes.MSP_PID_CONTROLLER);
4242
}
4343
}).then(function() {
44-
return MSP.promise(MSPCodes.MSP_PIDNAMES)
44+
return MSP.promise(MSPCodes.MSP_PIDNAMES);
4545
}).then(function() {
4646
return MSP.promise(MSPCodes.MSP_PID);
4747
}).then(function() {

0 commit comments

Comments
 (0)