diff options
Diffstat (limited to 'packages/main/src/stores/Profile.ts')
-rw-r--r-- | packages/main/src/stores/Profile.ts | 43 |
1 files changed, 31 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 -- |