Skip to content

Commit f96b41e

Browse files
committed
added promise chain to create-env-file to trigger listener in welcome
1 parent cebc29c commit f96b41e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

main.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function createWindow() {
3535
// Add event listener to set our global window variable to null
3636
// This is needed so that window is able to reopen when user relaunches the app
3737
win.on('closed', () => {
38+
//added to overwrite .env with null every time window is closed so new import can work
39+
fs.writeFileSync(path.join(__dirname, '/.env'), "", 'utf8');
3840
win = null;
3941
});
4042

@@ -209,14 +211,14 @@ ipcMain.on('import-tables', (event, env) => {
209211
let tables;
210212
pgQuery(tables)
211213
.then((tables) => {
212-
console.log("tables (main):", tables)
214+
// console.log("tables (main):", tables)
213215
event.reply('tables-imported', tables)
214216
})
215217
.catch(err => console.error("Error importing tables from postgres"))
216218
})
217219
//--------------------- CREATE ENV FILE -------------------//
218220

219-
function createEnvFile(env) {
221+
async function createEnvFile(env) {
220222
try {
221223
fs.writeFileSync(path.join(__dirname, '/.env'), env, 'utf8')
222224
} catch (err) {
@@ -225,8 +227,15 @@ function createEnvFile(env) {
225227
}
226228

227229
ipcMain.on('create-env-file', (event, env) => {
228-
console.log(env);
229-
createEnvFile(env);
230+
console.log('create env file URI: ', env);
231+
createEnvFile(env)
232+
.then(res => {
233+
event.reply('env-file-created');
234+
console.log('env-file-created')
235+
})
236+
.catch(err => {
237+
console.log('error occurred in createEnvFile promise')
238+
})
230239
});
231240

232241
//--------------------- MENU CUSTOMIZATION -------------------//

0 commit comments

Comments
 (0)