Skip to content

Commit 88ae5c3

Browse files
committed
feat: Added option to show the exported data
1 parent 16d964d commit 88ae5c3

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

electron/main/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ app.whenReady().then(()=>{
7272
const {filePath} = await dialog.showSaveDialog(win, {title: "Save Exported Data", defaultPath: `${formattedDate}`, filters: [{name: "XLSX File", extensions: ["xlsx"]}]})
7373
return filePath == "" ? null : filePath;
7474
})
75+
ipcMain.on("shell:showInFolder", (_event, path) => {
76+
shell.showItemInFolder(path);
77+
})
7578
createWindow();
7679
});
7780

electron/preload/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const writePort = async (data: string) => {
7575
const saveData = async () => {
7676
const path: string = await ipcRenderer.invoke('dialog:openSave')
7777
if (!path) {
78-
return { message: 'File Saving Canceled!', success: false }
78+
return { message: 'File Saving Canceled!', success: false, path: null }
7979
}
8080

8181
const workbook = new excelJS.Workbook();
@@ -114,9 +114,9 @@ const saveData = async () => {
114114

115115
try {
116116
await workbook.xlsx.writeFile(path);
117-
return { message: 'Data saved successfully', success: true };
117+
return { message: 'Data saved successfully', success: true, path: path };
118118
} catch (error) {
119-
return { message: `Error saving data`, success: false };
119+
return { message: `Error saving data`, success: false, path: null };
120120
}
121121
}
122122

@@ -233,6 +233,9 @@ const getPosition = () => {
233233
return position;
234234
}
235235

236+
const showSavedFile = (path: string) => {
237+
ipcRenderer.send("shell:showInFolder", path);
238+
}
236239

237240
ipcRenderer.on("close-port", () => {
238241
if (serialport) {
@@ -248,7 +251,8 @@ contextBridge.exposeInMainWorld("backend", {
248251
getStream,
249252
closeStream,
250253
getData,
251-
getPosition
254+
getPosition,
255+
showSavedFile
252256
})
253257

254258
// --------- Preload scripts loading ---------

src/App.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ function App() {
8686

8787
const exportData = async () => {
8888
const response = await window.backend.saveData()
89-
response.success ? toast.success(response.message) : toast.error(response.message)
89+
response.success ? toast(response.message, {
90+
action: {
91+
label: 'Show',
92+
onClick: () => window.backend.showSavedFile(response.path)
93+
},
94+
}) : toast.error(response.message)
9095
};
9196

9297
const postData = async () => {

src/vite-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface Window {
4242
saveData: () => Promise<{
4343
message: string;
4444
success: boolean;
45+
path: string;
4546
}>;
4647
getStream: (port: string) => Promise<void>;
4748
closeStream: () => void;
@@ -51,5 +52,6 @@ interface Window {
5152
y: number;
5253
z: number;
5354
};
55+
showSavedFile: (path: string) => void;
5456
};
5557
}

0 commit comments

Comments
 (0)