Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 68x 68x 68x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x | /** * This service manages multiple monitors or windows. */ export class MultiMonitorService { public readonly numberOfScreens: number; private windowsConfig; private screenConfig; private launchWindows = []; private basePath: string; public readonly screenNumber: number; public readonly isMultimonitor: boolean; public static readonly SOURCE_SCREEN = { id: 'source', // This is the primary screen, so don't launch is separately, but use primary launch: 'source', screen: null, location: { screen: null, width: 1, height: 1, left: 0, top: 0, }, }; public static REGISTRATION = { name: 'multiMonitorService', create: ({ configuration, commandsManager }): MultiMonitorService => { const service = new MultiMonitorService(configuration, commandsManager); return service; }, }; constructor(configuration, commandsManager) { const params = new URLSearchParams(window.location.search); const screenNumber = params.get('screenNumber'); const multimonitor = params.get('multimonitor'); const testParams = { params, screenNumber, multimonitor }; this.screenNumber = screenNumber ? Number(screenNumber) : -1; this.commandsManager = commandsManager; const windowAny = window as any; windowAny.multimonitor ||= { setLaunchWindows: this.setLaunchWindows, launchWindows: this.launchWindows, commandsManager, }; windowAny.multimonitor.commandsManager = commandsManager; this.launchWindows = (window as any).multimonitor?.launchWindows || this.launchWindows; Iif (this.screenNumber !== -1) { this.launchWindows[this.screenNumber] = window; } windowAny.commandsManager = (...args) => configuration.commandsManager; for (const windowsConfig of Array.isArray(configuration) ? configuration : []) { Iif (windowsConfig.test(testParams)) { this.isMultimonitor = true; this.numberOfScreens = windowsConfig.screens.length; this.windowsConfig = windowsConfig; if (this.screenNumber === -1 || this.screenNumber === null) { this.screenConfig = MultiMonitorService.SOURCE_SCREEN; } else { this.screenConfig = windowsConfig.screens[this.screenNumber]; Iif (!this.screenConfig) { throw new Error(`Screen ${screenNumber} not configured in ${this.windowsConfig}`); } window.name = this.screenConfig.id; } return; } this.numberOfScreens = 1; this.isMultimonitor = false; } } public async run(screenDelta = 1, commands, options) { const screenNumber = (this.screenNumber + (screenDelta ?? 1)) % this.numberOfScreens; const otherWindow = await this.getWindow(screenNumber); Iif (!otherWindow) { console.warn('No multimonitor found for screen', screenNumber, commands); return; } Iif (!otherWindow.multimonitor?.commandsManager) { console.warn("Didn't find a commands manager to run in the other window", otherWindow); return; } otherWindow.multimonitor.commandsManager.runAsync(commands, options); } /** Sets the launch windows for later use, shared amongst all windows. */ public setLaunchWindows = launchWindows => { this.launchWindows = launchWindows; (window as any).multimonitor.launchWindows = launchWindows; }; public async launchWindow(studyUid: string, screenDelta = 1, hashParams = '') { const forScreen = (this.screenNumber + screenDelta) % this.numberOfScreens; return this.getWindow(forScreen, studyUid ? `StudyInstanceUIDs=${studyUid}${hashParams}` : ''); } public async getWindow(screenNumber, hashParam?: string) { Iif (screenNumber === this.screenNumber) { return window; } Iif (this.launchWindows[screenNumber] && !this.launchWindows[screenNumber].closed) { return this.launchWindows[screenNumber]; } return await this.createWindow(screenNumber, hashParam); } /** * Creates a new window showing the given url by default, or gets an existing * window. */ public async createWindow(screenNumber, urlToUse?: string) { Iif (screenNumber === this.screenNumber) { return window; } const screenInfo = this.windowsConfig.screens[screenNumber]; const screenDetails = await window.getScreenDetails?.(); const screen = (screenInfo.screen >= 0 && screenDetails.screens[screenInfo.screen]) || screenDetails.currentScreen || window.screen; const { width = 1024, height = 1024, availLeft = 0, availTop = 0 } = screen || {}; const newScreen = this.windowsConfig.screens[screenNumber]; const { width: widthPercent = 1, height: heightPercent = 1, top: topPercent = 0, left: leftPercent = 0, } = newScreen.location || {}; const useLeft = Math.round(availLeft + leftPercent * width); const useTop = Math.round(availTop + topPercent * height); const useWidth = Math.round(width * widthPercent); const useHeight = Math.round(height * heightPercent); const baseFinalUrl = `${this.basePath}&screenNumber=${screenNumber}`; const finalUrl = urlToUse ? `${baseFinalUrl}#${urlToUse}` : baseFinalUrl; const newId = newScreen.id; const options = newScreen.options || ''; const position = `screenX=${useLeft},screenY=${useTop},width=${useWidth},height=${useHeight},${options}`; let newWindow = window.open('', newId, position); Iif (!newWindow?.location.href.startsWith(baseFinalUrl)) { newWindow = window.open(finalUrl, newId, position); } Iif (!newWindow) { console.warn('Unable to launch window', finalUrl, 'called', newId, 'at', position); return; } // Wait for the window to fully load await new Promise<void>(resolve => { if (newWindow.document.readyState === 'complete') { resolve(); } else { newWindow.addEventListener('load', () => resolve()); } }); this.launchWindows[screenNumber] = newWindow; return newWindow; } /** Launches all the windows using the initial configuration */ public launchAll() { for (let i = 0; i < this.numberOfScreens; i++) { this.createWindow(i); } } /** * Sets the base path to use for launching other windows, based on the * original base path without hash values in order to preserve consistent * URLs so that windows are refreshed on relaunch. */ public setBasePath() { const url = new URL(window.location.href); url.searchParams.delete('screenNumber'); url.searchParams.delete('protocolId'); url.searchParams.delete('launchAll'); url.searchParams.set('multimonitor', url.searchParams.get('multimonitor') || 'split'); url.hash = ''; this.basePath = url.toString(); } /** * Try moving the screen to the correct location - this will only work with * screens opened with openWindow containing no more than 1 tab. */ public async onModeEnter() { this.setBasePath(); Iif ( (this.isMultimonitor && this.screenNumber === -1) || window.location.href.toLowerCase().indexOf('launchall') !== -1 ) { this.launchAll(); } } } |