Skip to content

Commit 1e61960

Browse files
Kelementz916RoderickXiirobsinzDanielGaran02anthonyHerr
authored
Fixed export functionality (#7)
* Solved import fx Co-authored-by: Kevin Can <[email protected]> Co-authored-by: rob sinz <[email protected]> Co-authored-by: DanielGaran02 <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> * git commit -m "updated index.ts Co-authored-by: Daniel Garan <[email protected]> Co-authored-by: Kevin Can <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> Co-authored-by: Rob Sinzieri <[email protected]> Co-authored-by: Roderick de Leon <[email protected]>" * switching to new branch * adjusted existSync to checkFileExists * Refactor exportProject and writeFile handlers * created console.logs for Kevin to view Co-authored-by: Anthony Herrera <[email protected]> * updated async functions in ExportMenu and Electron Main Co-authored-by: Kevin Can <[email protected]> * "fixed export button functionality Co-authored-by: Daniel Garan <[email protected]> Co-authored-by: Kevin Can <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> Co-authored-by: Rob Sinzieri <[email protected]> Co-authored-by: Roderick de Leon <[email protected]>"" * Fixed save, import, and export functionality. Added Composition API to states Co-authored-by: Daniel Garan <[email protected]> Co-authored-by: Kevin Can <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> Co-authored-by: Rob Sinzieri <[email protected]> Co-authored-by: Roderick de Leon <[email protected]> --------- Co-authored-by: Roderick de Leon <[email protected]> Co-authored-by: Kevin Can <[email protected]> Co-authored-by: rob sinz <[email protected]> Co-authored-by: DanielGaran02 <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> Co-authored-by: Daniel Garan <[email protected]> Co-authored-by: Anthony Herrera <[email protected]> Co-authored-by: Rob Sinzieri <[email protected]>
1 parent 5472490 commit 1e61960

File tree

11 files changed

+2232
-1975
lines changed

11 files changed

+2232
-1975
lines changed

package-lock.json

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

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "overvue",
3-
"version": "10.0.0",
3+
"version": "11.0.0",
44
"main": "dist/electron/UnPackaged/electron-main.js",
55
"description": "Vue Prototype DevTool",
66
"productName": "OverVue",
@@ -72,8 +72,7 @@
7272
"vue3-tree": "^0.11.0",
7373
"vued3tree": "^5.1.0",
7474
"vuedraggable": "^4.1.0",
75-
"vuetensils": "^0.13.2",
76-
"vuex": "^4.0.2"
75+
"vuetensils": "^0.13.2"
7776
},
7877
"devDependencies": {
7978
"@babel/eslint-parser": "^7.17.0",
@@ -99,7 +98,7 @@
9998
},
10099
"browser": {
101100
"crypto": false
102-
},
101+
},
103102
"browserslist": [
104103
"last 10 Chrome versions",
105104
"last 10 Firefox versions",
@@ -111,9 +110,9 @@
111110
"last 10 iOS versions",
112111
"last 5 Opera versions"
113112
],
114-
"engines": {
115-
"node": ">= 16.13.0",
116-
"npm": ">= 8.1.0",
117-
"yarn": ">= 1.22.10"
118-
}
113+
"engines": {
114+
"node": ">= 16.13.0",
115+
"npm": ">= 8.1.0",
116+
"yarn": ">= 1.22.10"
117+
}
119118
}

src-electron/electron-main.ts

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function createWindow() {
1818
height: 600,
1919
useContentSize: true,
2020
webPreferences: {
21+
// JAIME: i tried adding these two below to make window.require('fs') work
22+
// nodeIntegration: true,
23+
// contextIsolation: false,
2124
contextIsolation: true,
2225
// More info: https://v2.quasar.dev/quasar-cli-webpack/developing-electron-apps/electron-preload-script
2326
preload: path.resolve(__dirname, process.env.QUASAR_ELECTRON_PRELOAD),
@@ -63,40 +66,95 @@ ipcMain.handle('showSaveDialog', async (event, options) => {
6366
return { filePath };
6467
});
6568

66-
ipcMain.handle('writeFile', async (event, { filePath, data }) => {
69+
ipcMain.handle('writeJSON', async (event, { filePath, data }) => {
6770
fs.writeFileSync(filePath, data);
6871
});
6972

70-
// //handler for Import
73+
//handler for Import
74+
7175
ipcMain.handle('openProject', async (event, options) => {
7276
if (mainWindow) {
7377
//{ filePaths } destructured comes fromdialog.showOpenDialog() function.
74-
const { filePaths } = await dialog.showOpenDialog(mainWindow, options);
75-
return { filePaths };
78+
const { filePaths } = await dialog.showOpenDialog(mainWindow, options);
79+
80+
console.log("filePaths from main is", filePaths);
81+
if (!filePaths) return;
82+
const readData = await fs.readFileSync(filePaths[0], "utf8");
83+
console.log("readData is", readData);
84+
const jsonFile = JSON.parse(readData);
85+
console.log("jsonFile is", jsonFile);
86+
return { jsonFile };
7687
}
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+
7793
});
7894

79-
//START: OLD import code block below
80-
// try {
81-
// if (mainWindow) {
82-
// const { filePaths } = await dialog.showOpenDialog(mainWindow, options);
83-
// console.log('Import dialog result:', filePaths); // Log the filePaths
84-
// if (filePaths.length > 0) {
85-
// const data = fs.readFileSync(filePaths[0], 'utf8');
86-
// return JSON.parse(data); // Return the imported data
87-
// }
88-
// } else {
89-
// console.error('Main window is undefined');
90-
// }
91-
// } catch (error) {
92-
// console.error('Failed to import project:', error);
93-
// }
94-
//END
95-
96-
97-
// //handler for Export
95+
96+
97+
98+
//handlers for Export
9899
ipcMain.handle("exportProject", async (event, options) => {
99100
const { dialog } = require("electron");
100101
const { filePath } = await dialog.showSaveDialog(options);
102+
if (filePath === '') {
103+
throw new Error('No file path selected');
104+
}
101105
return { filePath };
102106
});
107+
108+
ipcMain.handle('writeFile', async (event, filePath, content) => { //possibly merge this with 'writeJSON' handle
109+
// console.log('writeFile filePath:', filePath, '\n content:', content);
110+
console.log("writeFile filePath:", filePath);
111+
await fs.writeFile(filePath, content, (err) => {
112+
if (err) {
113+
console.log(`${err} in fs.writeFile`);
114+
} else {
115+
console.log("File written successfully");
116+
}
117+
});
118+
console.log('finished fs.writeSync')
119+
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+
// });
129+
});
130+
131+
// ipcMain.handle('existSync',(event, { path }) => {
132+
// return fs.existsSync(path)
133+
// });
134+
135+
ipcMain.handle('check-file-exists', async (event, path) => {
136+
const fileExists = await fs.existsSync(path);
137+
console.log("fileExists", fileExists);
138+
139+
if (fileExists) return { status: true };
140+
return { status: false };
141+
});
142+
143+
ipcMain.handle('mkdirSync', async (event, args: string[] ) => {
144+
console.log('about to make new directory')
145+
console.log("args", args);
146+
const mkdirPath = await path.join(...args);
147+
console.log("mkdirPath", mkdirPath);
148+
await fs.mkdirSync(mkdirPath);
149+
console.log("finished making new directory");
150+
return { status: 'success' };
151+
});
152+
153+
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+
const newPath:string = path.join(...args);
157+
console.log('newPath', newPath)
158+
return newPath; //return string directly instead of object
159+
});
160+

0 commit comments

Comments
 (0)