Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/replay/backend/managers/OverlayManager.ts
1030 views
1
import { BrowserWindow } from 'electron';
2
import BaseOverlay from '../overlays/BaseOverlay';
3
import MainMenu from '../overlays/MainMenu';
4
import LocationsMenu from '../overlays/LocationsMenu';
5
import IRectangle from '~shared/interfaces/IRectangle';
6
import CommandOverlay from '../overlays/CommandOverlay';
7
import MessageOverlay from '../overlays/MessageOverlay';
8
import ListMenu from '~backend/overlays/ListMenu';
9
10
export default class OverlayManager {
11
private overlays: BaseOverlay[] = [];
12
13
public start() {
14
// this.overlays.push(new FindOverlay());
15
this.overlays.push(new MainMenu());
16
this.overlays.push(new ListMenu());
17
this.overlays.push(new LocationsMenu());
18
this.overlays.push(new CommandOverlay());
19
this.overlays.push(new MessageOverlay());
20
}
21
22
public show(name: string, browserWindow: BrowserWindow, rect: IRectangle, ...args: any[]) {
23
this.getByName(name).show(browserWindow, { rect }, ...args);
24
}
25
26
public toggle(name: string, browserWindow: BrowserWindow, rect: IRectangle) {
27
const overlay = this.getByName(name);
28
if (overlay.visible) {
29
overlay.hide();
30
} else {
31
overlay.show(browserWindow, { rect });
32
}
33
}
34
35
public get browserViews() {
36
return Array.from(this.overlays).map(x => x.browserView);
37
}
38
39
public destroy = () => {
40
this.browserViews.length = 0;
41
};
42
43
public sendToAll = (channel: string, ...args: any[]) => {
44
this.browserViews.forEach(x => x?.webContents.send(channel, ...args));
45
};
46
47
public getByName(name: string) {
48
return this.overlays.find(x => x.name === name);
49
}
50
51
public getByWebContentsId(webContentsId: number) {
52
return this.overlays.find(x => x.id === webContentsId);
53
}
54
55
public isVisible(name: string) {
56
return this.getByName(name).visible;
57
}
58
}
59
60