MCPcopy Create free account
hub / github.com/bgstaal/multipleWindow3dScene / WindowManager

Class WindowManager

WindowManager.js:1–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class WindowManager
2{
3 #windows;
4 #count;
5 #id;
6 #winData;
7 #winShapeChangeCallback;
8 #winChangeCallback;
9
10 constructor ()
11 {
12 let that = this;
13
14 // event listener for when localStorage is changed from another window
15 addEventListener("storage", (event) =>
16 {
17 if (event.key == "windows")
18 {
19 let newWindows = JSON.parse(event.newValue);
20 let winChange = that.#didWindowsChange(that.#windows, newWindows);
21
22 that.#windows = newWindows;
23
24 if (winChange)
25 {
26 if (that.#winChangeCallback) that.#winChangeCallback();
27 }
28 }
29 });
30
31 // event listener for when current window is about to ble closed
32 window.addEventListener('beforeunload', function (e)
33 {
34 let index = that.getWindowIndexFromId(that.#id);
35
36 //remove this window from the list and update local storage
37 that.#windows.splice(index, 1);
38 that.updateWindowsLocalStorage();
39 });
40 }
41
42 // check if theres any changes to the window list
43 #didWindowsChange (pWins, nWins)
44 {
45 if (pWins.length != nWins.length)
46 {
47 return true;
48 }
49 else
50 {
51 let c = false;
52
53 for (let i = 0; i < pWins.length; i++)
54 {
55 if (pWins[i].id != nWins[i].id) c = true;
56 }
57
58 return c;
59 }
60 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected