diff options
Diffstat (limited to 'packages/main')
-rw-r--r-- | packages/main/src/stores/Profile.ts | 43 | ||||
-rw-r--r-- | packages/main/src/stores/Service.ts | 5 |
2 files changed, 36 insertions, 12 deletions
diff --git a/packages/main/src/stores/Profile.ts b/packages/main/src/stores/Profile.ts index b4343a0..73f4f0b 100644 --- a/packages/main/src/stores/Profile.ts +++ b/packages/main/src/stores/Profile.ts | |||
@@ -18,21 +18,40 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { Certificate, Profile as ProfileBase } from '@sophie/shared'; | 21 | import { |
22 | import { clone, getSnapshot, Instance } from 'mobx-state-tree'; | 22 | type Certificate, |
23 | type CertificateSnapshotIn, | ||
24 | Profile as ProfileBase, | ||
25 | } from '@sophie/shared'; | ||
26 | import { getSnapshot, type Instance } from 'mobx-state-tree'; | ||
23 | 27 | ||
24 | import type ProfileConfig from './config/ProfileConfig.js'; | 28 | import type ProfileConfig from './config/ProfileConfig.js'; |
25 | 29 | ||
26 | const Profile = ProfileBase.views((self) => ({ | 30 | const Profile = ProfileBase.volatile( |
27 | get config(): ProfileConfig { | 31 | (): { |
28 | const { id, settings } = self; | 32 | temporarilyTrustedCertificates: string[]; |
29 | return { ...getSnapshot(settings), id }; | 33 | } => ({ |
30 | }, | 34 | temporarilyTrustedCertificates: [], |
31 | })).actions((self) => ({ | 35 | }), |
32 | temporarilyTrustCertificate(certificate: Certificate): void { | 36 | ) |
33 | self.temporarilyTrustedCertificates.push(clone(certificate)); | 37 | .views((self) => ({ |
34 | }, | 38 | get config(): ProfileConfig { |
35 | })); | 39 | const { id, settings } = self; |
40 | return { ...getSnapshot(settings), id }; | ||
41 | }, | ||
42 | isCertificateTemporarilyTrusted( | ||
43 | certificate: CertificateSnapshotIn, | ||
44 | ): boolean { | ||
45 | return self.temporarilyTrustedCertificates.includes( | ||
46 | certificate.fingerprint, | ||
47 | ); | ||
48 | }, | ||
49 | })) | ||
50 | .actions((self) => ({ | ||
51 | temporarilyTrustCertificate(certificate: Certificate): void { | ||
52 | self.temporarilyTrustedCertificates.push(certificate.fingerprint); | ||
53 | }, | ||
54 | })); | ||
36 | 55 | ||
37 | /* | 56 | /* |
38 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 57 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/main/src/stores/Service.ts b/packages/main/src/stores/Service.ts index 3b7d0b2..d062fe1 100644 --- a/packages/main/src/stores/Service.ts +++ b/packages/main/src/stores/Service.ts | |||
@@ -67,6 +67,11 @@ const Service = defineServiceModel(ServiceSettings) | |||
67 | get shouldBeLoaded(): boolean { | 67 | get shouldBeLoaded(): boolean { |
68 | return !self.crashed; | 68 | return !self.crashed; |
69 | }, | 69 | }, |
70 | isCertificateTemporarilyTrusted( | ||
71 | certificate: CertificateSnapshotIn, | ||
72 | ): boolean { | ||
73 | return self.settings.profile.isCertificateTemporarilyTrusted(certificate); | ||
74 | }, | ||
70 | })) | 75 | })) |
71 | .views((self) => ({ | 76 | .views((self) => ({ |
72 | get shouldBeVisible(): boolean { | 77 | get shouldBeVisible(): boolean { |