@raydiant/playlist-window-manager 0.0.0-test-20 → 0.0.0-test-21

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.
@@ -16,6 +16,7 @@ interface BrowserWindowRendererOptions {
16
16
  export default class BrowserWindowRenderer implements PresentationWindowRenderer {
17
17
  private opts;
18
18
  private windows;
19
+ private windowsBounds;
19
20
  private windowCrashHandler;
20
21
  private browserWindowPool;
21
22
  private browserViewPool;
@@ -41,6 +42,7 @@ export default class BrowserWindowRenderer implements PresentationWindowRenderer
41
42
  */
42
43
  private setWindowOrViewBounds;
43
44
  private getWindow;
45
+ private getWindowBounds;
44
46
  private moveWindowOffscreen;
45
47
  private addWindowToParent;
46
48
  private removeWindowFromParent;
@@ -75,12 +75,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
75
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
76
  var path = __importStar(require("path"));
77
77
  var electron_1 = require("electron");
78
+ var lodash_1 = __importDefault(require("lodash"));
78
79
  var WindowUnresponsiveError_1 = __importDefault(require("./WindowUnresponsiveError"));
79
80
  var boundUtils_1 = require("./boundUtils");
80
81
  var BrowserWindowRenderer = /** @class */ (function () {
81
82
  function BrowserWindowRenderer(opts) {
82
83
  this.opts = opts;
83
84
  this.windows = {};
85
+ this.windowsBounds = {};
84
86
  this.windowCrashHandler = function (_) { };
85
87
  this.browserWindowPool = new WindowPool();
86
88
  this.browserViewPool = new WindowPool();
@@ -108,13 +110,14 @@ var BrowserWindowRenderer = /** @class */ (function () {
108
110
  BrowserWindowRenderer.prototype.createWindow = function (_a) {
109
111
  var windowId = _a.windowId, parentWindowId = _a.parentWindowId, _b = _a.bounds, bounds = _b === void 0 ? this.opts.bounds : _b, backgroundColor = _a.backgroundColor, receiveMessageCallback = _a.receiveMessageCallback, errorCallback = _a.errorCallback;
110
112
  return __awaiter(this, void 0, void 0, function () {
111
- var window;
113
+ var windowBounds, window;
112
114
  var _this = this;
113
115
  return __generator(this, function (_c) {
114
116
  switch (_c.label) {
115
117
  case 0:
116
- this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts createWindow1: ".concat(JSON.stringify(parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
117
- ? __assign(__assign({}, bounds), { x: bounds.x + this.opts.bounds.x, y: bounds.y + this.opts.bounds.y }) : bounds)));
118
+ windowBounds = parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
119
+ ? __assign(__assign({}, bounds), { x: bounds.x + this.opts.bounds.x, y: bounds.y + this.opts.bounds.y }) : bounds;
120
+ this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts createWindow1: ".concat(JSON.stringify(windowBounds)));
118
121
  window = {
119
122
  parentWindowId: parentWindowId,
120
123
  // If we are creating a child window and renderChildWindowsAsBrowserViews is true,
@@ -144,8 +147,7 @@ var BrowserWindowRenderer = /** @class */ (function () {
144
147
  // we are rendering child windows with BrowserWindow. BrowserWindows are positioned absolutely so
145
148
  // to place them in the correct spot relative to their parent we need to add the main window's x / y.
146
149
  // BrowserViews are relatively positioned so we don't need to do that.
147
- bounds: parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
148
- ? __assign(__assign({}, bounds), { x: bounds.x + this.opts.bounds.x, y: bounds.y + this.opts.bounds.y }) : bounds,
150
+ bounds: windowBounds,
149
151
  receiveMessageCallback: function (_, type, payload) {
150
152
  if (receiveMessageCallback) {
151
153
  receiveMessageCallback(type, payload);
@@ -177,6 +179,7 @@ var BrowserWindowRenderer = /** @class */ (function () {
177
179
  })));
178
180
  }
179
181
  this.windows[windowId] = window;
182
+ this.windowsBounds[windowId] = lodash_1.default.cloneDeep(windowBounds);
180
183
  // Listen for messages from window.
181
184
  electron_1.ipcMain.on(windowId, window.receiveMessageCallback);
182
185
  if (backgroundColor) {
@@ -274,19 +277,21 @@ var BrowserWindowRenderer = /** @class */ (function () {
274
277
  BrowserWindowRenderer.prototype.showWindow = function (windowId, isFocused) {
275
278
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow1");
276
279
  var window = this.getWindow(windowId);
277
- if (!window) {
280
+ var windowBounds = this.getWindowBounds(windowId);
281
+ if (!window || !windowBounds) {
278
282
  throw new Error("Failed to show window, missing window id '".concat(windowId, "'"));
279
283
  }
280
284
  if (window.view instanceof electron_1.BrowserWindow) {
281
285
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow2: ".concat(JSON.stringify({
282
286
  fullscreen: window.view.isFullScreen(),
283
287
  bounds: window.view.getBounds(),
288
+ windowBounds: windowBounds,
284
289
  normalBounds: window.view.getNormalBounds(),
285
290
  contentBounds: window.view.getContentBounds(),
286
291
  })));
287
- if (window.view.isFullScreen()) {
288
- this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: setFullScreen(true)");
289
- window.view.setFullScreen(true);
292
+ if (!(0, boundUtils_1.areBoundsEqual)(window.view.getBounds(), windowBounds)) {
293
+ this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: setWindowOrViewBounds");
294
+ this.setWindowOrViewBounds(window.view, windowBounds);
290
295
  }
291
296
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow4: ".concat(JSON.stringify({
292
297
  fullscreen: window.view.isFullScreen(),
@@ -353,6 +358,7 @@ var BrowserWindowRenderer = /** @class */ (function () {
353
358
  _a.label = 4;
354
359
  case 4:
355
360
  delete this.windows[windowId];
361
+ delete this.windowsBounds[windowId];
356
362
  if (this.opts.useWindowPool) {
357
363
  this.logPoolStats();
358
364
  }
@@ -413,20 +419,21 @@ var BrowserWindowRenderer = /** @class */ (function () {
413
419
  })));
414
420
  // calling setBounds or setFullscreen may introduce -1px resolution error
415
421
  // so we try to avoid unnecessary calls
416
- if ((0, boundUtils_1.areBoundsEqual)(window.getBounds(), bounds) ||
417
- ((0, boundUtils_1.isFullscreen)(bounds) && window.isFullScreen())) {
422
+ if ((0, boundUtils_1.areBoundsEqual)(window.getBounds(), bounds)) {
418
423
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds3: bounds are equal");
419
424
  return;
420
425
  }
421
- if ((0, boundUtils_1.isFullscreen)(bounds)) {
422
- this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: full screen");
423
- window.setFullScreen(true);
424
- }
425
- else {
426
- // setBounds will be ignored if window was in fullscreen mode
427
- window.setFullScreen(false);
428
- window.setBounds(bounds);
426
+ if ((0, boundUtils_1.isFullscreen)(bounds) !== window.isFullScreen()) {
427
+ this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: setFullScreen");
428
+ window.setFullScreen((0, boundUtils_1.isFullscreen)(bounds));
429
429
  }
430
+ this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds5: before: ".concat(JSON.stringify({
431
+ fullscreen: window.isFullScreen(),
432
+ bounds: window.getBounds(),
433
+ contentBounds: window.getContentBounds(),
434
+ normalBounds: window.getNormalBounds(),
435
+ })));
436
+ window.setBounds(bounds);
430
437
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds6: before: ".concat(JSON.stringify({
431
438
  fullscreen: window.isFullScreen(),
432
439
  bounds: window.getBounds(),
@@ -437,6 +444,9 @@ var BrowserWindowRenderer = /** @class */ (function () {
437
444
  BrowserWindowRenderer.prototype.getWindow = function (windowId) {
438
445
  return this.windows[windowId];
439
446
  };
447
+ BrowserWindowRenderer.prototype.getWindowBounds = function (windowId) {
448
+ return this.windowsBounds[windowId];
449
+ };
440
450
  BrowserWindowRenderer.prototype.moveWindowOffscreen = function (window) {
441
451
  if (!(window.view instanceof electron_1.BrowserView)) {
442
452
  throw new Error("Failed move window offscreen, window is not a BrowserView");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raydiant/playlist-window-manager",
3
- "version": "0.0.0-test-20",
3
+ "version": "0.0.0-test-21",
4
4
  "description": "Window manager for playlist playback.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -11,16 +11,18 @@
11
11
  "deploy": "sh tasks/npm-publish.sh"
12
12
  },
13
13
  "dependencies": {
14
- "fast-deep-equal": "^3.1.3",
15
14
  "@raydiant/playlist-rule-engine": "3.2.2",
15
+ "eventemitter3": "^4.0.7",
16
+ "fast-deep-equal": "^3.1.3",
17
+ "lodash": "^4.17.21",
16
18
  "raydiant-kit": "4.7.3",
17
- "uuid": "^8.3.0",
18
- "eventemitter3": "^4.0.7"
19
+ "uuid": "^8.3.0"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@babel/core": "^7.5.5",
22
- "@types/jschannel": "^1.0.1",
23
23
  "@types/jest": "^24.0.15",
24
+ "@types/jschannel": "^1.0.1",
25
+ "@types/lodash": "^4.14.200",
24
26
  "@types/uuid": "8.3.0",
25
27
  "electron": "10.1.5",
26
28
  "jest": "^24.8.0",
@@ -16,6 +16,7 @@ import {
16
16
  WindowBounds,
17
17
  Logger,
18
18
  } from './types';
19
+ import lodash from 'lodash';
19
20
  import WindowUnresponsiveError from './WindowUnresponsiveError';
20
21
  import { areBoundsEqual, isFullscreen } from './boundUtils';
21
22
 
@@ -54,6 +55,9 @@ export default class BrowserWindowRenderer
54
55
  private windows: {
55
56
  [windowId: string]: BrowserWindowRendererWindow;
56
57
  } = {};
58
+ private windowsBounds: {
59
+ [windowId: string]: WindowBounds;
60
+ } = {};
57
61
  private windowCrashHandler: (reason: string) => void = (_: string) => {};
58
62
 
59
63
  private browserWindowPool = new WindowPool<BrowserWindow>();
@@ -112,15 +116,18 @@ export default class BrowserWindowRenderer
112
116
  receiveMessageCallback,
113
117
  errorCallback,
114
118
  }: CreateWindowOptions): Promise<void> {
119
+ const windowBounds =
120
+ parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
121
+ ? {
122
+ ...bounds,
123
+ x: bounds.x + this.opts.bounds.x,
124
+ y: bounds.y + this.opts.bounds.y,
125
+ }
126
+ : bounds;
127
+
115
128
  this.logger.info(
116
129
  `playlist-window-manager/src/BrowserWindowRenderer.ts createWindow1: ${JSON.stringify(
117
- parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
118
- ? {
119
- ...bounds,
120
- x: bounds.x + this.opts.bounds.x,
121
- y: bounds.y + this.opts.bounds.y,
122
- }
123
- : bounds
130
+ windowBounds
124
131
  )}`
125
132
  );
126
133
  const window: BrowserWindowRendererWindow = {
@@ -153,14 +160,7 @@ export default class BrowserWindowRenderer
153
160
  // we are rendering child windows with BrowserWindow. BrowserWindows are positioned absolutely so
154
161
  // to place them in the correct spot relative to their parent we need to add the main window's x / y.
155
162
  // BrowserViews are relatively positioned so we don't need to do that.
156
- bounds:
157
- parentWindowId && !this.opts.renderChildWindowsAsBrowserViews
158
- ? {
159
- ...bounds,
160
- x: bounds.x + this.opts.bounds.x,
161
- y: bounds.y + this.opts.bounds.y,
162
- }
163
- : bounds,
163
+ bounds: windowBounds,
164
164
 
165
165
  receiveMessageCallback: (
166
166
  _: IpcMainEvent,
@@ -222,6 +222,7 @@ export default class BrowserWindowRenderer
222
222
  }
223
223
 
224
224
  this.windows[windowId] = window;
225
+ this.windowsBounds[windowId] = lodash.cloneDeep(windowBounds);
225
226
  // Listen for messages from window.
226
227
  ipcMain.on(windowId, window.receiveMessageCallback);
227
228
 
@@ -356,7 +357,8 @@ export default class BrowserWindowRenderer
356
357
  `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow1`
357
358
  );
358
359
  const window = this.getWindow(windowId);
359
- if (!window) {
360
+ const windowBounds = this.getWindowBounds(windowId);
361
+ if (!window || !windowBounds) {
360
362
  throw new Error(`Failed to show window, missing window id '${windowId}'`);
361
363
  }
362
364
 
@@ -366,17 +368,19 @@ export default class BrowserWindowRenderer
366
368
  {
367
369
  fullscreen: window.view.isFullScreen(),
368
370
  bounds: window.view.getBounds(),
371
+ windowBounds: windowBounds,
369
372
  normalBounds: window.view.getNormalBounds(),
370
373
  contentBounds: window.view.getContentBounds(),
371
374
  }
372
375
  )}`
373
376
  );
374
- if (window.view.isFullScreen()) {
377
+ if (!areBoundsEqual(window.view.getBounds(), windowBounds)) {
375
378
  this.logger.info(
376
- `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: setFullScreen(true)`
379
+ `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: setWindowOrViewBounds`
377
380
  );
378
- window.view.setFullScreen(true);
381
+ this.setWindowOrViewBounds(window.view, windowBounds);
379
382
  }
383
+
380
384
  this.logger.info(
381
385
  `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow4: ${JSON.stringify(
382
386
  {
@@ -447,6 +451,7 @@ export default class BrowserWindowRenderer
447
451
  }
448
452
 
449
453
  delete this.windows[windowId];
454
+ delete this.windowsBounds[windowId];
450
455
 
451
456
  if (this.opts.useWindowPool) {
452
457
  this.logPoolStats();
@@ -532,27 +537,33 @@ export default class BrowserWindowRenderer
532
537
 
533
538
  // calling setBounds or setFullscreen may introduce -1px resolution error
534
539
  // so we try to avoid unnecessary calls
535
- if (
536
- areBoundsEqual(window.getBounds(), bounds) ||
537
- (isFullscreen(bounds) && window.isFullScreen())
538
- ) {
540
+ if (areBoundsEqual(window.getBounds(), bounds)) {
539
541
  this.logger.info(
540
542
  `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds3: bounds are equal`
541
543
  );
542
544
  return;
543
545
  }
544
546
 
545
- if (isFullscreen(bounds)) {
547
+ if (isFullscreen(bounds) !== window.isFullScreen()) {
546
548
  this.logger.info(
547
- `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: full screen`
549
+ `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: setFullScreen`
548
550
  );
549
- window.setFullScreen(true);
550
- } else {
551
- // setBounds will be ignored if window was in fullscreen mode
552
- window.setFullScreen(false);
553
- window.setBounds(bounds);
551
+ window.setFullScreen(isFullscreen(bounds));
554
552
  }
555
553
 
554
+ this.logger.info(
555
+ `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds5: before: ${JSON.stringify(
556
+ {
557
+ fullscreen: window.isFullScreen(),
558
+ bounds: window.getBounds(),
559
+ contentBounds: window.getContentBounds(),
560
+ normalBounds: window.getNormalBounds(),
561
+ }
562
+ )}`
563
+ );
564
+
565
+ window.setBounds(bounds);
566
+
556
567
  this.logger.info(
557
568
  `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds6: before: ${JSON.stringify(
558
569
  {
@@ -569,6 +580,10 @@ export default class BrowserWindowRenderer
569
580
  return this.windows[windowId];
570
581
  }
571
582
 
583
+ private getWindowBounds(windowId: string): WindowBounds | null {
584
+ return this.windowsBounds[windowId];
585
+ }
586
+
572
587
  private moveWindowOffscreen(window: BrowserWindowRendererWindow) {
573
588
  if (!(window.view instanceof BrowserView)) {
574
589
  throw new Error(