-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(electron): compatible with vue custom renderer (#164)
- Loading branch information
1 parent
b569ec4
commit ab37408
Showing
16 changed files
with
752 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { devtools } from '@vue/devtools-kit' | ||
|
||
devtools.init() |
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,49 @@ | ||
import { isBrowser, target } from '@vue/devtools-shared' | ||
import { Bridge } from '../../core/src/bridge' | ||
import { prepareInjection } from '../../core/src/injection' | ||
import { devtools } from '../../devtools-kit/src/index' | ||
|
||
export function init(io) { | ||
const createSocket = io | ||
const host = target.__VUE_DEVTOOLS_HOST__ || 'http://localhost' | ||
const port = target.__VUE_DEVTOOLS_PORT__ !== undefined ? target.__VUE_DEVTOOLS_PORT__ : 8098 | ||
const fullHost = port ? `${host}:${port}` : host | ||
const socket = createSocket(fullHost) | ||
|
||
// @TODO: de-duplicate | ||
devtools.init() | ||
|
||
const bridge = new Bridge({ | ||
tracker(fn) { | ||
socket.on('vue-devtools:message', (data) => { | ||
fn(data) | ||
}) | ||
}, | ||
trigger(data) { | ||
socket.emit('vue-devtools:message', data) | ||
}, | ||
}) | ||
|
||
socket.on('connect', () => { | ||
prepareInjection(bridge) | ||
socket.emit('vue-devtools:init') | ||
}) | ||
|
||
// Global disconnect handler. Fires in two cases: | ||
// - after calling above socket.disconnect() | ||
// - once devtools is closed (that's why we need socket.disconnect() here too, to prevent further polling) | ||
socket.on('disconnect', () => { | ||
socket.disconnect() | ||
}) | ||
|
||
// Disconnect socket once other client is connected | ||
socket.on('vue-devtools:disconnect-user-app', () => { | ||
socket.disconnect() | ||
}) | ||
|
||
if (isBrowser) { | ||
window.addEventListener('beforeunload', () => { | ||
socket.emit('vue-devtools:disconnect') | ||
}) | ||
} | ||
} |
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,4 @@ | ||
import io from 'socket.io-client/dist/socket.io.js' | ||
import { init } from './user-app.core' | ||
|
||
init(io) |
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,46 +1,4 @@ | ||
import io from 'socket.io-client/dist/socket.io.js' | ||
import { target } from '@vue/devtools-shared' | ||
import { Bridge } from '../../core/src/bridge' | ||
import { prepareInjection } from '../../core/src/injection' | ||
import { devtools } from '../../devtools-kit/src/index' | ||
import io from 'socket.io-client' | ||
import { init } from './user-app.core' | ||
|
||
const createSocket = io | ||
const host = target.__VUE_DEVTOOLS_HOST__ || 'http://localhost' | ||
const port = target.__VUE_DEVTOOLS_PORT__ !== undefined ? target.__VUE_DEVTOOLS_PORT__ : 8098 | ||
const fullHost = port ? `${host}:${port}` : host | ||
const socket = createSocket(fullHost) | ||
|
||
// @TODO: de-duplicate | ||
devtools.init() | ||
|
||
const bridge = new Bridge({ | ||
tracker(fn) { | ||
socket.on('vue-devtools:message', (data) => { | ||
fn(data) | ||
}) | ||
}, | ||
trigger(data) { | ||
socket.emit('vue-devtools:message', data) | ||
}, | ||
}) | ||
|
||
socket.on('connect', () => { | ||
prepareInjection(bridge) | ||
socket.emit('vue-devtools:init') | ||
}) | ||
|
||
// Global disconnect handler. Fires in two cases: | ||
// - after calling above socket.disconnect() | ||
// - once devtools is closed (that's why we need socket.disconnect() here too, to prevent further polling) | ||
socket.on('disconnect', () => { | ||
socket.disconnect() | ||
}) | ||
|
||
// Disconnect socket once other client is connected | ||
socket.on('vue-devtools:disconnect-user-app', () => { | ||
socket.disconnect() | ||
}) | ||
|
||
window.addEventListener('beforeunload', () => { | ||
socket.emit('vue-devtools:disconnect') | ||
}) | ||
init(io) |
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,29 @@ | ||
{ | ||
"name": "vue-termui-playground", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"bin": { | ||
"vtui-app": "./dist/main.mjs" | ||
}, | ||
"scripts": { | ||
"dev:vtui": "vtui dev" | ||
}, | ||
"dependencies": { | ||
"@vue/devtools": "workspace:^", | ||
"@vue/runtime-core": "^3.2.41", | ||
"vue": "^3.2.41", | ||
"vue-termui": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.11.9", | ||
"@vitejs/plugin-vue": "^3.2.0", | ||
"@vue-termui/cli": "*", | ||
"@vue/compiler-sfc": "^3.2.41", | ||
"typescript": "^4.8.4", | ||
"unplugin-auto-import": "^0.11.4", | ||
"unplugin-vue-components": "^0.22.9", | ||
"vite": "^3.2.2", | ||
"vite-plugin-vue-termui": "*" | ||
} | ||
} |
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,56 @@ | ||
<script lang="ts" setup> | ||
// All imports are automatic but if you want to import anything, | ||
// remember to import from 'vue-termui': | ||
// import { ref } from 'vue-termui' | ||
const n = ref(0) | ||
const counter = ref(0) | ||
onKeyData(['+', 'ArrowRight', 'ArrowUp'], () => { | ||
counter.value++ | ||
}) | ||
onKeyData(['-', 'ArrowLeft', 'ArrowDown'], () => { | ||
counter.value-- | ||
}) | ||
useInterval(() => { | ||
n.value++ | ||
}, 600) | ||
</script> | ||
|
||
<template> | ||
<Box | ||
:padding="2" | ||
:margin="2" | ||
width="100%" | ||
:max-width="50" | ||
justify-content="center" | ||
align-items="center" | ||
flex-direction="column" | ||
border-color="yellowBright" | ||
border-style="round" | ||
> | ||
<Box :margin-y="1"> | ||
<Text color="cyanBright"> | ||
Hello World | ||
</Text> | ||
<Text>{{ n % 2 ? '👋 ' : ' ✋' }}</Text> | ||
</Box> | ||
<Box> | ||
<Text> | ||
Counter: | ||
<Text :color="counter < 0 ? 'red' : 'green'" bold> | ||
{{ counter }} | ||
</Text> | ||
<Text dimmed> | ||
(<Text color="red" bold> | ||
- | ||
</Text>/<Text bold color="green"> | ||
+ | ||
</Text> to | ||
change it) | ||
</Text> | ||
</Text> | ||
</Box> | ||
</Box> | ||
</template> |
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,14 @@ | ||
import { devtools } from '@vue/devtools' | ||
import '@vue/devtools/hook' | ||
import { createApp } from 'vue-termui' | ||
import App from './App.vue' | ||
|
||
globalThis.document = { | ||
createElement: () => {}, | ||
getElementById: () => {}, | ||
} as any | ||
|
||
devtools.connect('http://localhost', 8098) | ||
|
||
const app = createApp(App) | ||
app.mount() |
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,6 @@ | ||
import { defineConfig } from 'vite' | ||
import VueTermui from 'vite-plugin-vue-termui' | ||
|
||
export default defineConfig({ | ||
plugins: [VueTermui()], | ||
}) |
Oops, something went wrong.