mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
ISSUE-1609: Create communication mechanism between windows, implement dark theme for sticks window using it. Small fix for Tip popup window.
This commit is contained in:
parent
c6fd43fdec
commit
262bc05ab5
11 changed files with 190 additions and 72 deletions
59
src/js/utils/window_watchers.js
Normal file
59
src/js/utils/window_watchers.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
'use strict';
|
||||
|
||||
/*
|
||||
This utility is intended to communicate between chrome windows.
|
||||
One window could watch passed values from another window and react to them.
|
||||
*/
|
||||
|
||||
var windowWatcherUtil = {};
|
||||
|
||||
windowWatcherUtil.invokeWatcher = function(bindingKey, bindingVal, watchersObject) {
|
||||
if (watchersObject[bindingKey]) {
|
||||
watchersObject[bindingKey](bindingVal);
|
||||
}
|
||||
}
|
||||
|
||||
windowWatcherUtil.iterateOverBindings = function(bindings, watchersObject) {
|
||||
let entries = Object.entries(bindings);
|
||||
for (const [key, val] of entries) {
|
||||
this.invokeWatcher(key, val, watchersObject)
|
||||
}
|
||||
}
|
||||
|
||||
windowWatcherUtil.bindWatchers = function(windowObject, watchersObject) {
|
||||
if (!windowObject.bindings) {
|
||||
windowObject.bindings = {};
|
||||
} else {
|
||||
this.iterateOverBindings(windowObject.bindings, watchersObject);
|
||||
}
|
||||
|
||||
windowObject.bindings = new Proxy(windowObject.bindings, {
|
||||
set(target, prop, val, receiver) {
|
||||
windowWatcherUtil.invokeWatcher(prop, val, watchersObject);
|
||||
return Reflect.set(target, prop, val, receiver);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 'Windows' here could be array or single window reference
|
||||
windowWatcherUtil.passValue = function(windows, key, val) {
|
||||
let applyBinding = function(win, key, val) {
|
||||
if (!win) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (win.contentWindow.bindings) {
|
||||
win.contentWindow.bindings[key] = val;
|
||||
} else {
|
||||
win.contentWindow.bindings = {
|
||||
[key]: val
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(windows)) {
|
||||
windows.forEach((el) => applyBinding(el, key, val));
|
||||
} else {
|
||||
applyBinding(windows, key, val)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue