"post-init").then(() => { bootstrap.dispatch(loadDevices()).then(() => { bootstrap.dispatch(restoreDeviceState()); }); }); window.destroy = () => bootstrap.destroy(); // Allows quick testing of actions from the console window.dispatch = action => bootstrap.dispatch(action); // Expose the store on window for testing Object.defineProperty(window, "store", { get: () => bootstrap.store, enumerable: true, }); // Dispatch a `changeDisplayPixelRatio` action when the browser's pixel ratio is changing. // This is usually triggered when the user changes the monitor resolution, or when the // browser's window is dragged to a different display with a different pixel ratio. // TODO: It would be better to move this watching into the actor, so that it can be // better synchronized with any overrides that might be applied. Also, reading a single // value like this makes less sense with multiple viewports. function onDevicePixelRatioChange() { const dpr = window.devicePixelRatio; const mql = window.matchMedia(`(resolution: ${dpr}dppx)`); function listener() { bootstrap.dispatch(changeDisplayPixelRatio(window.devicePixelRatio)); mql.removeListener(listener); onDevicePixelRatioChange(); } mql.addListener(listener); } /** * Called by manager.js to add the initial viewport based on the original page. */ window.addInitialViewport = ({ userContextId }) => { try { onDevicePixelRatioChange(); bootstrap.dispatch(changeDisplayPixelRatio(window.devicePixelRatio)); bootstrap.dispatch(addViewport(userContextId)); } catch (e) { console.error(e); } }; window.getAssociatedDevice = () => { const { viewports } = bootstrap.store.getState(); if (!viewports.length) { return null; } return viewports[0].device; }; /** * Called by manager.js when tests want to check the viewport size. */ window.getViewportSize = () => { const { viewports } = bootstrap.store.getState(); if (!viewports.length) { return null; } const { width, height } = viewports[0]; return { width, height }; }; /** * Called by manager.js to set viewport size from tests, etc. */ window.setViewportSize = ({ width, height }) => { try { bootstrap.dispatch(resizeViewport(0, width, height)); } catch (e) { console.error(e); } }; window.clearDeviceAssociation = () => { try { bootstrap.dispatch(removeDeviceAssociation(0)); } catch (e) { console.error(e); } }; /** * Called by manager.js to access the viewport's browser, either for testing * purposes or to reload it when touch simulation is enabled. * A messageManager getter is added on the object to provide an easy access * to the message manager without pulling the frame loader. */ window.getViewportBrowser = () => { const browser = document.querySelector("iframe.browser"); if (browser && !browser.messageManager) { Object.defineProperty(browser, "messageManager", { get() { return this.frameLoader.messageManager; }, configurable: true, enumerable: true, }); } return browser; }; /** * Called by manager.js to zoom the viewport. */ window.setViewportZoom = zoom => { try { bootstrap.dispatch(zoomViewport(0, zoom)); } catch (e) { console.error(e); } }; PK