Skip to content

Commit 6193bba

Browse files
Shanon LeeShanon Lee
authored andcommitted
FUNCTIONAL ExportProject component using ipcRenderer.invoke and ipcMain.handle. OK in dev mode and build mode
1 parent 8965519 commit 6193bba

File tree

6 files changed

+577
-23
lines changed

6 files changed

+577
-23
lines changed

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"core-js": "^3.6.5",
2222
"dotenv": "^10.0.0",
2323
"electron-deeplink": "^1.0.9",
24+
"fs-extra": "^10.0.0",
2425
"localforage": "^1.10.0",
2526
"lodash.clonedeep": "^4.5.0",
2627
"lodash.isequal": "^4.5.0",

src-electron/electron-main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, nativeTheme } from 'electron';
1+
import { app, BrowserWindow, nativeTheme, dialog, ipcMain } from 'electron';
22
import { Deeplink } from "electron-deeplink";
33
import isDev from 'electron-is-dev';
44
import path from 'path';
@@ -38,6 +38,13 @@ if (process.env.PROD) {
3838
});
3939
}
4040

41+
// ******************* Handling dialogs for ExportProject *********************
42+
ipcMain.handle('exportProject', async (event, arg) => {
43+
const result = await dialog.showSaveDialog(arg)
44+
return result;
45+
})
46+
47+
// ************** Slack OAuth functions **********************
4148
// Sends request to Slack for User's information,
4249
// then sends user information back to renderer process
4350
function slackErrorHandler(err) {
@@ -120,8 +127,6 @@ function setOauthListener() {
120127
});
121128
}
122129

123-
124-
// ********************* Default *****************
125130
function createWindow () {
126131
/**
127132
* Initial window options

src-electron/electron-preload.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,32 @@
1717
*/
1818

1919

20-
const {ipcRenderer, shell, contextBridge} = require('electron');
20+
const {ipcRenderer, shell, contextBridge} = require('electron');
21+
const path = require('path');
22+
const fs = require('fs-extra');
23+
2124
// ipcRenderer contextBridge
25+
// on: used in SlackLoginWindow
26+
//
2227
contextBridge.exposeInMainWorld("ipcRenderer",{
23-
on: (channel, func) => ipcRenderer.on(
24-
channel,
25-
(event, ...args) => func(args)
26-
)
28+
on: (channel, func) => ipcRenderer.on(channel,(event, ...args) => func(args)),
29+
invoke: async (channel, ...args) => await ipcRenderer.invoke(channel, ...args)
2730
});
2831

32+
// shell, used in SlackLoginWindow
2933
contextBridge.exposeInMainWorld("shell", {
3034
openExternal: (url, options) => shell.openExternal(url, options)
31-
})
35+
})
36+
37+
// fs from fs-extra, used in ExportProject
38+
contextBridge.exposeInMainWorld("fs", {
39+
writeFileSync: (file, data, options) => fs.writeFileSync(file, data, options),
40+
existsSync: (data) => fs.existsSync(data),
41+
mkdirSync: (data) => fs.mkdirSync(data)
42+
})
43+
44+
// Exposing path module
45+
contextBridge.exposeInMainWorld("path", {
46+
join: (...paths) => path.join(...paths)
47+
})
48+

0 commit comments

Comments
 (0)