File tree Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' )
2
- const Serial = require ( './serial.js' )
3
- let serial
4
2
const registerMenu = require ( './menu.js' )
3
+ const serial = require ( './serial.js' ) . sharedInstance
5
4
6
5
const {
7
6
openFolderDialog,
@@ -11,7 +10,7 @@ const {
11
10
} = require ( './helpers.js' )
12
11
13
12
module . exports = function registerIPCHandlers (
8000
win , ipcMain , app , dialog ) {
14
- serial = new Serial ( win )
13
+ serial . win = win // Required to send callback messages to renderer
15
14
16
15
ipcMain . handle ( 'open-folder' , async ( event ) => {
17
16
console . log ( 'ipcMain' , 'open-folder' )
Original file line number Diff line number Diff line change 1
1
const { app, Menu } = require ( 'electron' )
2
2
const path = require ( 'path' )
3
- const Serial = require ( './serial.js' )
3
+ const serial = require ( './serial.js' ) . sharedInstance
4
4
const openAboutWindow = require ( 'about-window' ) . default
5
5
const shortcuts = require ( './shortcuts.js' )
6
6
const { type } = require ( 'os' )
@@ -128,7 +128,7 @@ module.exports = function registerMenu(win, state = {}) {
128
128
accelerator : '' ,
129
129
click : async ( ) => {
130
130
try {
131
- await Serial . disconnect ( )
131
+ await serial . disconnect ( )
132
132
win . reload ( )
133
133
} catch ( e ) {
134
134
console . error ( 'Reload from menu failed:' , e )
Original file line number Diff line number Diff line change 1
1
const MicroPython = require ( 'micropython.js' )
2
2
3
3
class Serial {
4
- constructor ( win ) {
4
+ constructor ( win = null ) {
5
5
this . win = win
6
6
this . board = new MicroPython ( )
7
7
this . board . chunk_size = 192
@@ -110,4 +110,6 @@ except OSError:
110
110
}
111
111
}
112
112
113
- module . exports = Serial
113
+ const sharedInstance = new Serial ( )
114
+
115
+ module . exports = { sharedInstance, Serial}
You can’t perform that action at this time.
0 commit comments