-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathdevtools.ts
47 lines (39 loc) · 1.17 KB
/
devtools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os from 'node:os'
import { functions } from '@vue/devtools-core'
import { createRpcClient, setElectronClientContext } from '@vue/devtools-kit'
import io from 'socket.io-client/dist/socket.io.js'
import { createConnectionApp, initDevTools } from '../client/devtools-panel'
const port = window.process.env.PORT || 8098
function address() {
return Object.values(os.networkInterfaces()).map((addresses) => {
return addresses?.filter((details) => {
return !details.internal && details.family === 'IPv4'
})
}).flat()[0]
}
function init() {
const localhost = `http://localhost:${port}`
const socket = io(localhost)
let reload: Function | null = null
const app = createConnectionApp('#app', {
local: localhost,
network: `http://${address()}:${port}`,
})
socket.on('vue-devtools:init', () => {
app.unmount()
setElectronClientContext(socket)
createRpcClient(functions, {
preset: 'electron',
})
initDevTools()
})
function shutdown() {
app.unmount()
reload = null
socket.close()
init()
}
socket.on('vue-devtools:disconnect', shutdown)
socket.on('vue-devtools-disconnect-devtools', shutdown)
}
init()