Skip to content

Commit 6cae3fa

Browse files
feat(overmind-devtools): electron 8 with heartbeat
1 parent 349811d commit 6cae3fa

File tree

8 files changed

+82
-86
lines changed

8 files changed

+82
-86
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"axios": "0.19.0",
3131
"color": "3.0.0",
3232
"color-hash": "1.0.3",
33-
"electron": "7.1.9",
34-
"electron-json-storage": "4.1.0",
35-
"electron-prompt": "1.3.1",
33+
"electron": "^8.0.0",
34+
"electron-json-storage": "^4.1.8",
35+
"electron-prompt": "^1.5.1",
3636
"emotion": "9.2.12",
3737
"express": "4.16.3",
3838
"graphql": "14.5.8",

packages/node_modules/overmind-devtools-client/DevtoolBackend.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class DevtoolBackend {
6262
const parsedMessage = JSON.parse(message)
6363

6464
switch (parsedMessage.type) {
65+
case 'ping':
66+
this.devtoolSocket.send(
67+
JSON.stringify({
68+
type: 'pong'
69+
})
70+
)
71+
break
6572
case 'storage:get':
6673
this.evaluateDevtoolMessage(parsedMessage, () =>
6774
this.options.storage.get(parsedMessage.data.key)

packages/node_modules/overmind-devtools-client/src/BackendConnector.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class WebsocketConnector {
1515
private socket: WebSocket
1616
private messagesBeforeConnected: Array<[string, any, any]> = []
1717
private isOpen = false
18-
18+
private schedulePing () {
19+
setTimeout(() => {
20+
this.send('ping')
21+
}, 1000 * 30)
22+
}
1923
public connect(
2024
port: string | number // TODO: return Promise so we can wait for it
2125
) {
@@ -28,7 +32,11 @@ class WebsocketConnector {
2832
this.socket.onmessage = (message) => {
2933
const parsedMessage = JSON.parse(message.data)
3034

31-
this.emit(parsedMessage.type, parsedMessage.data)
35+
if (parsedMessage.type === 'pong') {
36+
this.schedulePing()
37+
} else {
38+
this.emit(parsedMessage.type, parsedMessage.data)
39+
}
3240
}
3341
this.socket.onopen = () => {
3442
resolve()
@@ -37,6 +45,7 @@ class WebsocketConnector {
3745
this.send(...message)
3846
})
3947
this.messagesBeforeConnected.length = 0
48+
this.schedulePing()
4049
}
4150
this.socket.onclose = (reason) => {
4251
console.log("Socket closed", reason)
@@ -91,6 +100,7 @@ export class BackendConnector extends WebsocketConnector {
91100
onMessage = (onMessage: MessageCallback) => {
92101
this.on('message', (message) => {
93102
onMessage(message)
103+
94104
})
95105
}
96106
onDisconnect = (onDisconnect: (name: string) => void) => {

packages/node_modules/overmind-devtools-client/src/overmind/actions.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import {
22
Action,
3-
pipe,
4-
Operator,
53
AsyncAction,
6-
mutate,
4+
Operator,
75
debounce,
6+
mutate,
7+
pipe,
88
wait,
99
} from 'overmind'
10+
11+
import * as o from './operators'
1012
import {
11-
Message,
12-
Tab,
13-
ExecutionType,
1413
ActionsListItemType,
1514
Component,
15+
ExecutionType,
16+
Message,
17+
Tab,
1618
} from './types'
17-
import * as o from './operators'
18-
import { isValidJson, createApp, getActionId } from './utils'
19+
import { createApp, getActionId, isValidJson } from './utils'
1920

2021
export const onMessage: Operator<Message> = pipe(
2122
o.ensureCurrentApp(),

packages/node_modules/overmind-devtools-client/src/overmind/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export enum ExecutionType {
223223
}
224224

225225
export enum AppMessageType {
226-
PORT_EXISTS = 'PORT_EXISTS',
226+
PORT_EXISTS = 'PORT_EXISTS'
227227
}
228228

229229
export type AppMessage<T> = {

packages/node_modules/overmind-devtools/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"dependencies": {
2121
"color": "^3.0.0",
2222
"color-hash": "^1.0.3",
23-
"electron": "^7.1.9",
24-
"electron-json-storage": "^4.1.0",
25-
"electron-prompt": "^1.3.1",
23+
"electron": "^8.0.0",
24+
"electron-json-storage": "^4.1.8",
25+
"electron-prompt": "^1.5.1",
2626
"overmind-devtools-client": "next",
2727
"ws": "^7.0.0"
2828
},

packages/node_modules/overmind-devtools/src/main.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ function createWindow() {
1717
minWidth: 500,
1818
})
1919

20-
electron.protocol.registerFileProtocol('filestub', (request, callback) => {
21-
const url = request.url.substr(10)
22-
const file = { path: path.normalize(`${path.join(__dirname, '..')}/${url}`) }
23-
24-
callback(file)
25-
})
26-
2720
const devtoolBackend = DevtoolBackend.create({
2821
onRelaunch() {
2922
app.relaunch()
@@ -78,6 +71,7 @@ function createWindow() {
7871
}
7972
)
8073
} else {
74+
console.log("y0!")
8175
mainWindow.loadURL('http://localhost:8080')
8276
mainWindow.webContents.openDevTools()
8377
}
@@ -100,10 +94,7 @@ function createWindow() {
10094
onPortSubmit,
10195
onRestart
10296
)
103-
),
104-
{
105-
baseURLForDataURL: `file://${path.resolve()}/devtoolsDist/`,
106-
}
97+
)
10798
)
10899
})
109100
})
@@ -168,22 +159,6 @@ function createWindow() {
168159
)
169160

170161
startDevtoolBackend().then(openDevtools)
171-
172-
/*
173-
BUG FIX: https://github.com/electron/electron/issues/13008#issuecomment-575909942
174-
*/
175-
let redirectURL = 'data:application/x-javascript;base64,UHJvZHVjdFJlZ2lzdHJ5SW1wbC5SZWdpc3RyeT1jbGFzc3tjb25zdHJ1Y3Rvcigpe31uYW1lRm9yVXJsKHIpe3JldHVybiBudWxsfWVudHJ5Rm9yVXJsKHIpe3JldHVybiBudWxsfXR5cGVGb3JVcmwocil7cmV0dXJuIG51bGx9fSxQcm9kdWN0UmVnaXN0cnlJbXBsLl9oYXNoRm9yRG9tYWluPWZ1bmN0aW9uKHIpe3JldHVybiIifSxQcm9kdWN0UmVnaXN0cnlJbXBsLnJlZ2lzdGVyPWZ1bmN0aW9uKHIsdCl7UHJvZHVjdFJlZ2lzdHJ5SW1wbC5fcHJvZHVjdHNCeURvbWFpbkhhc2g9bmV3IE1hcH0sUHJvZHVjdFJlZ2lzdHJ5SW1wbC5fcHJvZHVjdHNCeURvbWFpbkhhc2g9bmV3IE1hcCxQcm9kdWN0UmVnaXN0cnlJbXBsLnJlZ2lzdGVyKFtdLFtdKSxQcm9kdWN0UmVnaXN0cnlJbXBsLnNoYTE9ZnVuY3Rpb24ocil7cmV0dXJuIiJ9Ow==';
176-
electron.session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
177-
if ((/^devtools:\/\/devtools\/remote\/serve_file\/@[0-9a-f]{40}\/product_registry_impl\/product_registry_impl_module.js$/ui).test(details.url)) {
178-
// eslint-disable-next-line
179-
callback({
180-
redirectURL
181-
});
182-
return;
183-
}
184-
// eslint-disable-next-line
185-
callback({});
186-
});
187162
}
188163

189164
// This method will be called when Electron has finished

0 commit comments

Comments
 (0)