Skip to content

Commit 041468f

Browse files
committed
Use shared instance of Serial in menu handler
1 parent 88e0bda commit 041468f

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

backend/ipc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs')
2-
const Serial = require('./serial.js')
3-
let serial
42
const registerMenu = require('./menu.js')
3+
const serial = require('./serial.js').sharedInstance
54

65
const {
76
openFolderDialog,
@@ -11,7 +10,7 @@ const {
1110
} = require('./helpers.js')
1211

1312
module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) {
14-
serial = new Serial(win)
13+
serial.win = win // Required to send callback messages to renderer
1514

1615
ipcMain.handle('open-folder', async (event) => {
1716
console.log('ipcMain', 'open-folder')

backend/menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { app, Menu } = require('electron')
22
const path = require('path')
3-
const Serial = require('./serial.js')
3+
const serial = require('./serial.js').sharedInstance
44
const openAboutWindow = require('about-window').default
55
const shortcuts = require('./shortcuts.js')
66
const { type } = require('os')
@@ -128,7 +128,7 @@ module.exports = function registerMenu(win, state = {}) {
128128
accelerator: '',
129129
click: async () => {
130130
try {
131-
await Serial.disconnect()
131+
await serial.disconnect()
132132
win.reload()
133133
} catch(e) {
134134
console.error('Reload from menu failed:', e)

backend/serial.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const MicroPython = require('micropython.js')
22

33
class Serial {
4-
constructor(win) {
4+
constructor(win = null) {
55
this.win = win
66
this.board = new MicroPython()
77
this.board.chunk_size = 192
@@ -110,4 +110,6 @@ except OSError:
110110
}
111111
}
112112

113-
module.exports = Serial
113+
const sharedInstance = new Serial()
114+
115+
module.exports = {sharedInstance, Serial}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy