diff options
Diffstat (limited to 'packages/shared')
-rw-r--r-- | packages/shared/src/index.ts | 21 | ||||
-rw-r--r-- | packages/shared/src/schemas.ts | 44 | ||||
-rw-r--r-- | packages/shared/src/stores/GlobalSettings.ts | 18 | ||||
-rw-r--r-- | packages/shared/src/stores/Profile.ts | 14 | ||||
-rw-r--r-- | packages/shared/src/stores/ProfileSettings.ts | 14 | ||||
-rw-r--r-- | packages/shared/src/stores/Service.ts | 14 | ||||
-rw-r--r-- | packages/shared/src/stores/ServiceSettings.ts | 18 | ||||
-rw-r--r-- | packages/shared/src/stores/SharedStore.ts | 34 |
8 files changed, 109 insertions, 68 deletions
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 55cf5ce..3d30488 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts | |||
@@ -22,40 +22,33 @@ export type { default as SophieRenderer } from './contextBridge/SophieRenderer'; | |||
22 | 22 | ||
23 | export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc'; | 23 | export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc'; |
24 | 24 | ||
25 | export type { Action, BrowserViewBounds, ThemeSource } from './schemas'; | 25 | export { Action, BrowserViewBounds, ThemeSource } from './schemas'; |
26 | export { action, browserViewBounds, themeSource } from './schemas'; | ||
27 | 26 | ||
28 | export type { | 27 | export type { |
29 | GlobalSettings, | ||
30 | GlobalSettingsSnapshotIn, | 28 | GlobalSettingsSnapshotIn, |
31 | GlobalSettingsSnapshotOut, | 29 | GlobalSettingsSnapshotOut, |
32 | } from './stores/GlobalSettings'; | 30 | } from './stores/GlobalSettings'; |
33 | export { globalSettings } from './stores/GlobalSettings'; | 31 | export { default as GlobalSettings } from './stores/GlobalSettings'; |
34 | 32 | ||
35 | export type { Profile } from './stores/Profile'; | 33 | export { default as Profile } from './stores/Profile'; |
36 | export { profile } from './stores/Profile'; | ||
37 | 34 | ||
38 | export type { | 35 | export type { |
39 | ProfileSettings, | ||
40 | ProfileSettingsSnapshotIn, | 36 | ProfileSettingsSnapshotIn, |
41 | ProfileSettingsSnapshotOut, | 37 | ProfileSettingsSnapshotOut, |
42 | } from './stores/ProfileSettings'; | 38 | } from './stores/ProfileSettings'; |
43 | export { profileSettings } from './stores/ProfileSettings'; | 39 | export { default as ProfileSettings } from './stores/ProfileSettings'; |
44 | 40 | ||
45 | export type { Service } from './stores/Service'; | 41 | export { default as Service } from './stores/Service'; |
46 | export { service } from './stores/Service'; | ||
47 | 42 | ||
48 | export type { | 43 | export type { |
49 | ServiceSettings, | ||
50 | ServiceSettingsSnapshotIn, | 44 | ServiceSettingsSnapshotIn, |
51 | ServiceSettingsSnapshotOut, | 45 | ServiceSettingsSnapshotOut, |
52 | } from './stores/ServiceSettings'; | 46 | } from './stores/ServiceSettings'; |
53 | export { serviceSettings } from './stores/ServiceSettings'; | 47 | export { default as ServiceSettings } from './stores/ServiceSettings'; |
54 | 48 | ||
55 | export type { | 49 | export type { |
56 | SharedStore, | ||
57 | SharedStoreListener, | 50 | SharedStoreListener, |
58 | SharedStoreSnapshotIn, | 51 | SharedStoreSnapshotIn, |
59 | SharedStoreSnapshotOut, | 52 | SharedStoreSnapshotOut, |
60 | } from './stores/SharedStore'; | 53 | } from './stores/SharedStore'; |
61 | export { sharedStore } from './stores/SharedStore'; | 54 | export { default as SharedStore } from './stores/SharedStore'; |
diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts index 7fb9717..edf3741 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas.ts | |||
@@ -20,43 +20,55 @@ | |||
20 | 20 | ||
21 | import { z } from 'zod'; | 21 | import { z } from 'zod'; |
22 | 22 | ||
23 | const setSelectedServiceId = z.object({ | 23 | const SetSelectedServiceId = z.object({ |
24 | action: z.literal('set-selected-service-id'), | 24 | action: z.literal('set-selected-service-id'), |
25 | serviceId: z.string(), | 25 | serviceId: z.string(), |
26 | }); | 26 | }); |
27 | 27 | ||
28 | export const browserViewBounds = z.object({ | 28 | export const BrowserViewBounds = z.object({ |
29 | x: z.number().int().nonnegative(), | 29 | x: z.number().int().nonnegative(), |
30 | y: z.number().int().nonnegative(), | 30 | y: z.number().int().nonnegative(), |
31 | width: z.number().int().nonnegative(), | 31 | width: z.number().int().nonnegative(), |
32 | height: z.number().int().nonnegative(), | 32 | height: z.number().int().nonnegative(), |
33 | }); | 33 | }); |
34 | 34 | ||
35 | export type BrowserViewBounds = z.infer<typeof browserViewBounds>; | 35 | /* |
36 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
37 | Intentionally naming the type the same as the schema definition. | ||
38 | */ | ||
39 | export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; | ||
36 | 40 | ||
37 | const setBrowserViewBoundsAction = z.object({ | 41 | const SetBrowserViewBoundsAction = z.object({ |
38 | action: z.literal('set-browser-view-bounds'), | 42 | action: z.literal('set-browser-view-bounds'), |
39 | browserViewBounds, | 43 | browserViewBounds: BrowserViewBounds, |
40 | }); | 44 | }); |
41 | 45 | ||
42 | export const themeSource = z.enum(['system', 'light', 'dark']); | 46 | export const ThemeSource = z.enum(['system', 'light', 'dark']); |
43 | 47 | ||
44 | export type ThemeSource = z.infer<typeof themeSource>; | 48 | /* |
49 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
50 | Intentionally naming the type the same as the schema definition. | ||
51 | */ | ||
52 | export type ThemeSource = z.infer<typeof ThemeSource>; | ||
45 | 53 | ||
46 | const setThemeSourceAction = z.object({ | 54 | const SetThemeSourceAction = z.object({ |
47 | action: z.literal('set-theme-source'), | 55 | action: z.literal('set-theme-source'), |
48 | themeSource, | 56 | themeSource: ThemeSource, |
49 | }); | 57 | }); |
50 | 58 | ||
51 | const reloadAllServicesAction = z.object({ | 59 | const ReloadAllServicesAction = z.object({ |
52 | action: z.literal('reload-all-services'), | 60 | action: z.literal('reload-all-services'), |
53 | }); | 61 | }); |
54 | 62 | ||
55 | export const action = z.union([ | 63 | export const Action = z.union([ |
56 | setSelectedServiceId, | 64 | SetSelectedServiceId, |
57 | setBrowserViewBoundsAction, | 65 | SetBrowserViewBoundsAction, |
58 | setThemeSourceAction, | 66 | SetThemeSourceAction, |
59 | reloadAllServicesAction, | 67 | ReloadAllServicesAction, |
60 | ]); | 68 | ]); |
61 | 69 | ||
62 | export type Action = z.infer<typeof action>; | 70 | /* |
71 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
72 | Intentionally naming the type the same as the schema definition. | ||
73 | */ | ||
74 | export type Action = z.infer<typeof Action>; | ||
diff --git a/packages/shared/src/stores/GlobalSettings.ts b/packages/shared/src/stores/GlobalSettings.ts index bd0155a..3a813b8 100644 --- a/packages/shared/src/stores/GlobalSettings.ts +++ b/packages/shared/src/stores/GlobalSettings.ts | |||
@@ -20,16 +20,22 @@ | |||
20 | 20 | ||
21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | 21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; |
22 | 22 | ||
23 | import { themeSource } from '../schemas'; | 23 | import { ThemeSource } from '../schemas'; |
24 | 24 | ||
25 | export const globalSettings = types.model('GlobalSettings', { | 25 | const GlobalSettings = types.model('GlobalSettings', { |
26 | themeSource: types.optional(types.enumeration(themeSource.options), 'system'), | 26 | themeSource: types.optional(types.enumeration(ThemeSource.options), 'system'), |
27 | }); | 27 | }); |
28 | 28 | ||
29 | export interface GlobalSettings extends Instance<typeof globalSettings> {} | 29 | /* |
30 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
31 | Intentionally naming the type the same as the store definition. | ||
32 | */ | ||
33 | interface GlobalSettings extends Instance<typeof GlobalSettings> {} | ||
34 | |||
35 | export default GlobalSettings; | ||
30 | 36 | ||
31 | export interface GlobalSettingsSnapshotIn | 37 | export interface GlobalSettingsSnapshotIn |
32 | extends SnapshotIn<typeof globalSettings> {} | 38 | extends SnapshotIn<typeof GlobalSettings> {} |
33 | 39 | ||
34 | export interface GlobalSettingsSnapshotOut | 40 | export interface GlobalSettingsSnapshotOut |
35 | extends SnapshotOut<typeof globalSettings> {} | 41 | extends SnapshotOut<typeof GlobalSettings> {} |
diff --git a/packages/shared/src/stores/Profile.ts b/packages/shared/src/stores/Profile.ts index bb058f6..256c33e 100644 --- a/packages/shared/src/stores/Profile.ts +++ b/packages/shared/src/stores/Profile.ts | |||
@@ -20,11 +20,17 @@ | |||
20 | 20 | ||
21 | import { Instance, types } from 'mobx-state-tree'; | 21 | import { Instance, types } from 'mobx-state-tree'; |
22 | 22 | ||
23 | import { profileSettings } from './ProfileSettings'; | 23 | import ProfileSettings from './ProfileSettings'; |
24 | 24 | ||
25 | export const profile = types.model('Profile', { | 25 | const Profile = types.model('Profile', { |
26 | id: types.identifier, | 26 | id: types.identifier, |
27 | settings: profileSettings, | 27 | settings: ProfileSettings, |
28 | }); | 28 | }); |
29 | 29 | ||
30 | export interface Profile extends Instance<typeof profile> {} | 30 | /* |
31 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
32 | Intentionally naming the type the same as the store definition. | ||
33 | */ | ||
34 | interface Profile extends Instance<typeof Profile> {} | ||
35 | |||
36 | export default Profile; | ||
diff --git a/packages/shared/src/stores/ProfileSettings.ts b/packages/shared/src/stores/ProfileSettings.ts index ec8da5f..9f2b27c 100644 --- a/packages/shared/src/stores/ProfileSettings.ts +++ b/packages/shared/src/stores/ProfileSettings.ts | |||
@@ -20,14 +20,20 @@ | |||
20 | 20 | ||
21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | 21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; |
22 | 22 | ||
23 | export const profileSettings = types.model('ProfileSettings', { | 23 | const ProfileSettings = types.model('ProfileSettings', { |
24 | name: types.string, | 24 | name: types.string, |
25 | }); | 25 | }); |
26 | 26 | ||
27 | export interface ProfileSettings extends Instance<typeof profileSettings> {} | 27 | /* |
28 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
29 | Intentionally naming the type the same as the store definition. | ||
30 | */ | ||
31 | interface ProfileSettings extends Instance<typeof ProfileSettings> {} | ||
32 | |||
33 | export default ProfileSettings; | ||
28 | 34 | ||
29 | export interface ProfileSettingsSnapshotIn | 35 | export interface ProfileSettingsSnapshotIn |
30 | extends SnapshotIn<typeof profileSettings> {} | 36 | extends SnapshotIn<typeof ProfileSettings> {} |
31 | 37 | ||
32 | export interface ProfileSettingsSnapshotOut | 38 | export interface ProfileSettingsSnapshotOut |
33 | extends SnapshotOut<typeof profileSettings> {} | 39 | extends SnapshotOut<typeof ProfileSettings> {} |
diff --git a/packages/shared/src/stores/Service.ts b/packages/shared/src/stores/Service.ts index 36acd3d..4a7334d 100644 --- a/packages/shared/src/stores/Service.ts +++ b/packages/shared/src/stores/Service.ts | |||
@@ -20,11 +20,11 @@ | |||
20 | 20 | ||
21 | import { Instance, types } from 'mobx-state-tree'; | 21 | import { Instance, types } from 'mobx-state-tree'; |
22 | 22 | ||
23 | import { serviceSettings } from './ServiceSettings'; | 23 | import ServiceSettings from './ServiceSettings'; |
24 | 24 | ||
25 | export const service = types.model('Service', { | 25 | const Service = types.model('Service', { |
26 | id: types.identifier, | 26 | id: types.identifier, |
27 | settings: serviceSettings, | 27 | settings: ServiceSettings, |
28 | currentUrl: types.maybe(types.string), | 28 | currentUrl: types.maybe(types.string), |
29 | canGoBack: false, | 29 | canGoBack: false, |
30 | canGoForward: false, | 30 | canGoForward: false, |
@@ -37,4 +37,10 @@ export const service = types.model('Service', { | |||
37 | indirectMessageCount: 0, | 37 | indirectMessageCount: 0, |
38 | }); | 38 | }); |
39 | 39 | ||
40 | export interface Service extends Instance<typeof service> {} | 40 | /* |
41 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
42 | Intentionally naming the type the same as the store definition. | ||
43 | */ | ||
44 | interface Service extends Instance<typeof Service> {} | ||
45 | |||
46 | export default Service; | ||
diff --git a/packages/shared/src/stores/ServiceSettings.ts b/packages/shared/src/stores/ServiceSettings.ts index 54cd7eb..6ba1dfa 100644 --- a/packages/shared/src/stores/ServiceSettings.ts +++ b/packages/shared/src/stores/ServiceSettings.ts | |||
@@ -20,19 +20,25 @@ | |||
20 | 20 | ||
21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | 21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; |
22 | 22 | ||
23 | import { profile } from './Profile'; | 23 | import Profile from './Profile'; |
24 | 24 | ||
25 | export const serviceSettings = types.model('ServiceSettings', { | 25 | const ServiceSettings = types.model('ServiceSettings', { |
26 | name: types.string, | 26 | name: types.string, |
27 | profile: types.reference(profile), | 27 | profile: types.reference(Profile), |
28 | // TODO: Remove this once recipes are added. | 28 | // TODO: Remove this once recipes are added. |
29 | url: types.string, | 29 | url: types.string, |
30 | }); | 30 | }); |
31 | 31 | ||
32 | export interface ServiceSettings extends Instance<typeof serviceSettings> {} | 32 | /* |
33 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
34 | Intentionally naming the type the same as the store definition. | ||
35 | */ | ||
36 | interface ServiceSettings extends Instance<typeof ServiceSettings> {} | ||
37 | |||
38 | export default ServiceSettings; | ||
33 | 39 | ||
34 | export interface ServiceSettingsSnapshotIn | 40 | export interface ServiceSettingsSnapshotIn |
35 | extends SnapshotIn<typeof serviceSettings> {} | 41 | extends SnapshotIn<typeof ServiceSettings> {} |
36 | 42 | ||
37 | export interface ServiceSettingsSnapshotOut | 43 | export interface ServiceSettingsSnapshotOut |
38 | extends SnapshotOut<typeof serviceSettings> {} | 44 | extends SnapshotOut<typeof ServiceSettings> {} |
diff --git a/packages/shared/src/stores/SharedStore.ts b/packages/shared/src/stores/SharedStore.ts index f301b9d..0cac3a5 100644 --- a/packages/shared/src/stores/SharedStore.ts +++ b/packages/shared/src/stores/SharedStore.ts | |||
@@ -26,26 +26,32 @@ import { | |||
26 | SnapshotOut, | 26 | SnapshotOut, |
27 | } from 'mobx-state-tree'; | 27 | } from 'mobx-state-tree'; |
28 | 28 | ||
29 | import { globalSettings } from './GlobalSettings'; | 29 | import GlobalSettings from './GlobalSettings'; |
30 | import { profile } from './Profile'; | 30 | import Profile from './Profile'; |
31 | import { service } from './Service'; | 31 | import Service from './Service'; |
32 | 32 | ||
33 | export const sharedStore = types.model('SharedStore', { | 33 | const SharedStore = types.model('SharedStore', { |
34 | settings: types.optional(globalSettings, {}), | 34 | settings: types.optional(GlobalSettings, {}), |
35 | profilesById: types.map(profile), | 35 | profilesById: types.map(Profile), |
36 | profiles: types.array(types.reference(profile)), | 36 | profiles: types.array(types.reference(Profile)), |
37 | servicesById: types.map(service), | 37 | servicesById: types.map(Service), |
38 | services: types.array(types.reference(service)), | 38 | services: types.array(types.reference(Service)), |
39 | selectedService: types.safeReference(service), | 39 | selectedService: types.safeReference(Service), |
40 | shouldUseDarkColors: false, | 40 | shouldUseDarkColors: false, |
41 | }); | 41 | }); |
42 | 42 | ||
43 | export interface SharedStore extends Instance<typeof sharedStore> {} | 43 | /* |
44 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
45 | Intentionally naming the type the same as the store definition. | ||
46 | */ | ||
47 | interface SharedStore extends Instance<typeof SharedStore> {} | ||
48 | |||
49 | export default SharedStore; | ||
44 | 50 | ||
45 | export interface SharedStoreSnapshotIn extends SnapshotIn<typeof sharedStore> {} | 51 | export interface SharedStoreSnapshotIn extends SnapshotIn<typeof SharedStore> {} |
46 | 52 | ||
47 | export interface SharedStoreSnapshotOut | 53 | export interface SharedStoreSnapshotOut |
48 | extends SnapshotOut<typeof sharedStore> {} | 54 | extends SnapshotOut<typeof SharedStore> {} |
49 | 55 | ||
50 | export interface SharedStoreListener { | 56 | export interface SharedStoreListener { |
51 | onSnapshot(snapshot: SharedStoreSnapshotIn): void; | 57 | onSnapshot(snapshot: SharedStoreSnapshotIn): void; |