@raydiant/playlist-window-manager 0.0.0-test-19 → 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,20 +277,23 @@ 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
- window.view.maximize();
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);
289
295
  }
290
- this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: ".concat(JSON.stringify({
296
+ this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts showWindow4: ".concat(JSON.stringify({
291
297
  fullscreen: window.view.isFullScreen(),
292
298
  bounds: window.view.getBounds(),
293
299
  normalBounds: window.view.getNormalBounds(),
@@ -352,6 +358,7 @@ var BrowserWindowRenderer = /** @class */ (function () {
352
358
  _a.label = 4;
353
359
  case 4:
354
360
  delete this.windows[windowId];
361
+ delete this.windowsBounds[windowId];
355
362
  if (this.opts.useWindowPool) {
356
363
  this.logPoolStats();
357
364
  }
@@ -412,20 +419,21 @@ var BrowserWindowRenderer = /** @class */ (function () {
412
419
  })));
413
420
  // calling setBounds or setFullscreen may introduce -1px resolution error
414
421
  // so we try to avoid unnecessary calls
415
- if ((0, boundUtils_1.areBoundsEqual)(window.getBounds(), bounds) ||
416
- ((0, boundUtils_1.isFullscreen)(bounds) && window.isFullScreen())) {
422
+ if ((0, boundUtils_1.areBoundsEqual)(window.getBounds(), bounds)) {
417
423
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds3: bounds are equal");
418
424
  return;
419
425
  }
420
- if ((0, boundUtils_1.isFullscreen)(bounds)) {
421
- this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: full screen");
422
- window.setFullScreen(true);
423
- }
424
- else {
425
- // setBounds will be ignored if window was in fullscreen mode
426
- window.setFullScreen(false);
427
- 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));
428
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);
429
437
  this.logger.info("playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds6: before: ".concat(JSON.stringify({
430
438
  fullscreen: window.isFullScreen(),
431
439
  bounds: window.getBounds(),
@@ -436,6 +444,9 @@ var BrowserWindowRenderer = /** @class */ (function () {
436
444
  BrowserWindowRenderer.prototype.getWindow = function (windowId) {
437
445
  return this.windows[windowId];
438
446
  };
447
+ BrowserWindowRenderer.prototype.getWindowBounds = function (windowId) {
448
+ return this.windowsBounds[windowId];
449
+ };
439
450
  BrowserWindowRenderer.prototype.moveWindowOffscreen = function (window) {
440
451
  if (!(window.view instanceof electron_1.BrowserView)) {
441
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-19",
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,16 +368,21 @@ 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()) {
375
- window.view.maximize();
377
+ if (!areBoundsEqual(window.view.getBounds(), windowBounds)) {
378
+ this.logger.info(
379
+ `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: setWindowOrViewBounds`
380
+ );
381
+ this.setWindowOrViewBounds(window.view, windowBounds);
376
382
  }
383
+
377
384
  this.logger.info(
378
- `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow3: ${JSON.stringify(
385
+ `playlist-window-manager/src/BrowserWindowRenderer.ts showWindow4: ${JSON.stringify(
379
386
  {
380
387
  fullscreen: window.view.isFullScreen(),
381
388
  bounds: window.view.getBounds(),
@@ -444,6 +451,7 @@ export default class BrowserWindowRenderer
444
451
  }
445
452
 
446
453
  delete this.windows[windowId];
454
+ delete this.windowsBounds[windowId];
447
455
 
448
456
  if (this.opts.useWindowPool) {
449
457
  this.logPoolStats();
@@ -529,27 +537,33 @@ export default class BrowserWindowRenderer
529
537
 
530
538
  // calling setBounds or setFullscreen may introduce -1px resolution error
531
539
  // so we try to avoid unnecessary calls
532
- if (
533
- areBoundsEqual(window.getBounds(), bounds) ||
534
- (isFullscreen(bounds) && window.isFullScreen())
535
- ) {
540
+ if (areBoundsEqual(window.getBounds(), bounds)) {
536
541
  this.logger.info(
537
542
  `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds3: bounds are equal`
538
543
  );
539
544
  return;
540
545
  }
541
546
 
542
- if (isFullscreen(bounds)) {
547
+ if (isFullscreen(bounds) !== window.isFullScreen()) {
543
548
  this.logger.info(
544
- `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: full screen`
549
+ `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds4: setFullScreen`
545
550
  );
546
- window.setFullScreen(true);
547
- } else {
548
- // setBounds will be ignored if window was in fullscreen mode
549
- window.setFullScreen(false);
550
- window.setBounds(bounds);
551
+ window.setFullScreen(isFullscreen(bounds));
551
552
  }
552
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
+
553
567
  this.logger.info(
554
568
  `playlist-window-manager/src/BrowserWindowRenderer.ts setWindowOrViewBounds6: before: ${JSON.stringify(
555
569
  {
@@ -566,6 +580,10 @@ export default class BrowserWindowRenderer
566
580
  return this.windows[windowId];
567
581
  }
568
582
 
583
+ private getWindowBounds(windowId: string): WindowBounds | null {
584
+ return this.windowsBounds[windowId];
585
+ }
586
+
569
587
  private moveWindowOffscreen(window: BrowserWindowRendererWindow) {
570
588
  if (!(window.view instanceof BrowserView)) {
571
589
  throw new Error(