diff options
Diffstat (limited to 'packages/main/src/infrastructure/electron/impl')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronViewFactory.ts | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronViewFactory.ts b/packages/main/src/infrastructure/electron/impl/ElectronViewFactory.ts index 884643a..c72860d 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronViewFactory.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronViewFactory.ts | |||
@@ -18,15 +18,9 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { readFile } from 'node:fs/promises'; | ||
22 | |||
23 | import { ServiceToMainIpcMessage } from '@sophie/service-shared'; | ||
24 | import { ipcMain, WebSource } from 'electron'; | ||
25 | |||
26 | import type MainStore from '../../../stores/MainStore'; | 21 | import type MainStore from '../../../stores/MainStore'; |
27 | import type Profile from '../../../stores/Profile'; | 22 | import type Profile from '../../../stores/Profile'; |
28 | import type Service from '../../../stores/Service'; | 23 | import type Service from '../../../stores/Service'; |
29 | import { getLogger } from '../../../utils/log'; | ||
30 | import type Resources from '../../resources/Resources'; | 24 | import type Resources from '../../resources/Resources'; |
31 | import type UserAgents from '../UserAgents'; | 25 | import type UserAgents from '../UserAgents'; |
32 | import type { MainWindow, Partition, ServiceView, ViewFactory } from '../types'; | 26 | import type { MainWindow, Partition, ServiceView, ViewFactory } from '../types'; |
@@ -35,37 +29,17 @@ import ElectronMainWindow from './ElectronMainWindow'; | |||
35 | import ElectronPartition from './ElectronPartition'; | 29 | import ElectronPartition from './ElectronPartition'; |
36 | import ElectronServiceView from './ElectronServiceView'; | 30 | import ElectronServiceView from './ElectronServiceView'; |
37 | 31 | ||
38 | const log = getLogger('ElectronViewFactory'); | ||
39 | |||
40 | export default class ElectronViewFactory implements ViewFactory { | 32 | export default class ElectronViewFactory implements ViewFactory { |
41 | private readonly webContentsIdToServiceView = new Map< | 33 | private readonly webContentsIdToServiceView = new Map< |
42 | number, | 34 | number, |
43 | ElectronServiceView | 35 | ElectronServiceView |
44 | >(); | 36 | >(); |
45 | 37 | ||
46 | private serviceInjectSource: WebSource | undefined; | ||
47 | |||
48 | constructor( | 38 | constructor( |
49 | readonly userAgents: UserAgents, | 39 | readonly userAgents: UserAgents, |
50 | readonly resources: Resources, | 40 | readonly resources: Resources, |
51 | readonly devMode: boolean, | 41 | readonly devMode: boolean, |
52 | ) { | 42 | ) {} |
53 | ipcMain.handle(ServiceToMainIpcMessage.ApiExposedInMainWorld, (event) => { | ||
54 | if (!this.webContentsIdToServiceView.has(event.sender.id)) { | ||
55 | log.error( | ||
56 | 'Unexpected', | ||
57 | ServiceToMainIpcMessage.ApiExposedInMainWorld, | ||
58 | 'IPC message from webContents', | ||
59 | event.sender.id, | ||
60 | ); | ||
61 | throw new Error('Invalid IPC call'); | ||
62 | } | ||
63 | if (this.serviceInjectSource === undefined) { | ||
64 | log.error('Service inject source was not loaded'); | ||
65 | } | ||
66 | return this.serviceInjectSource; | ||
67 | }); | ||
68 | } | ||
69 | 43 | ||
70 | async createMainWindow(store: MainStore): Promise<MainWindow> { | 44 | async createMainWindow(store: MainStore): Promise<MainWindow> { |
71 | const mainWindow = new ElectronMainWindow(store, this); | 45 | const mainWindow = new ElectronMainWindow(store, this); |
@@ -94,23 +68,12 @@ export default class ElectronViewFactory implements ViewFactory { | |||
94 | throw new TypeError('Unexpected ProfileSession is not a WrappedSession'); | 68 | throw new TypeError('Unexpected ProfileSession is not a WrappedSession'); |
95 | } | 69 | } |
96 | 70 | ||
97 | async loadServiceInject(): Promise<void> { | ||
98 | const injectPackage = 'service-inject'; | ||
99 | const injectFile = 'index.js'; | ||
100 | const injectPath = this.resources.getPath(injectPackage, injectFile); | ||
101 | this.serviceInjectSource = { | ||
102 | code: await readFile(injectPath, 'utf8'), | ||
103 | url: this.resources.getFileURL(injectPackage, injectFile), | ||
104 | }; | ||
105 | } | ||
106 | |||
107 | dispose(): void { | 71 | dispose(): void { |
108 | if (this.webContentsIdToServiceView.size > 0) { | 72 | if (this.webContentsIdToServiceView.size > 0) { |
109 | throw new Error( | 73 | throw new Error( |
110 | 'Must dispose all ServiceView instances before disposing ViewFactory', | 74 | 'Must dispose all ServiceView instances before disposing ViewFactory', |
111 | ); | 75 | ); |
112 | } | 76 | } |
113 | ipcMain.removeHandler(ServiceToMainIpcMessage.ApiExposedInMainWorld); | ||
114 | } | 77 | } |
115 | 78 | ||
116 | unregisterServiceView(id: number): void { | 79 | unregisterServiceView(id: number): void { |