Skip to content

Commit 6ddea61

Browse files
committed
Remote devtools MVP: added middleware server with websockets communication and express serving file for client (backend)
1 parent bbc9999 commit 6ddea61

File tree

10 files changed

+8573
-47
lines changed

10 files changed

+8573
-47
lines changed

package-lock.json

Lines changed: 8453 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"dev": "cd shells/dev && webpack-dev-server --inline --hot --no-info",
88
"dev:chrome": "cd shells/chrome && webpack --watch --hide-modules",
9-
"dev:electron": "cd shells/electron && webpack --watch --hide-modules",
109
"dev:safari": "cd shells/safari && webpack --watch --hide-modules",
1110
"lint": "eslint src --ext=js,vue && eslint shells/chrome/src && eslint shells/dev/src && eslint shells/safari/src",
1211
"build": "cd shells/chrome && cross-env NODE_ENV=production webpack --progress --hide-modules",

shells/electron/app.html

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<title>Vue Developer Tools</title>
6-
<style>
7-
body {
8-
display: flex;
9-
flex-direction: column;
10-
position: absolute;
11-
top: 0;
12-
left: 0;
13-
right: 0;
14-
bottom: 0;
15-
margin: 0;
16-
padding: 0;
17-
}
18-
</style>
4+
<meta charset="UTF-8">
5+
<title>Vue Developer Tools</title>
6+
<style>
7+
body {
8+
display: flex;
9+
flex-direction: column;
10+
position: absolute;
11+
top: 0;
12+
left: 0;
13+
right: 0;
14+
bottom: 0;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
</style>
1919
</head>
2020
<body>
21-
<div id="app"></div>
22-
<script src="build/devtools.js"></script>
21+
<div id="app">
22+
Loading...
23+
</div>
24+
<script src="build/devtools.js"></script>
2325
</body>
24-
</html>
26+
</html>

shells/electron/app.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1+
// Start middleware server
2+
require('./server')
3+
14
const { app, BrowserWindow } = require('electron')
5+
const path = require('path')
6+
const url = require('url')
27

38
let mainWindow = null
49

5-
app.on('window-all-closed', () => app.quit())
6-
app.on('ready', () => {
7-
mainWindow = new BrowserWindow({ width: 800, height: 600 })
10+
function createWindow () {
11+
mainWindow = new BrowserWindow({
12+
width: 800,
13+
height: 600,
14+
icon: path.join(__dirname, 'icons/128.png')
15+
})
16+
17+
mainWindow.loadURL(url.format({
18+
pathname: path.join(__dirname, 'app.html'),
19+
protocol: 'file:',
20+
slashes: true
21+
}))
22+
23+
mainWindow.on('closed', () => {
24+
mainWindow = null
25+
})
26+
}
27+
28+
app.on('ready', createWindow)
829

9-
mainWindow.loadURL('file://' + __dirname + '/app.html')
30+
app.on('window-all-closed', () => {
31+
if (process.platform !== 'darwin') {
32+
app.quit()
33+
}
34+
})
1035

11-
mainWindow.on('closed', () => mainWindow = null)
12-
})
36+
app.on('activate', () => {
37+
if (mainWindow === null) {
38+
createWindow()
39+
}
40+
})

shells/electron/bin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const spawn = require('cross-spawn')
33

44
const result = spawn.sync(
55
electron,
6-
[require.resolve('./app')],
6+
[
7+
require.resolve('./app')
8+
],
9+
{ stdio: 'ignore' }
710
)
811

9-
process.exit(result.status)
12+
process.exit(result.status)
File renamed without changes.

shells/electron/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
"name": "vue-devtools",
33
"version": "0.0.1",
44
"description": "StandAlone vue-devtools",
5+
"repository": {
6+
"url": "https://github.com/vuejs/vue-devtools.git",
7+
"type": "git"
8+
},
59
"bin": {
610
"vue-devtools": "./bin.js"
711
},
812
"scripts": {
9-
"start": "node bin.js"
13+
"start": "node bin.js",
14+
"dev": "webpack --watch --hide-modules"
1015
},
1116
"author": "",
1217
"license": "MIT",
1318
"dependencies": {
1419
"cross-spawn": "^5.1.0",
15-
"electron": "^1.8.1"
20+
"electron": "^1.8.1",
21+
"express": "^4.16.2",
22+
"socket.io": "^2.0.4"
23+
},
24+
"devDependencies": {
25+
"webpack": "^3.10.0"
1626
}
1727
}

shells/electron/server.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const app = require('express')()
2+
const http = require('http').Server(app)
3+
const io = require('socket.io')(http)
4+
const path = require('path')
5+
6+
app.get('/', function (req, res) {
7+
res.sendFile(path.join(__dirname, '/build/backend.js'))
8+
})
9+
10+
// Middleman
11+
io.on('connection', function (socket) {
12+
socket.on('vue-message', data => {
13+
socket.broadcast.emit('vue-message', data)
14+
})
15+
})
16+
17+
http.listen(8098, () => {
18+
console.log('listening on *:8098')
19+
})

shells/electron/src/backend.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
import io from 'socket.io-client'
12
import { initBackend } from 'src/backend'
3+
import { installHook } from 'src/backend/hook'
24
import Bridge from 'src/bridge'
35

4-
const bridge = new Bridge({
5-
listen (fn) {
6-
window.addEventListener('message', evt => fn(evt.data))
7-
},
8-
send (data) {
9-
console.log('backend -> devtools', data)
10-
window.parent.postMessage(data, '*')
6+
(function () {
7+
const socket = io('http://localhost:8098')
8+
9+
const bridge = new Bridge({
10+
listen (fn) {
11+
socket.on('vue-message', data => fn(data))
12+
},
13+
send (data) {
14+
console.log('backend -> devtools', data)
15+
socket.emit('vue-message', data)
16+
}
17+
})
18+
19+
if (!window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
20+
installHook(window)
1121
}
12-
})
1322

14-
initBackend(bridge)
23+
initBackend(bridge)
24+
}())

shells/electron/src/devtools.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { initDevTools } from 'src/devtools'
22
import Bridge from 'src/bridge'
3+
import io from 'socket.io-client'
34

4-
initDevTools({
5-
connect(callback) {
6-
console.log('connect has been called')
5+
const socket = io('http://localhost:8098')
76

7+
initDevTools({
8+
connect (callback) {
89
const wall = {
9-
listen(fn) {
10-
console.log('wall.listen has been called')
10+
listen (fn) {
11+
socket.on('vue-message', data => fn(data))
1112
},
12-
send(data) {
13-
console.log('wall.send has been called', data)
13+
send (data) {
14+
console.log('devtools -> backend', data)
15+
socket.emit('vue-message', data)
1416
}
1517
}
1618
const bridge = new Bridge(wall)
1719

1820
callback(bridge)
1921
},
20-
onReload(fn) {
22+
onReload (fn) {
2123
console.log('onReload has been called')
2224
}
23-
})
25+
})

0 commit comments

Comments
 (0)