@raydiant/playlist-window-manager 0.0.0-electron-upgrade-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.eslintrc +6 -0
  2. package/README.md +16 -0
  3. package/babel.config.js +13 -0
  4. package/build/BrowserViewRenderer.d.ts +19 -0
  5. package/build/BrowserViewRenderer.js +213 -0
  6. package/build/BrowserWindowRenderer.d.ts +47 -0
  7. package/build/BrowserWindowRenderer.js +524 -0
  8. package/build/IFrameRenderer.d.ts +20 -0
  9. package/build/IFrameRenderer.js +226 -0
  10. package/build/PlaylistWindowManager.d.ts +111 -0
  11. package/build/PlaylistWindowManager.js +1056 -0
  12. package/build/PlaylistWindowManagerState.d.ts +28 -0
  13. package/build/PlaylistWindowManagerState.js +60 -0
  14. package/build/PresentationWindow.d.ts +149 -0
  15. package/build/PresentationWindow.js +1235 -0
  16. package/build/PresentationWindow.test.d.ts +1 -0
  17. package/build/PresentationWindow.test.js +340 -0
  18. package/build/WindowLoadError.d.ts +3 -0
  19. package/build/WindowLoadError.js +29 -0
  20. package/build/WindowTimeoutError.d.ts +3 -0
  21. package/build/WindowTimeoutError.js +29 -0
  22. package/build/WindowUnresponsiveError.d.ts +3 -0
  23. package/build/WindowUnresponsiveError.js +29 -0
  24. package/build/embeddedApps.d.ts +2 -0
  25. package/build/embeddedApps.js +59 -0
  26. package/build/embeddedApps.test.d.ts +1 -0
  27. package/build/embeddedApps.test.js +123 -0
  28. package/build/index.d.ts +10 -0
  29. package/build/index.js +30 -0
  30. package/build/preload.d.ts +1 -0
  31. package/build/preload.js +20 -0
  32. package/build/testUtils.d.ts +43 -0
  33. package/build/testUtils.js +209 -0
  34. package/build/types.d.ts +162 -0
  35. package/build/types.js +2 -0
  36. package/jest.config.js +6 -0
  37. package/package.json +30 -0
  38. package/src/BrowserViewRenderer.ts +180 -0
  39. package/src/BrowserWindowRenderer.ts +595 -0
  40. package/src/IFrameRenderer.ts +251 -0
  41. package/src/PlaylistWindowManager.ts +1094 -0
  42. package/src/PlaylistWindowManagerState.ts +70 -0
  43. package/src/PresentationWindow.test.ts +333 -0
  44. package/src/PresentationWindow.ts +1434 -0
  45. package/src/WindowLoadError.ts +8 -0
  46. package/src/WindowTimeoutError.ts +8 -0
  47. package/src/WindowUnresponsiveError.ts +8 -0
  48. package/src/embeddedApps.test.ts +231 -0
  49. package/src/embeddedApps.ts +74 -0
  50. package/src/index.ts +13 -0
  51. package/src/preload.ts +27 -0
  52. package/src/testUtils.ts +160 -0
  53. package/src/types.ts +199 -0
  54. package/tasks/npm-publish.sh +13 -0
  55. package/tsconfig.json +7 -0
@@ -0,0 +1,180 @@
1
+ import * as path from 'path';
2
+ import { BrowserWindow, BrowserView, ipcMain, IpcMainEvent } from 'electron';
3
+ import {
4
+ PresentationWindowRenderer,
5
+ CreateWindowOptions,
6
+ WindowBounds,
7
+ } from './types';
8
+
9
+ interface BrowserViewRendererWindow {
10
+ view: BrowserView;
11
+ bounds: WindowBounds;
12
+ receiveMessageCallback: (
13
+ event: IpcMainEvent,
14
+ type: string,
15
+ payload?: any
16
+ ) => void;
17
+ }
18
+
19
+ export default class BrowserViewRenderer implements PresentationWindowRenderer {
20
+ private windows: {
21
+ [windowId: string]: BrowserViewRendererWindow;
22
+ } = {};
23
+
24
+ constructor(
25
+ private mainWindow: BrowserWindow,
26
+ private offscreenWindow: BrowserWindow
27
+ ) {}
28
+
29
+ public async createWindow({
30
+ windowId,
31
+ parentWindowId,
32
+ bounds,
33
+ backgroundColor,
34
+ receiveMessageCallback,
35
+ }: CreateWindowOptions) {
36
+ const window = {
37
+ view: new BrowserView({
38
+ webPreferences: {
39
+ preload: path.join(__dirname, 'preload.js'),
40
+ contextIsolation: false,
41
+ },
42
+ }),
43
+
44
+ bounds: bounds || { ...this.mainWindow.getBounds(), x: 0, y: 0 },
45
+
46
+ receiveMessageCallback: (
47
+ _: IpcMainEvent,
48
+ type: string,
49
+ payload?: any
50
+ ) => {
51
+ if (receiveMessageCallback) {
52
+ receiveMessageCallback(type, payload);
53
+ }
54
+ },
55
+ };
56
+
57
+ this.windows[windowId] = window;
58
+
59
+ ipcMain.on(windowId, window.receiveMessageCallback);
60
+
61
+ this.offscreenWindow.addBrowserView(window.view);
62
+ window.view.setBounds(window.bounds);
63
+
64
+ if (backgroundColor) {
65
+ window.view.setBackgroundColor(backgroundColor);
66
+ }
67
+
68
+ // The main window browserviews should auto size with the container but child window
69
+ // browser views have their own resize handlers and are updated via updateWindowBounds.
70
+ if (!parentWindowId) {
71
+ window.view.setAutoResize({
72
+ width: true,
73
+ height: true,
74
+ });
75
+ }
76
+ }
77
+
78
+ public async loadWindow(windowId: string, url: string) {
79
+ const window = this.getWindow(windowId);
80
+ if (!window) {
81
+ throw new Error(`Failed to load window, missing window id '${windowId}'`);
82
+ }
83
+
84
+ await window.view.webContents.loadURL(url);
85
+ }
86
+
87
+ public updateWindowBounds(windowId: string, bounds: WindowBounds) {
88
+ const window = this.getWindow(windowId);
89
+ if (!window) {
90
+ throw new Error(
91
+ `Failed to update window bounds, missing window id '${windowId}'`
92
+ );
93
+ }
94
+
95
+ window.bounds = bounds;
96
+ window.view.setBounds(window.bounds);
97
+ }
98
+
99
+ public showWindow(windowId: string, isFocused: boolean) {
100
+ const window = this.getWindow(windowId);
101
+ if (!window) {
102
+ throw new Error(`Failed to show window, missing window id '${windowId}'`);
103
+ }
104
+
105
+ this.mainWindow.addBrowserView(window.view);
106
+
107
+ if (isFocused) {
108
+ // The setTimeout is required to set focus after the BrowserView has
109
+ // been added to the parent BrowserWindow.
110
+ setTimeout(() => window.view.webContents.focus(), 0);
111
+ }
112
+ }
113
+
114
+ public hideWindow(windowId: string) {
115
+ const window = this.getWindow(windowId);
116
+ if (!window) {
117
+ throw new Error(`Failed to hide window, missing window id '${windowId}'`);
118
+ }
119
+
120
+ this.offscreenWindow.addBrowserView(window.view);
121
+ }
122
+
123
+ public async removeWindow(windowId: string) {
124
+ const window = this.getWindow(windowId);
125
+ if (!window) {
126
+ throw new Error(`Failed to hide window, missing window id '${windowId}'`);
127
+ }
128
+
129
+ this.hideWindow(windowId);
130
+ window.view.webContents.loadURL('about:blank');
131
+ ipcMain.off(windowId, window.receiveMessageCallback);
132
+ delete this.windows[windowId];
133
+ }
134
+
135
+ public sendMessageString(windowId: string, message: string) {
136
+ const window = this.getWindow(windowId);
137
+ if (!window) {
138
+ throw new Error(
139
+ `Failed to send message to window, missing window id '${windowId}'`
140
+ );
141
+ }
142
+
143
+ window.view.webContents.send('electron-main', message);
144
+ }
145
+
146
+ public sendMessageObject(windowId: string, type: string, payload?: any) {
147
+ const window = this.getWindow(windowId);
148
+ if (!window) {
149
+ throw new Error(
150
+ `Failed to send message to window, missing window id '${windowId}'`
151
+ );
152
+ }
153
+
154
+ window.view.webContents.send('electron-main', { type, payload });
155
+ }
156
+
157
+ public muteWindow(windowId: string) {
158
+ const window = this.getWindow(windowId);
159
+ if (!window) {
160
+ throw new Error(`Failed to mute window, missing window id '${windowId}'`);
161
+ }
162
+
163
+ window.view.webContents.setAudioMuted(true);
164
+ }
165
+
166
+ public unMuteWindow(windowId: string) {
167
+ const window = this.getWindow(windowId);
168
+ if (!window) {
169
+ throw new Error(
170
+ `Failed to unmute window, missing window id '${windowId}'`
171
+ );
172
+ }
173
+
174
+ window.view.webContents.setAudioMuted(false);
175
+ }
176
+
177
+ private getWindow(windowId: string): BrowserViewRendererWindow | null {
178
+ return this.windows[windowId];
179
+ }
180
+ }