-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(media/developer): adds store communication between renderer and …
…main processes
- Loading branch information
1 parent
1873c03
commit 2f7ba05
Showing
12 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { onBeforeUnmount, reactive, toRaw, watch } from 'vue' | ||
|
||
import { StoreDefinition } from 'shared/types/store' | ||
|
||
export function useStore<Key extends keyof StoreDefinition> (key: Key) { | ||
const store = reactive(window.store.get<Key>(key)) | ||
|
||
watch(store, (newValue) => { | ||
window.store.set(key, toRaw(newValue) as StoreDefinition[Key]) | ||
}) | ||
const unwatch = window.store.watch(key, (newValue) => { | ||
Object.assign(store, newValue) | ||
}) | ||
onBeforeUnmount(() => { | ||
unwatch() | ||
}) | ||
|
||
return { | ||
store | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"baseUrl": ".", | ||
"rootDir": "..", | ||
"composite": false, | ||
"module": "es2020", | ||
"paths": { | ||
"@/*": [ | ||
"src/*" | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/media/app/shared/store.ts → packages/media/app/shared/src/store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"rootDir": ".", | ||
"module": "es2020" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"types/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
interface ElectronApi { | ||
import { StoreDefinition } from './store' | ||
|
||
export interface ElectronApi { | ||
invoke<T extends { Args?: unknown, Response: unknown }> (channel: string, args?: T['Args']): Promise<T['Response']> | ||
send<T extends { Args?: unknown }> (channel: string, args?: T['Args']): void | ||
on<T extends { Args?: unknown }> (channel: string, cb: (args: T['Args']) => void): void | ||
} | ||
|
||
declare interface Window { | ||
electron: Readonly<ElectronApi> | ||
log: import('electron-log').LogFunctions | ||
export interface StoreApi { | ||
get<Key extends keyof StoreDefinition> (key: Key, defaultValue?: StoreDefinition[Key]): StoreDefinition[Key] | ||
get<Key extends string, Value extends unknown> (key: Key, defaultValue?: Value): Value | ||
set<Key extends keyof StoreDefinition> (key: Key, value: StoreDefinition[Key]): void | ||
watch<Key extends keyof StoreDefinition> (key: Key, cb: (newValue?: StoreDefinition[Key]) => void): () => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare interface Window { | ||
electron: Readonly<import('./electron-api').ElectronApi> | ||
log: import('electron-log').LogFunctions | ||
store: import('./electron-api').StoreApi | ||
} |