1
1
const { app, BrowserWindow, Menu, ipcMain, dialog } = require ( 'electron' )
2
2
const Micropython = require ( 'micropython-ctl-cont' ) . MicroPythonDevice
3
+ const { SerialPort } = require ( 'serialport' )
3
4
const path = require ( 'path' )
4
5
const fs = require ( 'fs' )
5
6
const openAboutWindow = require ( 'about-window' ) . default
@@ -42,7 +43,7 @@ function ilistFolder(folder) {
42
43
}
43
44
44
45
// LOCAL FILE SYSTEM ACCESS
45
- ipcMain . handle ( 'open-folder' , async ( event ) => {
46
+ ipcMain . handle ( 'disk- open-folder' , async ( event ) => {
46
47
console . log ( 'ipcMain' , 'open-folder' )
47
48
const folder = await openFolderDialog ( )
48
49
let files = [ ]
@@ -52,31 +53,31 @@ ipcMain.handle('open-folder', async (event) => {
52
53
return { folder, files }
53
54
} )
54
55
55
- ipcMain . handle ( 'list-files' , async ( event , folder ) => {
56
+ ipcMain . handle ( 'disk- list-files' , async ( event , folder ) => {
8000
56
57
console . log ( 'ipcMain' , 'list-files' , folder )
57
58
if ( ! folder ) return [ ]
58
59
return listFolder ( folder )
59
60
} )
60
61
61
- ipcMain . handle ( 'ilist-files' , async ( event , folder ) => {
62
+ ipcMain . handle ( 'disk- ilist-files' , async ( event , folder ) => {
62
63
console . log ( 'ipcMain' , 'ilist-files' , folder )
63
64
if ( ! folder ) return [ ]
64
65
return ilistFolder ( folder )
65
66
} )
66
67
67
- ipcMain . handle ( 'load-file' , ( event , filePath ) => {
68
+ ipcMain . handle ( 'disk- load-file' , ( event , filePath ) => {
68
69
console . log ( 'ipcMain' , 'load-file' , filePath )
69
70
let content = fs . readFileSync ( filePath )
70
71
return content
71
72
} )
72 73
73
- ipcMain . handle ( 'save-file' , ( event , filePath , content ) => {
74
+ ipcMain . handle ( 'disk- save-file' , ( event , filePath , content ) => {
74
75
console . log ( 'ipcMain' , 'save-file' , filePath , content )
75
76
fs . writeFileSync ( filePath , content , 'utf8' )
76
77
return true
77
78
} )
78
79
79
- ipcMain . handle ( 'update-folder' , ( event , folder ) => {
80
+ ipcMain . handle ( 'disk- update-folder' , ( event , folder ) => {
80
81
console . log ( 'ipcMain' , 'update-folder' , folder )
81
82
let files = fs . readdirSync ( path . resolve ( folder ) )
82
83
// Filter out directories
@@ -87,13 +88,13 @@ ipcMain.handle('update-folder', (event, folder) => {
87
88
return { folder, files }
88
89
} )
89
90
90
- ipcMain . handle ( 'remove-file' , ( event , filePath ) => {
91
+ ipcMain . handle ( 'disk- remove-file' , ( event , filePath ) => {
91
92
console . log ( 'ipcMain' , 'remove-file' , filePath )
92
93
fs . unlinkSync ( filePath )
93
94
return true
94
95
} )
95
96
96
- ipcMain . handle ( 'rename-file' , ( event , filePath , newFilePath ) => {
97
+ ipcMain . handle ( 'disk- rename-file' , ( event , filePath , newFilePath ) => {
97
98
console . log ( 'ipcMain' , 'rename-file' , filePath , newFilePath )
98
99
fs . renameSync ( filePath , newFilePath )
99
100
return true
@@ -103,12 +104,7 @@ ipcMain.handle('rename-file', (event, filePath, newFilePath) => {
103
104
const board = new Micropython ( )
104
105
ipcMain . handle ( 'serial-list-ports' , ( event ) => {
105
106
console . log ( 'ipcMain' , 'serial-list-ports' )
106
- return [
107
- { path : '/dev/ttyACM0' } ,
108
- { path : '/dev/ttyACM1' } ,
109
- { path : '/dev/ttyUSB0' } ,
110
- { path : '/dev/ttyUSB1' } ,
111
- ]
107
+ return SerialPort . list ( )
112
108
} )
113
109
ipcMain . handle ( 'serial-connect' , async ( event , path ) => {
114
110
console . log ( 'ipcMain' , 'serial-connect' , path )
@@ -134,11 +130,12 @@ ipcMain.handle('serial-run', async (event, code) => {
134
130
disableDedent : true ,
135
131
broadcastOutputAsTerminalData : true
136
132
} )
133
+ board . sendData ( '\r\n' )
134
+ return Promise . resolve ( output )
137
135
} catch ( err ) {
138
136
console . log ( err )
137
+ return Promise . reject ( err )
139
138
}
140
- board . sendData ( '\r\n' )
141
- return Promise . resolve ( output )
142
139
} )
143
140
ipcMain . handle ( 'serial-stop' , async ( event ) => {
144
141
console . log ( 'ipcMain' , 'serial-stop' )
@@ -170,10 +167,9 @@ ipcMain.handle('serial-ilist-files', async (event, folder) => {
170
167
console . log ( 'ipcMain' , 'serial-ilist-files' , folder )
171
168
let files = await board . listFiles ( folder )
172
169
files = files . map ( f => ( {
173
- path : f . filename . slice ( 1 ) ,
170
+ path : f . filename . split ( '/' ) . pop ( ) ,
174
171
type : f . isDir ? 'folder' : 'file'
175
172
} ) )
176
- // console.log('yolo', files)
177
173
return files
178
174
} )
179
175
ipcMain . handle ( 'serial-load-file' , async ( event , filePath ) => {
@@ -214,7 +210,7 @@ ipcMain.handle('serial-create-folder', async (event, folder) => {
214
210
215
211
216
212
// WINDOW MANAGEMENT
217
- ipcMain . handle ( 'set-window -size' , ( event , minWidth , minHeight ) => {
213
+ ipcMain . handle ( 'window- set-minimum -size' , ( event , minWidth , minHeight ) => {
218
214
console . log ( 'ipcMain' , 'set-window-size' , minWidth , minHeight )
219
215
if ( ! win ) {
220
216
console . log ( 'No window defined' )
0 commit comments