@raydiant/playlist-window-manager 0.0.0-test-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 +214 -0
  6. package/build/BrowserWindowRenderer.d.ts +47 -0
  7. package/build/BrowserWindowRenderer.js +528 -0
  8. package/build/IFrameRenderer.d.ts +20 -0
  9. package/build/IFrameRenderer.js +226 -0
  10. package/build/PlaylistWindowManager.d.ts +106 -0
  11. package/build/PlaylistWindowManager.js +1018 -0
  12. package/build/PlaylistWindowManagerState.d.ts +28 -0
  13. package/build/PlaylistWindowManagerState.js +60 -0
  14. package/build/PresentationWindow.d.ts +142 -0
  15. package/build/PresentationWindow.js +1140 -0
  16. package/build/PresentationWindow.test.d.ts +1 -0
  17. package/build/PresentationWindow.test.js +241 -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 +208 -0
  34. package/build/types.d.ts +142 -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 +182 -0
  39. package/src/BrowserWindowRenderer.ts +624 -0
  40. package/src/IFrameRenderer.ts +251 -0
  41. package/src/PlaylistWindowManager.ts +1042 -0
  42. package/src/PlaylistWindowManagerState.ts +70 -0
  43. package/src/PresentationWindow.test.ts +221 -0
  44. package/src/PresentationWindow.ts +1327 -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 +159 -0
  53. package/src/types.ts +175 -0
  54. package/tasks/npm-publish.sh +13 -0
  55. package/tsconfig.json +7 -0
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.createRenderer = exports.createLogger = exports.createRuleEngineState = exports.createPlaylistWindowManagerState = exports.createApplicationVersion = exports.createPresentationRelationships = exports.createPresentation = exports.createPresentationWindow = void 0;
66
+ var re = __importStar(require("@raydiant/playlist-rule-engine"));
67
+ var PresentationWindow_1 = __importDefault(require("./PresentationWindow"));
68
+ var PlaylistWindowManagerState_1 = __importDefault(require("./PlaylistWindowManagerState"));
69
+ function createPresentationWindow(overrides) {
70
+ var _a, _b, _c, _d, _e, _f;
71
+ if (overrides === void 0) { overrides = {}; }
72
+ return new PresentationWindow_1.default({
73
+ windowId: (_a = overrides.windowId) !== null && _a !== void 0 ? _a : 'test',
74
+ presentation: createPresentation(overrides.presentation),
75
+ applicationVersion: createApplicationVersion(overrides.applicationVersion),
76
+ publishedAt: (_b = overrides.publishedAt) !== null && _b !== void 0 ? _b : 'publishedAt',
77
+ playlistWindowManagerState: (_c = overrides.playlistWindowManagerState) !== null && _c !== void 0 ? _c : createPlaylistWindowManagerState(),
78
+ ruleEngineState: (_d = overrides.ruleEngineState) !== null && _d !== void 0 ? _d : createRuleEngineState(),
79
+ logger: createLogger(),
80
+ workerState: (_e = overrides.workerState) !== null && _e !== void 0 ? _e : {},
81
+ renderer: (_f = overrides.renderer) !== null && _f !== void 0 ? _f : {
82
+ createWindow: function () { },
83
+ loadWindow: function () {
84
+ return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
85
+ return [2 /*return*/];
86
+ }); });
87
+ },
88
+ updateWindowBounds: function () { },
89
+ showWindow: function () { },
90
+ hideWindow: function () { },
91
+ removeWindow: function () {
92
+ return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
93
+ return [2 /*return*/];
94
+ }); });
95
+ },
96
+ sendMessageString: function () { },
97
+ sendMessageObject: function () { },
98
+ muteWindow: function () { },
99
+ unMuteWindow: function () { },
100
+ },
101
+ });
102
+ }
103
+ exports.createPresentationWindow = createPresentationWindow;
104
+ function createPresentation(overrides) {
105
+ var _a, _b, _c, _d, _e, _f;
106
+ if (overrides === void 0) { overrides = {}; }
107
+ return {
108
+ id: (_a = overrides.id) !== null && _a !== void 0 ? _a : 'id',
109
+ name: (_b = overrides.name) !== null && _b !== void 0 ? _b : 'name',
110
+ applicationDeploymentId: (_c = overrides.applicationDeploymentId) !== null && _c !== void 0 ? _c : 'applicationDeploymentId',
111
+ themeId: (_d = overrides.themeId) !== null && _d !== void 0 ? _d : null,
112
+ applicationVariables: (_e = overrides.applicationVariables) !== null && _e !== void 0 ? _e : {},
113
+ duration: (_f = overrides.duration) !== null && _f !== void 0 ? _f : 1,
114
+ r: createPresentationRelationships(overrides.r),
115
+ };
116
+ }
117
+ exports.createPresentation = createPresentation;
118
+ function createPresentationRelationships(overrides) {
119
+ var _a, _b;
120
+ if (overrides === void 0) { overrides = {}; }
121
+ return {
122
+ resource: (_a = overrides.resource) !== null && _a !== void 0 ? _a : {
123
+ updatedAt: 'updatedAt',
124
+ createdAt: 'createdAt',
125
+ },
126
+ presentationsPlaylists: (_b = overrides.presentationsPlaylists) !== null && _b !== void 0 ? _b : [],
127
+ };
128
+ }
129
+ exports.createPresentationRelationships = createPresentationRelationships;
130
+ function createApplicationVersion(overrides) {
131
+ var _a, _b, _c, _d, _e, _f, _g;
132
+ if (overrides === void 0) { overrides = {}; }
133
+ return {
134
+ id: (_a = overrides.id) !== null && _a !== void 0 ? _a : 'id',
135
+ name: (_b = overrides.name) !== null && _b !== void 0 ? _b : 'name',
136
+ applicationId: (_c = overrides.applicationId) !== null && _c !== void 0 ? _c : 'applicationId',
137
+ embeddedUrlFormat: (_d = overrides.embeddedUrlFormat) !== null && _d !== void 0 ? _d : null,
138
+ configurableDuration: (_e = overrides.configurableDuration) !== null && _e !== void 0 ? _e : false,
139
+ sourceUrl: (_f = overrides.sourceUrl) !== null && _f !== void 0 ? _f : null,
140
+ presentationProperties: (_g = overrides.presentationProperties) !== null && _g !== void 0 ? _g : [],
141
+ };
142
+ }
143
+ exports.createApplicationVersion = createApplicationVersion;
144
+ function createPlaylistWindowManagerState(overrides) {
145
+ var _a, _b, _c, _d;
146
+ if (overrides === void 0) { overrides = {}; }
147
+ return new PlaylistWindowManagerState_1.default({
148
+ presentations: (_a = overrides.presentations) !== null && _a !== void 0 ? _a : {},
149
+ applicationVersions: (_b = overrides.applicationVersions) !== null && _b !== void 0 ? _b : {},
150
+ themes: (_c = overrides.themes) !== null && _c !== void 0 ? _c : {},
151
+ publishedAt: (_d = overrides.publishedAt) !== null && _d !== void 0 ? _d : 'publishedAt',
152
+ });
153
+ }
154
+ exports.createPlaylistWindowManagerState = createPlaylistWindowManagerState;
155
+ function createRuleEngineState(playlists, presentations, rulesDataStore, isMultitimezoneEnabled) {
156
+ if (playlists === void 0) { playlists = {}; }
157
+ if (presentations === void 0) { presentations = {}; }
158
+ if (rulesDataStore === void 0) { rulesDataStore = {}; }
159
+ if (isMultitimezoneEnabled === void 0) { isMultitimezoneEnabled = false; }
160
+ return new re.State(playlists, presentations, rulesDataStore, isMultitimezoneEnabled);
161
+ }
162
+ exports.createRuleEngineState = createRuleEngineState;
163
+ function createLogger(overrides) {
164
+ var _a, _b, _c, _d;
165
+ if (overrides === void 0) { overrides = {}; }
166
+ var noop = function () { };
167
+ return {
168
+ debug: (_a = overrides.debug) !== null && _a !== void 0 ? _a : noop,
169
+ info: (_b = overrides.info) !== null && _b !== void 0 ? _b : noop,
170
+ warn: (_c = overrides.warn) !== null && _c !== void 0 ? _c : noop,
171
+ error: (_d = overrides.error) !== null && _d !== void 0 ? _d : noop,
172
+ };
173
+ }
174
+ exports.createLogger = createLogger;
175
+ function createRenderer() {
176
+ var createWindowOpts = null;
177
+ return {
178
+ createWindow: jest.fn(function (opts) {
179
+ createWindowOpts = opts;
180
+ }),
181
+ loadWindow: jest.fn(),
182
+ updateWindowBounds: jest.fn(),
183
+ showWindow: jest.fn(),
184
+ hideWindow: jest.fn(),
185
+ removeWindow: jest.fn(),
186
+ sendMessageString: jest.fn(),
187
+ sendMessageObject: jest.fn(),
188
+ muteWindow: jest.fn(),
189
+ unMuteWindow: jest.fn(),
190
+ runReceiveMessageCallback: function (type, payload) {
191
+ if (createWindowOpts === null || createWindowOpts === void 0 ? void 0 : createWindowOpts.receiveMessageCallback) {
192
+ createWindowOpts.receiveMessageCallback(type, payload);
193
+ }
194
+ else {
195
+ throw new Error('No receiveMessageCallback defined, make sure to call window.load first');
196
+ }
197
+ },
198
+ runErrorCallback: function (error) {
199
+ if (createWindowOpts === null || createWindowOpts === void 0 ? void 0 : createWindowOpts.errorCallback) {
200
+ createWindowOpts.errorCallback(error);
201
+ }
202
+ else {
203
+ throw new Error('No errorCallback defined, make sure to call window.load first');
204
+ }
205
+ },
206
+ };
207
+ }
208
+ exports.createRenderer = createRenderer;
@@ -0,0 +1,142 @@
1
+ export interface Playlist {
2
+ id: string;
3
+ }
4
+ export interface Presentation {
5
+ id: string;
6
+ name: string;
7
+ applicationDeploymentId: string;
8
+ themeId: string | null;
9
+ applicationVariables: {
10
+ [key: string]: any;
11
+ };
12
+ duration: number;
13
+ r: {
14
+ resource: {
15
+ updatedAt: string;
16
+ createdAt: string;
17
+ };
18
+ presentationsPlaylists: Array<{
19
+ playlistId: string;
20
+ }>;
21
+ };
22
+ }
23
+ export interface ApplicationVersion {
24
+ id: string;
25
+ name: string;
26
+ applicationId: string;
27
+ embeddedUrlFormat: string | null;
28
+ configurableDuration: boolean;
29
+ sourceUrl: string | null;
30
+ presentationProperties: Array<{
31
+ name: string;
32
+ type: string;
33
+ encode?: boolean;
34
+ }>;
35
+ }
36
+ export interface Font {
37
+ id: string;
38
+ name: string;
39
+ weight: string;
40
+ fileUpload: {
41
+ url: string;
42
+ };
43
+ }
44
+ export interface Theme {
45
+ id: string;
46
+ name: string;
47
+ backgroundColor: string;
48
+ backgroundImage: string;
49
+ backgroundImagePortrait: string;
50
+ headingTextColor: string;
51
+ headingFont: string;
52
+ heading2TextColor: string;
53
+ heading2Font: string;
54
+ bodyTextColor: string;
55
+ bodyFont: string;
56
+ borderColor: string;
57
+ headingFontNew: Font | null;
58
+ heading2FontNew: Font | null;
59
+ bodyFontNew: Font | null;
60
+ backgroundImageFileUpload: {
61
+ url: string;
62
+ } | null;
63
+ backgroundScale: 'fit' | 'fill' | null;
64
+ }
65
+ export interface Device {
66
+ id: string;
67
+ name: string | null;
68
+ }
69
+ export interface WindowBounds {
70
+ x: number;
71
+ y: number;
72
+ width: number;
73
+ height: number;
74
+ }
75
+ export interface WorkerState {
76
+ [key: string]: any;
77
+ }
78
+ export interface PreviewState {
79
+ inputs: Record<string, any>;
80
+ }
81
+ export interface CreateWindowOptions {
82
+ windowId: string;
83
+ parentWindowId?: string;
84
+ bounds?: WindowBounds;
85
+ backgroundColor?: string;
86
+ receiveMessageCallback?: (type: string, payload?: any) => void;
87
+ errorCallback: (err: any) => void;
88
+ }
89
+ export interface Logger {
90
+ debug(message: any, context?: {
91
+ [key: string]: any;
92
+ }): void;
93
+ info(message: any, context?: {
94
+ [key: string]: any;
95
+ }): void;
96
+ warn(message: any, context?: {
97
+ [key: string]: any;
98
+ }): void;
99
+ error(message: any, context?: {
100
+ [key: string]: any;
101
+ }): void;
102
+ }
103
+ export interface PresentationWindowRenderer {
104
+ createWindow(options: CreateWindowOptions): void;
105
+ loadWindow(windowId: string, url: string): Promise<void>;
106
+ updateWindowBounds(windowId: string, bounds: WindowBounds): void;
107
+ showWindow(windowId: string, isFocused: boolean): void;
108
+ hideWindow(windowId: string): void;
109
+ removeWindow(windowId: string): Promise<void>;
110
+ sendMessageString(windowId: string, message: string): void;
111
+ sendMessageObject(windowId: string, type: string, payload?: any): void;
112
+ muteWindow(windowId: string): void;
113
+ unMuteWindow(windowId: string): void;
114
+ }
115
+ export interface OpenChildWindowOptions {
116
+ windowId: string;
117
+ playlistId: string;
118
+ x: number;
119
+ y: number;
120
+ width: number;
121
+ height: number;
122
+ isFocused: boolean;
123
+ isMuted: boolean;
124
+ theme?: Theme;
125
+ }
126
+ export type Path = Array<string | number>;
127
+ export interface BuilderState {
128
+ inputs: InputState[];
129
+ profileId?: string;
130
+ }
131
+ export interface InputState {
132
+ path: Path;
133
+ state: any;
134
+ }
135
+ export interface EmbeddedAppMetadata {
136
+ renderMode: 'preview' | 'live';
137
+ }
138
+ export interface AnalyticsEvent {
139
+ type: string;
140
+ source: string;
141
+ productCategory?: string | null;
142
+ }
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ roots: ['<rootDir>/src'],
3
+ transform: {
4
+ '^.+\\.tsx?$': 'ts-jest'
5
+ }
6
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@raydiant/playlist-window-manager",
3
+ "version": "0.0.0-test-1",
4
+ "description": "Window manager for playlist playback.",
5
+ "main": "build/index.js",
6
+ "scripts": {
7
+ "build": "rm -rf build && tsc",
8
+ "lint": "eslint -c ./.eslintrc **/*.ts",
9
+ "tsc": "tsc",
10
+ "test": "jest",
11
+ "deploy": "sh tasks/npm-publish.sh"
12
+ },
13
+ "dependencies": {
14
+ "fast-deep-equal": "^3.1.3",
15
+ "@raydiant/playlist-rule-engine": "3.2.2",
16
+ "raydiant-kit": "4.7.3",
17
+ "uuid": "^8.3.0",
18
+ "eventemitter3": "^4.0.7"
19
+ },
20
+ "devDependencies": {
21
+ "@babel/core": "^7.5.5",
22
+ "@types/jschannel": "^1.0.1",
23
+ "@types/jest": "^24.0.15",
24
+ "@types/uuid": "8.3.0",
25
+ "electron": "10.1.5",
26
+ "jest": "^24.8.0",
27
+ "ts-jest": "^24.0.2",
28
+ "typescript": "^4.1.2"
29
+ }
30
+ }
@@ -0,0 +1,182 @@
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
+ // TODO log bounds
37
+
38
+ const window = {
39
+ view: new BrowserView({
40
+ webPreferences: {
41
+ preload: path.join(__dirname, 'preload.js'),
42
+ },
43
+ }),
44
+
45
+ bounds: bounds || { ...this.mainWindow.getBounds(), x: 0, y: 0 },
46
+
47
+ receiveMessageCallback: (
48
+ _: IpcMainEvent,
49
+ type: string,
50
+ payload?: any
51
+ ) => {
52
+ if (receiveMessageCallback) {
53
+ receiveMessageCallback(type, payload);
54
+ }
55
+ },
56
+ };
57
+
58
+ this.windows[windowId] = window;
59
+
60
+ ipcMain.on(windowId, window.receiveMessageCallback);
61
+
62
+ this.offscreenWindow.addBrowserView(window.view);
63
+ // TODO log bounds
64
+ window.view.setBounds(window.bounds);
65
+
66
+ if (backgroundColor) {
67
+ window.view.setBackgroundColor(backgroundColor);
68
+ }
69
+
70
+ // The main window browserviews should auto size with the container but child window
71
+ // browser views have their own resize handlers and are updated via updateWindowBounds.
72
+ if (!parentWindowId) {
73
+ window.view.setAutoResize({
74
+ width: true,
75
+ height: true,
76
+ });
77
+ }
78
+ }
79
+
80
+ public async loadWindow(windowId: string, url: string) {
81
+ const window = this.getWindow(windowId);
82
+ if (!window) {
83
+ throw new Error(`Failed to load window, missing window id '${windowId}'`);
84
+ }
85
+
86
+ await window.view.webContents.loadURL(url);
87
+ }
88
+
89
+ public updateWindowBounds(windowId: string, bounds: WindowBounds) {
90
+ const window = this.getWindow(windowId);
91
+ if (!window) {
92
+ throw new Error(
93
+ `Failed to update window bounds, missing window id '${windowId}'`
94
+ );
95
+ }
96
+ // TODO log bounds
97
+ window.bounds = bounds;
98
+ window.view.setBounds(window.bounds);
99
+ }
100
+
101
+ public showWindow(windowId: string, isFocused: boolean) {
102
+ const window = this.getWindow(windowId);
103
+ if (!window) {
104
+ throw new Error(`Failed to show window, missing window id '${windowId}'`);
105
+ }
106
+
107
+ this.mainWindow.addBrowserView(window.view);
108
+
109
+ if (isFocused) {
110
+ // The setTimeout is required to set focus after the BrowserView has
111
+ // been added to the parent BrowserWindow.
112
+ setTimeout(() => window.view.webContents.focus(), 0);
113
+ }
114
+ }
115
+
116
+ public hideWindow(windowId: string) {
117
+ const window = this.getWindow(windowId);
118
+ if (!window) {
119
+ throw new Error(`Failed to hide window, missing window id '${windowId}'`);
120
+ }
121
+
122
+ this.offscreenWindow.addBrowserView(window.view);
123
+ }
124
+
125
+ public async removeWindow(windowId: string) {
126
+ const window = this.getWindow(windowId);
127
+ if (!window) {
128
+ throw new Error(`Failed to hide window, missing window id '${windowId}'`);
129
+ }
130
+
131
+ this.hideWindow(windowId);
132
+ window.view.webContents.loadURL('about:blank');
133
+ ipcMain.off(windowId, window.receiveMessageCallback);
134
+ delete this.windows[windowId];
135
+ }
136
+
137
+ public sendMessageString(windowId: string, message: string) {
138
+ const window = this.getWindow(windowId);
139
+ if (!window) {
140
+ throw new Error(
141
+ `Failed to send message to window, missing window id '${windowId}'`
142
+ );
143
+ }
144
+
145
+ window.view.webContents.send('electron-main', message);
146
+ }
147
+
148
+ public sendMessageObject(windowId: string, type: string, payload?: any) {
149
+ const window = this.getWindow(windowId);
150
+ if (!window) {
151
+ throw new Error(
152
+ `Failed to send message to window, missing window id '${windowId}'`
153
+ );
154
+ }
155
+
156
+ window.view.webContents.send('electron-main', { type, payload });
157
+ }
158
+
159
+ public muteWindow(windowId: string) {
160
+ const window = this.getWindow(windowId);
161
+ if (!window) {
162
+ throw new Error(`Failed to mute window, missing window id '${windowId}'`);
163
+ }
164
+
165
+ window.view.webContents.setAudioMuted(true);
166
+ }
167
+
168
+ public unMuteWindow(windowId: string) {
169
+ const window = this.getWindow(windowId);
170
+ if (!window) {
171
+ throw new Error(
172
+ `Failed to unmute window, missing window id '${windowId}'`
173
+ );
174
+ }
175
+
176
+ window.view.webContents.setAudioMuted(false);
177
+ }
178
+
179
+ private getWindow(windowId: string): BrowserViewRendererWindow | null {
180
+ return this.windows[windowId];
181
+ }
182
+ }