aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/shared/src')
-rw-r--r--packages/shared/src/contextBridge/SophieRenderer.ts7
-rw-r--r--packages/shared/src/index.ts4
-rw-r--r--packages/shared/src/ipc.ts2
-rw-r--r--packages/shared/src/schemas/Action.ts7
-rw-r--r--packages/shared/src/schemas/Translation.ts33
-rw-r--r--packages/shared/src/stores/SharedStoreBase.ts1
6 files changed, 54 insertions, 0 deletions
diff --git a/packages/shared/src/contextBridge/SophieRenderer.ts b/packages/shared/src/contextBridge/SophieRenderer.ts
index dc77c97..732f941 100644
--- a/packages/shared/src/contextBridge/SophieRenderer.ts
+++ b/packages/shared/src/contextBridge/SophieRenderer.ts
@@ -18,11 +18,18 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import type { ResourceKey } from 'i18next';
22
21import { Action } from '../schemas/Action'; 23import { Action } from '../schemas/Action';
24import { Translation } from '../schemas/Translation';
22import { SharedStoreListener } from '../stores/SharedStoreBase'; 25import { SharedStoreListener } from '../stores/SharedStoreBase';
23 26
24export default interface SophieRenderer { 27export default interface SophieRenderer {
25 onSharedStoreChange(this: void, listener: SharedStoreListener): Promise<void>; 28 onSharedStoreChange(this: void, listener: SharedStoreListener): Promise<void>;
26 29
27 dispatchAction(this: void, action: Action): void; 30 dispatchAction(this: void, action: Action): void;
31
32 getTranslation(this: void, translation: Translation): Promise<ResourceKey>;
33
34 onReloadTranslations(this: void, listener: () => void): void;
28} 35}
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index f7c5bcf..51f9f06 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -18,6 +18,8 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21export const fallbackLng = ['en'];
22
21export type { default as SophieRenderer } from './contextBridge/SophieRenderer'; 23export type { default as SophieRenderer } from './contextBridge/SophieRenderer';
22 24
23export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc'; 25export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc';
@@ -30,6 +32,8 @@ export { ServiceAction } from './schemas/ServiceAction';
30 32
31export { ThemeSource } from './schemas/ThemeSource'; 33export { ThemeSource } from './schemas/ThemeSource';
32 34
35export { Translation } from './schemas/Translation';
36
33export type { CertificateSnapshotIn } from './stores/Certificate'; 37export type { CertificateSnapshotIn } from './stores/Certificate';
34export { default as Certificate } from './stores/Certificate'; 38export { default as Certificate } from './stores/Certificate';
35 39
diff --git a/packages/shared/src/ipc.ts b/packages/shared/src/ipc.ts
index 54d761a..2716633 100644
--- a/packages/shared/src/ipc.ts
+++ b/packages/shared/src/ipc.ts
@@ -20,9 +20,11 @@
20 20
21export enum MainToRendererIpcMessage { 21export enum MainToRendererIpcMessage {
22 SharedStorePatch = 'sophie-main-to-renderer:shared-store-patch', 22 SharedStorePatch = 'sophie-main-to-renderer:shared-store-patch',
23 ReloadTranslations = 'sophie-main-to-renderer:reload-translations',
23} 24}
24 25
25export enum RendererToMainIpcMessage { 26export enum RendererToMainIpcMessage {
26 GetSharedStoreSnapshot = 'sophie-renderer-to-main:get-shared-store-snapshot', 27 GetSharedStoreSnapshot = 'sophie-renderer-to-main:get-shared-store-snapshot',
28 GetTranslation = 'sophie-renderer-to-main:get-translation',
27 DispatchAction = 'sophie-renderer-to-main:dispatch-action', 29 DispatchAction = 'sophie-renderer-to-main:dispatch-action',
28} 30}
diff --git a/packages/shared/src/schemas/Action.ts b/packages/shared/src/schemas/Action.ts
index 8d6ca3a..ce983fa 100644
--- a/packages/shared/src/schemas/Action.ts
+++ b/packages/shared/src/schemas/Action.ts
@@ -49,6 +49,13 @@ export const Action = /* @__PURE__ */ (() =>
49 action: z.literal('reload-all-translations'), 49 action: z.literal('reload-all-translations'),
50 }), 50 }),
51 z.object({ 51 z.object({
52 action: z.literal('add-missing-translation'),
53 languages: z.string().nonempty().array(),
54 namespace: z.string().nonempty(),
55 key: z.string().nonempty(),
56 value: z.string(),
57 }),
58 z.object({
52 action: z.literal('dispatch-service-action'), 59 action: z.literal('dispatch-service-action'),
53 serviceId: z.string(), 60 serviceId: z.string(),
54 serviceAction: ServiceAction, 61 serviceAction: ServiceAction,
diff --git a/packages/shared/src/schemas/Translation.ts b/packages/shared/src/schemas/Translation.ts
new file mode 100644
index 0000000..ab513b5
--- /dev/null
+++ b/packages/shared/src/schemas/Translation.ts
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 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
21import { z } from 'zod';
22
23export const Translation = /* @__PURE__ */ (() =>
24 z.object({
25 language: z.string().nonempty(),
26 namespace: z.string().nonempty(),
27 }))();
28
29/*
30 eslint-disable-next-line @typescript-eslint/no-redeclare --
31 Intentionally naming the type the same as the schema definition.
32*/
33export type Translation = z.infer<typeof Translation>;
diff --git a/packages/shared/src/stores/SharedStoreBase.ts b/packages/shared/src/stores/SharedStoreBase.ts
index 8d6624b..86bd0fc 100644
--- a/packages/shared/src/stores/SharedStoreBase.ts
+++ b/packages/shared/src/stores/SharedStoreBase.ts
@@ -43,6 +43,7 @@ export function defineSharedStoreModel<
43 servicesById: types.map(service), 43 servicesById: types.map(service),
44 services: types.array(types.reference(service)), 44 services: types.array(types.reference(service)),
45 shouldUseDarkColors: false, 45 shouldUseDarkColors: false,
46 language: 'en',
46 }); 47 });
47} 48}
48 49