Skip to content

Commit 771b840

Browse files
authored
feat: use modules instead of global bindings (#3245)
1 parent 4412000 commit 771b840

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+433
-341
lines changed

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,25 @@ module.exports = {
2020
"no-var": "error",
2121
"prefer-template": "error",
2222
"template-curly-spacing": "error",
23+
"no-undef": "error",
24+
'no-duplicate-imports': 'error',
25+
},
26+
globals: {
27+
d3: true,
28+
THREE: true,
29+
cordova: true,
30+
cordovaUI: true,
31+
ol: true,
32+
wNumb: true,
33+
ConfigStorage: true,
34+
objectHash: true,
35+
// start cordova bindings, remove after cordova is removed/replace/modularized
36+
cordova_serial: true,
37+
fileChooser: true,
38+
i18n: true,
39+
appReady: true,
40+
cordovaChromeapi: true,
41+
appAvailability: true,
42+
// end cordova bindings
2343
},
2444
};

src/components/EscDshotDirection/EscDshotDirectionComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import EscDshotDirectionMotorDriver from "./EscDshotDirectionMotorDriver.js";
55
import DshotCommand from "../../js/utils/DshotCommand.js";
66
import FC from "../../js/fc.js";
77
import { API_VERSION_1_44 } from '../../js/data_storage.js';
8+
import { getMixerImageSrc } from "../../js/utils/common.js";
89

910
class EscDshotDirectionComponent
1011
{

src/components/MotorOutputReordering/MotorOutputReorderingComponent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import MSP from "../../js/msp";
66
import MSPCodes from "../../js/msp/MSPCodes";
77
import FC from "../../js/fc";
88
import { gui_log } from "../../js/gui_log";
9+
import { i18n } from "../../js/localization";
10+
import GUI, { TABS } from "../../js/gui";
911

1012
export default class MotorOutputReorderComponent
1113
{

src/js/Analytics.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import ShortUniqueId from 'short-unique-id';
2+
import googleAnalytics from 'universal-ga';
3+
import { set as setConfig, get as getConfig } from './ConfigStorage';
4+
import GUI from './gui';
5+
import CONFIGURATOR from './data_storage';
16

27
let tracking = null;
38
export { tracking };
@@ -6,6 +11,66 @@ export function createAnalytics(ga, settings) {
611
tracking = new Analytics(ga, settings);
712
}
813

14+
function getBuildType() {
15+
return GUI.Mode;
16+
}
17+
18+
function setupAnalytics(result) {
19+
let userId;
20+
if (result.userId) {
21+
userId = result.userId;
22+
} else {
23+
const uid = new ShortUniqueId();
24+
userId = uid.randomUUID(13);
25+
26+
setConfig({ 'userId': userId });
27+
}
28+
29+
const optOut = !!result.analyticsOptOut;
30+
const checkForDebugVersions = !!result.checkForConfiguratorUnstableVersions;
31+
32+
const debugMode = typeof process === "object" && process.versions['nw-flavor'] === 'sdk';
33+
34+
const settings = {
35+
trackingId: 'UA-123002063-1',
36+
userId: userId,
37+
appName: CONFIGURATOR.productName,
38+
appVersion: CONFIGURATOR.version,
39+
gitRevision: CONFIGURATOR.gitRevision,
40+
os: GUI.operating_system,
41+
checkForDebugVersions: checkForDebugVersions,
42+
optOut: optOut,
43+
debugMode: debugMode,
44+
buildType: getBuildType(),
45+
};
46+
createAnalytics(googleAnalytics, settings);
47+
window.tracking = tracking;
48+
49+
function logException(exception) {
50+
tracking.sendException(exception.stack);
51+
}
52+
53+
if (typeof process === "object") {
54+
process.on('uncaughtException', logException);
55+
}
56+
57+
tracking.sendEvent(tracking.EVENT_CATEGORIES.APPLICATION, 'AppStart', { sessionControl: 'start' });
58+
59+
$('.connect_b a.connect').removeClass('disabled');
60+
$('.firmware_b a.flash').removeClass('disabled');
61+
}
62+
63+
export function checkSetupAnalytics(callback) {
64+
if (!tracking) {
65+
const result = getConfig(['userId', 'analyticsOptOut', 'checkForConfiguratorUnstableVersions' ]);
66+
setupAnalytics(result);
67+
}
68+
69+
if (callback) {
70+
callback(tracking);
71+
}
72+
}
73+
974
class Analytics {
1075

1176
constructor (ga, settings) {

src/js/CliAutoComplete.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import GUI from './gui';
22
import CONFIGURATOR from './data_storage';
33
import FC from './fc';
4+
import semver from 'semver';
5+
import { tracking } from './Analytics';
46

57
/**
68
* Encapsulates the AutoComplete logic

src/js/DarkTheme.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import GUI from "./gui";
22
import windowWatcherUtil from "./utils/window_watchers";
3+
import { checkSetupAnalytics } from "./Analytics";
34

45
const css_dark = [
56
'./css/dark-theme.css',
@@ -65,4 +66,13 @@ DarkTheme.applyNormal = function () {
6566
css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', true));
6667
};
6768

69+
70+
export function setDarkTheme(enabled) {
71+
DarkTheme.setConfig(enabled);
72+
73+
checkSetupAnalytics(function (analyticsService) {
74+
analyticsService.sendEvent(analyticsService.EVENT_CATEGORIES.APPLICATION, 'DarkTheme', enabled);
75+
});
76+
}
77+
6878
export default DarkTheme;

src/js/Features.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { bit_check, bit_set, bit_clear } from "./bit";
22
import { API_VERSION_1_44 } from './data_storage';
3+
import semver from "semver";
4+
import { tracking } from "./Analytics";
35

46
const Features = function (config) {
57
const self = this;

src/js/LogoManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { gui_log } from "./gui_log";
22
import { i18n } from "./localization";
3+
import { checkChromeRuntimeError } from "./utils/common";
34

45
/**
56
* Takes an ImageData object and returns an MCM symbol as an array of strings.

src/js/RateCurve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import FC from "./fc";
22
import { API_VERSION_1_43 } from "./data_storage";
3+
import semver from "semver";
34

45
const minRc = 1000;
56
const midRc = 1500;

src/js/TuningSliders.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import MSP from "./msp";
22
import FC from "./fc";
33
import MSPCodes from "./msp/MSPCodes";
44
import { API_VERSION_1_44 } from './data_storage';
5+
import { isExpertModeEnabled } from "./utils/isExportModeEnabled";
6+
import semver from "semver";
7+
import { mspHelper } from "./msp/MSPHelper";
8+
import { TABS } from "./gui";
59

610
const TuningSliders = {
711
// Legacy Sliders

0 commit comments

Comments
 (0)