From 32f986afcfb5bbc932a65fc2721528e626706836 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 9 Nov 2020 16:06:03 -0500 Subject: [PATCH] chore: lookup window indirectly --- ui/desktop/app/services/ipc.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ui/desktop/app/services/ipc.js b/ui/desktop/app/services/ipc.js index 21c9c2c43..af6982d87 100644 --- a/ui/desktop/app/services/ipc.js +++ b/ui/desktop/app/services/ipc.js @@ -1,4 +1,5 @@ import Service from '@ember/service'; +import { getOwner } from '@ember/application'; import { Promise } from 'rsvp'; /** @@ -35,9 +36,10 @@ class IPCRequest { * resolves to the response. * @param {string} method * @param {object} payload + * @param {Window} window - A reference to the window object * @param {?string} origin */ - constructor(method, payload, origin='serve://boundary') { + constructor(method, payload, window, origin='serve://boundary') { this.method = method; this.payload = payload; this.origin = origin; @@ -101,6 +103,19 @@ class IPCRequest { */ export default class IpcService extends Service { + // =attributes + + /** + * Looks up the window object indirectly. + * @type {Window} + */ + get window() { + // The Ember way of accessing globals... + const document = getOwner(this).lookup('service:-document').documentElement; + // defaultView === window, but without using globals directly + return document.parentNode.defaultView; + } + // =methods /** @@ -110,7 +125,7 @@ export default class IpcService extends Service { * @return {IPCRequest} */ invoke(method, payload) { - return new IPCRequest(method, payload); + return new IPCRequest(method, payload, this.window); } }