diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-02-27 01:52:55 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-03-06 18:56:47 +0100 |
commit | 098d6f9bb1fd26f2d192db497992ab95b258ce55 (patch) | |
tree | 22905f87e6ad53032b6ff39bb3af274df2f6287c /packages/shared | |
parent | refactor: Shared model type factories (diff) | |
download | sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.tar.gz sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.tar.zst sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.zip |
feat: Location bar actions
The buttons and the text field in the location bar shall now affect the
BrowserView of the loaded service.
Some error handling is still needed, e.g., when loading a web page fails
due to a DNS error.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/shared')
-rw-r--r-- | packages/shared/src/contextBridge/SophieRenderer.ts | 2 | ||||
-rw-r--r-- | packages/shared/src/index.ts | 8 | ||||
-rw-r--r-- | packages/shared/src/schemas/Action.ts (renamed from packages/shared/src/schemas.ts) | 29 | ||||
-rw-r--r-- | packages/shared/src/schemas/BrowserViewBounds.ts | 35 | ||||
-rw-r--r-- | packages/shared/src/schemas/ServiceAction.ts | 51 | ||||
-rw-r--r-- | packages/shared/src/schemas/ThemeSource.ts | 29 | ||||
-rw-r--r-- | packages/shared/src/stores/GlobalSettingsBase.ts | 2 |
7 files changed, 132 insertions, 24 deletions
diff --git a/packages/shared/src/contextBridge/SophieRenderer.ts b/packages/shared/src/contextBridge/SophieRenderer.ts index 9e087da..dc77c97 100644 --- a/packages/shared/src/contextBridge/SophieRenderer.ts +++ b/packages/shared/src/contextBridge/SophieRenderer.ts | |||
@@ -18,7 +18,7 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { Action } from '../schemas'; | 21 | import { Action } from '../schemas/Action'; |
22 | import { SharedStoreListener } from '../stores/SharedStoreBase'; | 22 | import { SharedStoreListener } from '../stores/SharedStoreBase'; |
23 | 23 | ||
24 | export default interface SophieRenderer { | 24 | export default interface SophieRenderer { |
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 66debf7..fa3fbfd 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts | |||
@@ -22,7 +22,13 @@ 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 { Action, BrowserViewBounds, ThemeSource } from './schemas'; | 25 | export { Action } from './schemas/Action'; |
26 | |||
27 | export { BrowserViewBounds } from './schemas/BrowserViewBounds'; | ||
28 | |||
29 | export { ServiceAction } from './schemas/ServiceAction'; | ||
30 | |||
31 | export { ThemeSource } from './schemas/ThemeSource'; | ||
26 | 32 | ||
27 | export type { | 33 | export type { |
28 | GlobalSettingsSnapshotIn, | 34 | GlobalSettingsSnapshotIn, |
diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas/Action.ts index 9d87d10..d5d0a8d 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas/Action.ts | |||
@@ -20,27 +20,9 @@ | |||
20 | 20 | ||
21 | import { z } from 'zod'; | 21 | import { z } from 'zod'; |
22 | 22 | ||
23 | export const BrowserViewBounds = /* @__PURE__ */ (() => | 23 | import { BrowserViewBounds } from './BrowserViewBounds'; |
24 | z.object({ | 24 | import { ServiceAction } from './ServiceAction'; |
25 | x: z.number().int().nonnegative(), | 25 | import { ThemeSource } from './ThemeSource'; |
26 | y: z.number().int().nonnegative(), | ||
27 | width: z.number().int().nonnegative(), | ||
28 | height: z.number().int().nonnegative(), | ||
29 | }))(); | ||
30 | |||
31 | /* | ||
32 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
33 | Intentionally naming the type the same as the schema definition. | ||
34 | */ | ||
35 | export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; | ||
36 | |||
37 | export const ThemeSource = /* @__PURE__ */ z.enum(['system', 'light', 'dark']); | ||
38 | |||
39 | /* | ||
40 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
41 | Intentionally naming the type the same as the schema definition. | ||
42 | */ | ||
43 | export type ThemeSource = z.infer<typeof ThemeSource>; | ||
44 | 26 | ||
45 | export const Action = /* @__PURE__ */ (() => | 27 | export const Action = /* @__PURE__ */ (() => |
46 | z.union([ | 28 | z.union([ |
@@ -63,6 +45,11 @@ export const Action = /* @__PURE__ */ (() => | |||
63 | z.object({ | 45 | z.object({ |
64 | action: z.literal('reload-all-services'), | 46 | action: z.literal('reload-all-services'), |
65 | }), | 47 | }), |
48 | z.object({ | ||
49 | action: z.literal('dispatch-service-action'), | ||
50 | serviceId: z.string(), | ||
51 | serviceAction: ServiceAction, | ||
52 | }), | ||
66 | ]))(); | 53 | ]))(); |
67 | 54 | ||
68 | /* | 55 | /* |
diff --git a/packages/shared/src/schemas/BrowserViewBounds.ts b/packages/shared/src/schemas/BrowserViewBounds.ts new file mode 100644 index 0000000..e668a4a --- /dev/null +++ b/packages/shared/src/schemas/BrowserViewBounds.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2021-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 { z } from 'zod'; | ||
22 | |||
23 | export const BrowserViewBounds = /* @__PURE__ */ (() => | ||
24 | z.object({ | ||
25 | x: z.number().int().nonnegative(), | ||
26 | y: z.number().int().nonnegative(), | ||
27 | width: z.number().int().nonnegative(), | ||
28 | height: z.number().int().nonnegative(), | ||
29 | }))(); | ||
30 | |||
31 | /* | ||
32 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
33 | Intentionally naming the type the same as the schema definition. | ||
34 | */ | ||
35 | export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; | ||
diff --git a/packages/shared/src/schemas/ServiceAction.ts b/packages/shared/src/schemas/ServiceAction.ts new file mode 100644 index 0000000..a4a7049 --- /dev/null +++ b/packages/shared/src/schemas/ServiceAction.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2021-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 { z } from 'zod'; | ||
22 | |||
23 | export const ServiceAction = /* @__PURE__ */ (() => | ||
24 | z.union([ | ||
25 | z.object({ | ||
26 | action: z.literal('back'), | ||
27 | }), | ||
28 | z.object({ | ||
29 | action: z.literal('forward'), | ||
30 | }), | ||
31 | z.object({ | ||
32 | action: z.literal('reload'), | ||
33 | ignoreCache: z.boolean(), | ||
34 | }), | ||
35 | z.object({ | ||
36 | action: z.literal('stop'), | ||
37 | }), | ||
38 | z.object({ | ||
39 | action: z.literal('go-home'), | ||
40 | }), | ||
41 | z.object({ | ||
42 | action: z.literal('go'), | ||
43 | url: z.string(), | ||
44 | }), | ||
45 | ]))(); | ||
46 | |||
47 | /* | ||
48 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
49 | Intentionally naming the type the same as the schema definition. | ||
50 | */ | ||
51 | export type ServiceAction = z.infer<typeof ServiceAction>; | ||
diff --git a/packages/shared/src/schemas/ThemeSource.ts b/packages/shared/src/schemas/ThemeSource.ts new file mode 100644 index 0000000..6db5788 --- /dev/null +++ b/packages/shared/src/schemas/ThemeSource.ts | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2021-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 { z } from 'zod'; | ||
22 | |||
23 | export const ThemeSource = /* @__PURE__ */ z.enum(['system', 'light', 'dark']); | ||
24 | |||
25 | /* | ||
26 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
27 | Intentionally naming the type the same as the schema definition. | ||
28 | */ | ||
29 | export type ThemeSource = z.infer<typeof ThemeSource>; | ||
diff --git a/packages/shared/src/stores/GlobalSettingsBase.ts b/packages/shared/src/stores/GlobalSettingsBase.ts index 48092fd..1bd0628 100644 --- a/packages/shared/src/stores/GlobalSettingsBase.ts +++ b/packages/shared/src/stores/GlobalSettingsBase.ts | |||
@@ -26,7 +26,7 @@ import { | |||
26 | IAnyModelType, | 26 | IAnyModelType, |
27 | } from 'mobx-state-tree'; | 27 | } from 'mobx-state-tree'; |
28 | 28 | ||
29 | import { ThemeSource } from '../schemas'; | 29 | import { ThemeSource } from '../schemas/ThemeSource'; |
30 | 30 | ||
31 | import ServiceBase from './ServiceBase'; | 31 | import ServiceBase from './ServiceBase'; |
32 | 32 | ||