@@ -18,7 +18,6 @@ function createWindow() {
18
18
height : 600 ,
19
19
useContentSize : true ,
20
20
webPreferences : {
21
- // JAIME: i tried adding these two below to make window.require('fs') work
22
21
// nodeIntegration: true,
23
22
// contextIsolation: false,
24
23
contextIsolation : true ,
@@ -85,11 +84,6 @@ if (mainWindow) {
85
84
console . log ( "jsonFile is" , jsonFile ) ;
86
85
return { jsonFile } ;
87
86
}
88
-
89
- //Kevin: I think calling readFileSync here in electron main is actually what we're supposed to do
90
- //and then we send the received data back to Import
91
- //because in here, readFileSync should be a function that has access to the res data
92
-
93
87
} ) ;
94
88
95
89
@@ -105,6 +99,16 @@ ipcMain.handle("exportProject", async (event, options) => {
105
99
return { filePath } ;
106
100
} ) ;
107
101
102
+ ipcMain . handle ( "useExportComponent" , async ( event , options ) => {
103
+ const { dialog } = require ( "electron" ) ;
104
+ const { filePath } = await dialog . showSaveDialog ( options ) ;
105
+ if ( filePath === "" ) {
106
+ throw new Error ( "No file path selected" ) ;
107
+ }
108
+ return { filePath } ;
109
+ } ) ;
110
+
111
+
108
112
ipcMain . handle ( 'writeFile' , async ( event , filePath , content ) => { //possibly merge this with 'writeJSON' handle
109
113
// console.log('writeFile filePath:', filePath, '\n content:', content);
110
114
console . log ( "writeFile filePath:" , filePath ) ;
@@ -117,32 +121,19 @@ ipcMain.handle('writeFile', async (event, filePath, content) => { //possibly mer
117
121
} ) ;
118
122
console . log ( 'finished fs.writeSync' )
119
123
return { status : "success" } ;
120
- // return new Promise(async (resolve, reject) => {
121
- // await fs.writeFile(filePath, content, (err) => {
122
- // if (err) {
123
- // reject(err);
124
- // } else {
125
- // resolve("File written successfully");
126
- // }
127
- // });
128
- // });
124
+
129
125
} ) ;
130
126
131
- // ipcMain.handle('existSync',(event, { path }) => {
132
- // return fs.existsSync(path)
133
- // });
127
+
134
128
135
129
ipcMain . handle ( 'check-file-exists' , async ( event , path ) => {
136
130
const fileExists = await fs . existsSync ( path ) ;
137
131
console . log ( "fileExists" , fileExists ) ;
138
-
139
132
if ( fileExists ) return { status : true } ;
140
133
return { status : false } ;
141
134
} ) ;
142
135
143
136
ipcMain . handle ( 'mkdirSync' , async ( event , args : string [ ] ) => {
144
- console . log ( 'about to make new directory' )
145
- console . log ( "args" , args ) ;
146
137
const mkdirPath = await path . join ( ...args ) ;
147
138
console . log ( "mkdirPath" , mkdirPath ) ;
148
139
await fs . mkdirSync ( mkdirPath ) ;
@@ -151,10 +142,7 @@ ipcMain.handle('mkdirSync', async (event, args: string[] ) => {
151
142
} ) ;
152
143
153
144
ipcMain . handle ( 'pathJoin' , ( event , ...args : any [ ] ) => { //should expect args and output to be string
154
- // for(const arg:any of [...args])
155
- console . log ( 'pathJoin args:' , ...args ) ;
156
145
const newPath :string = path . join ( ...args ) ;
157
- console . log ( 'newPath' , newPath )
158
146
return newPath ; //return string directly instead of object
159
147
} ) ;
160
148
0 commit comments