Skip to content

Commit e3757d4

Browse files
committed
Handle disconnections, keep only one connection live
1 parent 7680aca commit e3757d4

File tree

6 files changed

+69
-25
lines changed

6 files changed

+69
-25
lines changed

shells/electron/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
Install the package globally:
88
```bash
9-
npm install -g vue-remote-devtools
9+
npm install -g @vue/devtools
1010
```
1111

1212
### :rocket: Usage
1313

1414
Once you installed the package globally, run:
1515
```bash
16-
vue-remote-devtools
16+
vue-devtools
1717
```
1818

1919
Then add:
@@ -23,14 +23,14 @@ Then add:
2323
To the `<head>` section of your app.
2424
**(Don't forget to remove it before deploying to production!)**
2525

26-
Alternatively you can also install `vue-remote-devtools` as project dependency:
26+
Alternatively you can also install `@vue/devtools` as project dependency:
2727
```bash
28-
npm install vue-remote-devtools --save-dev
28+
npm install @vue/devtools --save-dev
2929
```
3030

3131
And then directly import it in your app:
3232
```js
33-
import devtools from 'vue-remote-devtools'
33+
import devtools from '@vue/devtools'
3434

3535
if (process.env.NODE_ENV === 'development') {
3636
devtools.connect()

shells/electron/app.html

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<meta charset="UTF-8">
55
<title>Vue Developer Tools</title>
66
<style>
7-
#app {
7+
#app,
8+
#intro {
89
display: flex;
910
flex-direction: column;
1011
position: absolute;
@@ -17,13 +18,19 @@
1718
}
1819

1920
#intro {
21+
z-index: 100;
22+
justify-content: center;
23+
align-items: center;
2024
background-color: #fff;
21-
margin: auto;
2225
text-align: center;
2326
font-family: Roboto, sans-serif;
2427
color: #484848;
2528
}
2629

30+
#intro.hidden {
31+
display: none;
32+
}
33+
2734
#intro .logo {
2835
width: 120px;
2936
}
@@ -63,33 +70,32 @@
6370
</style>
6471
</head>
6572
<body>
66-
<div id="app">
67-
<div id="intro">
68-
<img src="icons/128.png" alt="" class="logo">
69-
<h2 class="title">
70-
Waiting for connection...
71-
</h2>
72-
<div class="content">
73-
<div class="content-row">
74-
<label for="script-localhost">Add</label>
75-
<input type="text" id="script-localhost">
76-
</div>
77-
<div class="content-row">
78-
<label for="script-byip">Or</label>
79-
<input type="text" id="script-byip">
80-
</div>
81-
to the top of the page you want to debug.
73+
<div id="intro">
74+
<img src="icons/128.png" alt="" class="logo">
75+
<h2 class="title">
76+
Waiting for connection...
77+
</h2>
78+
<div class="content">
79+
<div class="content-row">
80+
<label for="script-localhost">Add</label>
81+
<input type="text" id="script-localhost">
82+
</div>
83+
<div class="content-row">
84+
<label for="script-byip">Or</label>
85+
<input type="text" id="script-byip">
8286
</div>
87+
to the top of the page you want to debug.
8388
</div>
8489
</div>
90+
<div id="app">
91+
</div>
8592
<script>
8693
const port = process.env.PORT || 8098
8794
const localIp = require('ip').address();
8895
const $ = document.querySelector.bind(document)
8996

9097
const $localhost = $('#script-localhost')
9198
const $byIp = $('#script-byip')
92-
const $intro = $('#intro')
9399

94100
$localhost.value = '<' + 'script src="http://localhost:' + port + '"><' + '/script>'
95101
$byIp.value = '<' + 'script src="http://' + localIp + ':' + port + '"><' + '/script>'

shells/electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "vue-remote-devtools",
2+
"name": "@vue/devtools",
33
"version": "0.0.1",
44
"description": "StandAlone vue-devtools",
55
"repository": {

shells/electron/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ app.get('/', function (req, res) {
1414

1515
// Middleman
1616
io.on('connection', function (socket) {
17+
// Disconnect any previously connected apps
18+
socket.broadcast.emit('vue-devtools-disconnect-backend')
19+
20+
socket.on('disconnect', (reason) => {
21+
if (reason.indexOf('client')) {
22+
socket.broadcast.emit('vue-devtools-disconnect-devtools')
23+
}
24+
})
25+
1726
socket.on('vue-message', data => {
1827
socket.broadcast.emit('vue-message', data)
1928
})

shells/electron/src/backend.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import io from 'socket.io-client'
22
import { initBackend } from 'src/backend'
33
import Bridge from 'src/bridge'
4+
import { installToast } from 'src/backend/toast'
5+
6+
const connectedMessage = () => {
7+
if (window.__VUE_DEVTOOLS_TOAST__) {
8+
window.__VUE_DEVTOOLS_TOAST__('Remote Devtools Connected', 'normal')
9+
}
10+
}
11+
12+
const disconnectedMessage = () => {
13+
if (window.__VUE_DEVTOOLS_TOAST__) {
14+
window.__VUE_DEVTOOLS_TOAST__('Remote Devtools Disconnected', 'error')
15+
}
16+
}
417

518
(function () {
619
const port = process.env.PORT || 8098
@@ -9,6 +22,10 @@ import Bridge from 'src/bridge'
922
const bridge = new Bridge({
1023
listen (fn) {
1124
socket.on('vue-message', data => fn(data))
25+
socket.on('vue-devtools-disconnect-backend', () => {
26+
socket.disconnect()
27+
disconnectedMessage()
28+
})
1229
},
1330
send (data) {
1431
socket.emit('vue-message', data)
@@ -17,8 +34,11 @@ import Bridge from 'src/bridge'
1734

1835
bridge.on('shutdown', () => {
1936
socket.disconnect()
37+
disconnectedMessage()
2038
})
2139

40+
installToast(window)
2241
initBackend(bridge)
2342
socket.emit('vue-devtools-init')
43+
connectedMessage()
2444
}())

shells/electron/src/devtools.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import Bridge from 'src/bridge'
44

55
const port = process.env.PORT || 8098
66
const socket = io('http://localhost:' + port)
7+
const $ = document.querySelector.bind(document)
8+
const $intro = $('#intro')
79

810
let reload = null
911

12+
socket.on('vue-devtools-disconnect-devtools', () => {
13+
$intro.classList.remove('hidden')
14+
})
15+
1016
socket.on('vue-devtools-init', () => {
17+
socket.off('vue-message')
18+
$intro.classList.add('hidden')
19+
1120
// If new page is opened reload devtools
1221
if (reload) return reload()
1322

0 commit comments

Comments
 (0)