Skip to content

Commit

Permalink
feat(webui): use CLIENT_CONFIG instead of KOISHI_CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 25, 2024
1 parent ac0598d commit 72dbe80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/client/client/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { markRaw, ref } from 'vue'
import { Context } from './context'
import { root } from '.'

declare const KOISHI_CONFIG: ClientConfig
export const global = KOISHI_CONFIG
declare const CLIENT_CONFIG: ClientConfig
export const global = CLIENT_CONFIG

export const socket = ref<WebSocket>()
const listeners: Record<string, (data: any) => void> = {}
Expand Down
24 changes: 11 additions & 13 deletions plugins/webui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class NodeWebUI extends WebUI<NodeWebUI.Config> {
} else {
template = template.replace(/(href|src)="(?=\/)/g, (_, $1) => `${$1}="${uiPath}`)
}
let headInjection = `<script>KOISHI_CONFIG = ${JSON.stringify(this.createGlobal())}</script>`
let headInjection = `<script>CLIENT_CONFIG = ${JSON.stringify(this.createGlobal())}</script>`
for (const { tag, attrs = {}, content } of head) {
const attrString = Object.entries(attrs).map(([key, value]) => ` ${key}="${escapeHTML(value ?? '', true)}"`).join('')
headInjection += `<${tag}${attrString}>${content ?? ''}</${tag}>`
Expand All @@ -216,18 +216,16 @@ class NodeWebUI extends WebUI<NodeWebUI.Config> {
for (const [key, { files }] of Object.entries(this.entries)) {
const index = makeArray(this.getFiles(files)).indexOf(pathToFileURL(id).href)
if (index < 0) continue
return {
code: code + [
'if (import.meta.hot) {',
' import.meta.hot.accept(async (module) => {',
' const { root } = await import("@cordisjs/client");',
` const fork = root.$loader.entries["${key}"]?.forks[${index}];`,
' return fork?.update(module, true);',
' });',
'}',
].join('\n') + '\n',
map: null,
}
code += [
'if (import.meta.hot) {',
' import.meta.hot.accept(async (module) => {',
' const { root } = await import("@cordisjs/client");',
` const fork = root.$loader.entries["${key}"]?.forks[${index}];`,
' return fork?.update(module, true);',
' });',
'}',
].join('\n') + '\n'
return { code }
}
},
}],
Expand Down

0 comments on commit 72dbe80

Please sign in to comment.