diff options
author | 2022-02-08 21:40:40 +0100 | |
---|---|---|
committer | 2022-02-14 12:13:22 +0100 | |
commit | cc214bb1afd37068c2bbc93f33990ca93f9a900f (patch) | |
tree | 7707415d5c4e42b2542d3f482060d4935c892fe1 /packages/main/src/infrastructure/electron/impl/ElectronPartition.ts | |
parent | feat: Unread message badges (diff) | |
download | sophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.tar.gz sophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.tar.zst sophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.zip |
feat: Load and switch services
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/infrastructure/electron/impl/ElectronPartition.ts')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronPartition.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronPartition.ts b/packages/main/src/infrastructure/electron/impl/ElectronPartition.ts new file mode 100644 index 0000000..e60ce21 --- /dev/null +++ b/packages/main/src/infrastructure/electron/impl/ElectronPartition.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import { Session, session } from 'electron'; | ||
22 | |||
23 | import type Profile from '../../../stores/Profile'; | ||
24 | import type { Partition } from '../types'; | ||
25 | |||
26 | import type ElectronViewFactory from './ElectronViewFactory'; | ||
27 | |||
28 | export default class ElectronPartition implements Partition { | ||
29 | readonly id: string; | ||
30 | |||
31 | readonly session: Session; | ||
32 | |||
33 | constructor(profile: Profile, parent: ElectronViewFactory) { | ||
34 | this.id = profile.id; | ||
35 | this.session = session.fromPartition(`persist:${profile.id}`); | ||
36 | this.session.setPermissionRequestHandler( | ||
37 | (_webContents, permission, callback) => { | ||
38 | // TODO Handle screen sharing. | ||
39 | callback(permission === 'notifications'); | ||
40 | }, | ||
41 | ); | ||
42 | this.session.setUserAgent(parent.userAgents.serviceUserAgent()); | ||
43 | this.session.webRequest.onBeforeSendHeaders( | ||
44 | ({ url, requestHeaders }, callback) => { | ||
45 | callback({ | ||
46 | requestHeaders: { | ||
47 | ...requestHeaders, | ||
48 | 'User-Agent': parent.userAgents.serviceUserAgent(url), | ||
49 | }, | ||
50 | }); | ||
51 | }, | ||
52 | ); | ||
53 | } | ||
54 | |||
55 | // eslint-disable-next-line class-methods-use-this -- Implementing interface method. | ||
56 | dispose(): void { | ||
57 | // No reactions to dispose yet. | ||
58 | } | ||
59 | } | ||