Skip to content

Commit

Permalink
feature: add setInfo command for electron webview handler (#105)
Browse files Browse the repository at this point in the history
* feature: add setInfo command for electron webview handler

* coverage

* lint
  • Loading branch information
levivilet authored Dec 23, 2024
1 parent 1df4375 commit 5ada98a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"type-check": "tsc",
"build": "node scripts/build.js",
"build:watch": "nodemon",
"lint": "eslint ."
"lint": "eslint .",
"format": "prettier --write ."
},
"keywords": [
"Lvce Editor",
Expand Down Expand Up @@ -119,7 +120,7 @@
"coverageThreshold": {
"global": {
"branches": 47,
"functions": 43,
"functions": 40,
"lines": 60
}
}
Expand Down
6 changes: 1 addition & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import pluginTypeScript from '@babel/preset-typescript'
const options = {
input: 'src/previewProcessMain.ts',
preserveEntrySignatures: 'strict',
external: [
'@lvce-editor/ipc',
'@lvce-editor/json-rpc',
'@lvce-editor/verror',
],
external: ['@lvce-editor/ipc', '@lvce-editor/json-rpc', '@lvce-editor/verror'],
treeshake: {
propertyReadSideEffects: false,
},
Expand Down
2 changes: 2 additions & 0 deletions src/parts/CommandMap/CommandMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as CreateWebViewServer from '../CreateWebViewServer/CreateWebViewServer.ts'
import * as HandleElectronMessagePort from '../HandleElectronMessagePort/HandleElectronMessagePort.ts'
import * as SetInfo from '../SetInfo/SetInfo.ts'
import * as SetWebViewServerHandler from '../SetWebViewServerHandler/SetWebViewServerHandler.ts'
import * as StartWebViewServer from '../StartWebViewServer/StartWebViewServer.ts'
import * as WebViewProtocol from '../WebViewProtocol/WebViewProtocol.ts'
Expand All @@ -10,4 +11,5 @@ export const commandMap = {
'WebViewServer.create': CreateWebViewServer.createWebViewServer,
'WebViewServer.setHandler': SetWebViewServerHandler.setWebViewServerHandler,
'WebViewServer.start': StartWebViewServer.startWebViewServer,
'WebViewServer.setInfo': SetInfo.setInfo,
}
4 changes: 4 additions & 0 deletions src/parts/Info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Info {
readonly webViewRoot: string
readonly webViewId: string
}
17 changes: 17 additions & 0 deletions src/parts/InfoRegistry/InfoRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Info } from '../Info.ts'

interface State {
[key: string]: Info
}

export const state: State = {
infos: Object.create(null),
}

export const set = (webViewId: string, info: Info): void => {
state[webViewId] = info
}

export const get = (webViewId: string): Info => {
return state[webViewId]
}
10 changes: 10 additions & 0 deletions src/parts/SetInfo/SetInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as CreateWebViewServerHandler from '../CreateWebViewServerHandler/CreateWebViewServerHandler.ts'
import * as InfoRegistry from '../InfoRegistry/InfoRegistry.ts'
import * as WebViewServerState from '../WebViewServerState/WebViewServerState.ts'

export const setInfo = (id: number, webViewId: string, webViewRoot: string): void => {
InfoRegistry.set(webViewId, {
webViewId,
webViewRoot,
})
}

0 comments on commit 5ada98a

Please sign in to comment.