Skip to content

Commit ccf4898

Browse files
author
thyttan
committed
refactor global. -> globalThis.
As per: [global is used in Node.js. Consider using the identical globalThis as it was introduced in the ECMAScript spec.](https://www.espruino.com/ReferenceBANGLEJS2#l__global_global)
1 parent b2202cf commit ccf4898

File tree

72 files changed

+210
-210
lines changed

Some content is hidden

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

72 files changed

+210
-210
lines changed

apps/about/app-bangle1.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/accelrec/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function showData(save_file) {
118118
setWatch(function() {
119119
if (save_file) showSaveMenu(); // when select only plot, don't ask for save option
120120
else showMenu();
121-
}, global.BTN2 ? BTN2 : BTN);
121+
}, globalThis.BTN2 ? BTN2 : BTN);
122122
}
123123

124124
function showBig(txt) {
@@ -250,4 +250,4 @@ function DeleteRecord(file) {
250250
require("Storage").erase(file);
251251
StorageMenu();
252252
}
253-
showMenu();
253+
showMenu();

apps/andark/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Bangle.setUI({
165165
if (settings.loadWidgets) {
166166
Bangle.loadWidgets();
167167
require("widget_utils").swipeOn();
168-
} else if (global.WIDGETS) require("widget_utils").hide();
168+
} else if (globalThis.WIDGETS) require("widget_utils").hide();
169169

170170
// Stop updates when LCD is off, restart when on
171171
Bangle.on('lcdPower', updateState);

apps/android/boot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
let settings = Object.assign({rp:true,as:true,vibrate:".."},
55
require("Storage").readJSON("android.settings.json",1)||{}
66
);
7-
let _GB = global.GB;
8-
global.GB = e => {
7+
let _GB = globalThis.GB;
8+
globalThis.GB = e => {
99
// feed a copy to other handlers if there were any
1010
if (_GB) setTimeout(_GB,0,Object.assign({},e));
1111
Bangle.emit("GB",e);

apps/autoreset/boot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let timeoutAutoreset;
2020
const resetTimeoutAutoreset = (force)=>{
2121
if (timeoutAutoreset) clearTimeout(timeoutAutoreset);
2222
setTimeout(()=>{ // Short outer timeout to make sure we have time to leave clock face before checking `Bangle.CLOCK!=1`.
23-
if (enabledForApp(global.__FILE__)) {
23+
if (enabledForApp(globalThis.__FILE__)) {
2424
timeoutAutoreset = setTimeout(()=>{
2525
if (Bangle.CLOCK!=1) Bangle.showClock();
2626
}, settings.timeout*60*1000);

apps/backswipe/boot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
options = mode;
1414
}
1515

16-
var currentFile = global.__FILE__ || "";
16+
var currentFile = globalThis.__FILE__ || "";
1717

18-
if (global.BACK) delete global.BACK;
18+
if (globalThis.BACK) delete globalThis.BACK;
1919
if (options && options.back && enabledForApp(currentFile)) {
20-
global.BACK = options.back;
20+
globalThis.BACK = options.back;
2121
}
2222
setUI(mode, cb);
2323
};
@@ -36,8 +36,8 @@
3636
// if it is a left to right swipe
3737
if (lr === 1) {
3838
// if we're in an app that has a back button, run the callback for it
39-
if (global.BACK && countHandlers("swipe")<=settings.standardNumSwipeHandlers && countHandlers("drag")<=settings.standardNumDragHandlers) {
40-
global.BACK();
39+
if (globalThis.BACK && countHandlers("swipe")<=settings.standardNumSwipeHandlers && countHandlers("drag")<=settings.standardNumDragHandlers) {
40+
globalThis.BACK();
4141
E.stopEventPropagation();
4242
}
4343
}

apps/bikespeedo/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
};
2424

25-
if (global.WIDGETS && WIDGETS["recorder"]) {
25+
if (globalThis.WIDGETS && WIDGETS["recorder"]) {
2626
appMenu[/*LANG*/"Record rides"] = {
2727
value : !!settings.record,
2828
onchange : v => {

apps/boot/bootloader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var s = require("Storage").readJSON("setting.json",1)||{};
33
/* If were being called from JS code in order to load the clock quickly (eg from a launcher)
44
and the clock in question doesn't have widgets, force a normal 'load' as this will then
55
reset everything and remove the widgets. */
6-
if (global.__FILE__ && !s.clockHasWidgets) {load();throw "Clock has no widgets, can't fast load";}
6+
if (globalThis.__FILE__ && !s.clockHasWidgets) {load();throw "Clock has no widgets, can't fast load";}
77
// Otherwise continue to try and load the clock
88
var _clkApp = require("Storage").read(s.clock);
99
if (!_clkApp) {
@@ -24,6 +24,6 @@ if (!_clkApp) {
2424
}
2525
}
2626
delete s;
27-
if (!_clkApp) _clkApp=`E.showMessage("No Clock Found");setWatch(()=>{Bangle.showLauncher();}, global.BTN2||BTN, {repeat:false,edge:"falling"});`;
27+
if (!_clkApp) _clkApp=`E.showMessage("No Clock Found");setWatch(()=>{Bangle.showLauncher();}, globalThis.BTN2||BTN, {repeat:false,edge:"falling"});`;
2828
eval(_clkApp);
2929
delete _clkApp;

apps/boot/bootupdate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Bluetooth.on('data',function(d) {
4949
});
5050
Bluetooth.on('line',function(l) {
5151
if (l.startsWith('\x10')) l=l.slice(1);
52-
if (l.startsWith('GB({') && l.endsWith('})') && global.GB)
53-
try { global.GB(JSON.parse(l.slice(3,-1))); } catch(e) {}
52+
if (l.startsWith('GB({') && l.endsWith('})') && globalThis.GB)
53+
try { globalThis.GB(JSON.parse(l.slice(3,-1))); } catch(e) {}
5454
});\n`;
5555
} else {
5656
if (s.log>=2) boot += `_DBGLOG=require("Storage").open("log.txt","a");
@@ -73,7 +73,7 @@ if (s.log) boot += `E.on('errorFlag', function(errorFlags) {
7373
E.getErrorFlags();
7474
});\n`;// E.getErrorFlags() -> clear flags so we get called next time
7575
// stop users doing bad things!
76-
if (global.save) boot += `global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }\n`;
76+
if (globalThis.save) boot += `globalThis.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }\n`;
7777
// Apply any settings-specific stuff
7878
if (s.options) boot+=`Bangle.setOptions(${E.toJS(s.options)});\n`;
7979
if (s.brightness && s.brightness!=1) boot+=`Bangle.setLCDBrightness(${s.brightness});\n`;
@@ -85,7 +85,7 @@ if (s.bleprivacy || (s.passkey!==undefined && s.passkey.length==6)) {
8585
if (s.blename === false) boot+=`NRF.setAdvertising({},{showName:false});\n`;
8686
if (s.whitelist && !s.whitelist_disabled) boot+=`NRF.on('connect', function(addr) { if (!NRF.ignoreWhitelist) { let whitelist = (require('Storage').readJSON('setting.json',1)||{}).whitelist; if (NRF.resolveAddress !== undefined) { let resolvedAddr = NRF.resolveAddress(addr); if (resolvedAddr !== undefined) addr = resolvedAddr + " (resolved)"; } if (!whitelist.includes(addr)) NRF.disconnect(); }});\n`;
8787
if (s.rotate) boot+=`g.setRotation(${s.rotate&3},${s.rotate>>2});\n` // screen rotation
88-
boot+=`Bangle.loadWidgets=function(){if(!global.WIDGETS)eval(require("Storage").read(".widcache"))};\n`;
88+
boot+=`Bangle.loadWidgets=function(){if(!globalThis.WIDGETS)eval(require("Storage").read(".widcache"))};\n`;
8989
// ================================================== FIXING OLDER FIRMWARES
9090
// deleting stops us getting confused by our own decl. builtins can't be deleted
9191
// this is a polyfill without fastloading capability
@@ -175,7 +175,7 @@ require('Storage').write('.boot0',bootPost,fileOffset);
175175
delete boot,bootPost,bootFiles;
176176
// ================================================== .WIDCACHE for widgets
177177
let widgetFiles = require("Storage").list(/\.wid\.js$/);
178-
let widget = `// Made by bootupdate.js\nglobal.WIDGETS={};`, widgetPost = `var W=WIDGETS;WIDGETS={};
178+
let widget = `// Made by bootupdate.js\nglobalThis.WIDGETS={};`, widgetPost = `var W=WIDGETS;WIDGETS={};
179179
Object.keys(W).sort((a,b)=>(0|W[b].sortorder)-(0|W[a].sortorder)).forEach(k=>WIDGETS[k]=W[k]);`; // sort
180180
if (DEBUG) widget+="var _tm=Date.now();";
181181
outputFileComplete = (dst,fn) => {

apps/bthrm/bthrm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function draw(){
121121

122122

123123
// This can get called for the boot code to show what's happening
124-
global.showStatusInfo = function(txt) {
124+
globalThis.showStatusInfo = function(txt) {
125125
var R = Bangle.appRect;
126126
g.reset().clearRect(R.x,R.y2-8,R.x2,R.y2).setFont("6x8");
127127
txt = g.wrapString(txt, R.w)[0];

0 commit comments

Comments
 (0)