aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/src/index.ts21
-rw-r--r--packages/shared/src/schemas.ts44
-rw-r--r--packages/shared/src/stores/GlobalSettings.ts18
-rw-r--r--packages/shared/src/stores/Profile.ts14
-rw-r--r--packages/shared/src/stores/ProfileSettings.ts14
-rw-r--r--packages/shared/src/stores/Service.ts14
-rw-r--r--packages/shared/src/stores/ServiceSettings.ts18
-rw-r--r--packages/shared/src/stores/SharedStore.ts34
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
23export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc'; 23export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc';
24 24
25export type { Action, BrowserViewBounds, ThemeSource } from './schemas'; 25export { Action, BrowserViewBounds, ThemeSource } from './schemas';
26export { action, browserViewBounds, themeSource } from './schemas';
27 26
28export type { 27export type {
29 GlobalSettings,
30 GlobalSettingsSnapshotIn, 28 GlobalSettingsSnapshotIn,
31 GlobalSettingsSnapshotOut, 29 GlobalSettingsSnapshotOut,
32} from './stores/GlobalSettings'; 30} from './stores/GlobalSettings';
33export { globalSettings } from './stores/GlobalSettings'; 31export { default as GlobalSettings } from './stores/GlobalSettings';
34 32
35export type { Profile } from './stores/Profile'; 33export { default as Profile } from './stores/Profile';
36export { profile } from './stores/Profile';
37 34
38export type { 35export type {
39 ProfileSettings,
40 ProfileSettingsSnapshotIn, 36 ProfileSettingsSnapshotIn,
41 ProfileSettingsSnapshotOut, 37 ProfileSettingsSnapshotOut,
42} from './stores/ProfileSettings'; 38} from './stores/ProfileSettings';
43export { profileSettings } from './stores/ProfileSettings'; 39export { default as ProfileSettings } from './stores/ProfileSettings';
44 40
45export type { Service } from './stores/Service'; 41export { default as Service } from './stores/Service';
46export { service } from './stores/Service';
47 42
48export type { 43export type {
49 ServiceSettings,
50 ServiceSettingsSnapshotIn, 44 ServiceSettingsSnapshotIn,
51 ServiceSettingsSnapshotOut, 45 ServiceSettingsSnapshotOut,
52} from './stores/ServiceSettings'; 46} from './stores/ServiceSettings';
53export { serviceSettings } from './stores/ServiceSettings'; 47export { default as ServiceSettings } from './stores/ServiceSettings';
54 48
55export type { 49export type {
56 SharedStore,
57 SharedStoreListener, 50 SharedStoreListener,
58 SharedStoreSnapshotIn, 51 SharedStoreSnapshotIn,
59 SharedStoreSnapshotOut, 52 SharedStoreSnapshotOut,
60} from './stores/SharedStore'; 53} from './stores/SharedStore';
61export { sharedStore } from './stores/SharedStore'; 54export { 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
21import { z } from 'zod'; 21import { z } from 'zod';
22 22
23const setSelectedServiceId = z.object({ 23const 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
28export const browserViewBounds = z.object({ 28export 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
35export 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*/
39export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>;
36 40
37const setBrowserViewBoundsAction = z.object({ 41const 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
42export const themeSource = z.enum(['system', 'light', 'dark']); 46export const ThemeSource = z.enum(['system', 'light', 'dark']);
43 47
44export 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*/
52export type ThemeSource = z.infer<typeof ThemeSource>;
45 53
46const setThemeSourceAction = z.object({ 54const 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
51const reloadAllServicesAction = z.object({ 59const ReloadAllServicesAction = z.object({
52 action: z.literal('reload-all-services'), 60 action: z.literal('reload-all-services'),
53}); 61});
54 62
55export const action = z.union([ 63export const Action = z.union([
56 setSelectedServiceId, 64 SetSelectedServiceId,
57 setBrowserViewBoundsAction, 65 SetBrowserViewBoundsAction,
58 setThemeSourceAction, 66 SetThemeSourceAction,
59 reloadAllServicesAction, 67 ReloadAllServicesAction,
60]); 68]);
61 69
62export 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*/
74export 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
21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; 21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree';
22 22
23import { themeSource } from '../schemas'; 23import { ThemeSource } from '../schemas';
24 24
25export const globalSettings = types.model('GlobalSettings', { 25const 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
29export 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*/
33interface GlobalSettings extends Instance<typeof GlobalSettings> {}
34
35export default GlobalSettings;
30 36
31export interface GlobalSettingsSnapshotIn 37export interface GlobalSettingsSnapshotIn
32 extends SnapshotIn<typeof globalSettings> {} 38 extends SnapshotIn<typeof GlobalSettings> {}
33 39
34export interface GlobalSettingsSnapshotOut 40export 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
21import { Instance, types } from 'mobx-state-tree'; 21import { Instance, types } from 'mobx-state-tree';
22 22
23import { profileSettings } from './ProfileSettings'; 23import ProfileSettings from './ProfileSettings';
24 24
25export const profile = types.model('Profile', { 25const Profile = types.model('Profile', {
26 id: types.identifier, 26 id: types.identifier,
27 settings: profileSettings, 27 settings: ProfileSettings,
28}); 28});
29 29
30export 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*/
34interface Profile extends Instance<typeof Profile> {}
35
36export 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
21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; 21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree';
22 22
23export const profileSettings = types.model('ProfileSettings', { 23const ProfileSettings = types.model('ProfileSettings', {
24 name: types.string, 24 name: types.string,
25}); 25});
26 26
27export 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*/
31interface ProfileSettings extends Instance<typeof ProfileSettings> {}
32
33export default ProfileSettings;
28 34
29export interface ProfileSettingsSnapshotIn 35export interface ProfileSettingsSnapshotIn
30 extends SnapshotIn<typeof profileSettings> {} 36 extends SnapshotIn<typeof ProfileSettings> {}
31 37
32export interface ProfileSettingsSnapshotOut 38export 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
21import { Instance, types } from 'mobx-state-tree'; 21import { Instance, types } from 'mobx-state-tree';
22 22
23import { serviceSettings } from './ServiceSettings'; 23import ServiceSettings from './ServiceSettings';
24 24
25export const service = types.model('Service', { 25const 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
40export 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*/
44interface Service extends Instance<typeof Service> {}
45
46export 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
21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; 21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree';
22 22
23import { profile } from './Profile'; 23import Profile from './Profile';
24 24
25export const serviceSettings = types.model('ServiceSettings', { 25const 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
32export 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*/
36interface ServiceSettings extends Instance<typeof ServiceSettings> {}
37
38export default ServiceSettings;
33 39
34export interface ServiceSettingsSnapshotIn 40export interface ServiceSettingsSnapshotIn
35 extends SnapshotIn<typeof serviceSettings> {} 41 extends SnapshotIn<typeof ServiceSettings> {}
36 42
37export interface ServiceSettingsSnapshotOut 43export 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
29import { globalSettings } from './GlobalSettings'; 29import GlobalSettings from './GlobalSettings';
30import { profile } from './Profile'; 30import Profile from './Profile';
31import { service } from './Service'; 31import Service from './Service';
32 32
33export const sharedStore = types.model('SharedStore', { 33const 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
43export 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*/
47interface SharedStore extends Instance<typeof SharedStore> {}
48
49export default SharedStore;
44 50
45export interface SharedStoreSnapshotIn extends SnapshotIn<typeof sharedStore> {} 51export interface SharedStoreSnapshotIn extends SnapshotIn<typeof SharedStore> {}
46 52
47export interface SharedStoreSnapshotOut 53export interface SharedStoreSnapshotOut
48 extends SnapshotOut<typeof sharedStore> {} 54 extends SnapshotOut<typeof SharedStore> {}
49 55
50export interface SharedStoreListener { 56export interface SharedStoreListener {
51 onSnapshot(snapshot: SharedStoreSnapshotIn): void; 57 onSnapshot(snapshot: SharedStoreSnapshotIn): void;