diff options
Diffstat (limited to 'packages/renderer/src/env/impl/RendererEnvImpl.ts')
-rw-r--r-- | packages/renderer/src/env/impl/RendererEnvImpl.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/renderer/src/env/impl/RendererEnvImpl.ts b/packages/renderer/src/env/impl/RendererEnvImpl.ts new file mode 100644 index 0000000..184d31b --- /dev/null +++ b/packages/renderer/src/env/impl/RendererEnvImpl.ts | |||
@@ -0,0 +1,55 @@ | |||
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 | |||
21 | import { | ||
22 | Action, | ||
23 | runtimeService, | ||
24 | RuntimeService, | ||
25 | SophieRenderer, | ||
26 | } from '@sophie/shared'; | ||
27 | import type { IMSTMap } from 'mobx-state-tree'; | ||
28 | |||
29 | import type { RendererStore } from '../../stores/RendererStore'; | ||
30 | import type RendererEnv from '../RendererEnv'; | ||
31 | |||
32 | export default class RendererEnvImpl implements RendererEnv { | ||
33 | readonly #ipc: SophieRenderer; | ||
34 | |||
35 | #runtimeServices: IMSTMap<typeof runtimeService> | undefined; | ||
36 | |||
37 | constructor(ipc: SophieRenderer) { | ||
38 | this.#ipc = ipc; | ||
39 | } | ||
40 | |||
41 | setStore(store: RendererStore): void { | ||
42 | this.#runtimeServices = store.shared.runtimeServices; | ||
43 | } | ||
44 | |||
45 | dispatchMainAction(action: Action): void { | ||
46 | this.#ipc.dispatchAction(action); | ||
47 | } | ||
48 | |||
49 | getRuntimeService(serviceId: string): RuntimeService | undefined { | ||
50 | if (this.#runtimeServices === undefined) { | ||
51 | throw new Error('runtime services map is not yet set'); | ||
52 | } | ||
53 | return this.#runtimeServices.get(serviceId); | ||
54 | } | ||
55 | } | ||