-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprojectFile.js
51 lines (43 loc) · 1.32 KB
/
projectFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { dialog, BrowserWindow } = require('electron');
const fs = require('fs');
const path = require('path');
function openProjectRequest(parent) {
const result = dialog.showOpenDialogSync(parent, {
properties: ['openFile'],
title: 'Open project file...',
filters: [{ name: 'Project file (*.rpe)', extensions: ['rpe'] }],
});
if (result !== undefined) {
return result[0];
}
return '';
}
function saveProjectRequest(parent) {
const folderPath = dialog.showSaveDialogSync(parent, {
title: 'Save project folder...',
defaultPath: 'project',
buttonLabel: 'Save Project Folder',
properties: ['createDirectory'],
});
if (folderPath) {
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
}
const folderName = path.basename(folderPath);
const projectFileName = `${folderName}.rpe`;
const projectFilePath = path.join(folderPath, projectFileName);
fs.writeFileSync(projectFilePath, '');
const currentWindow = BrowserWindow.getFocusedWindow();
if (currentWindow) {
currentWindow.setTitle(`${projectFileName} - Rapid Power Estimator`);
} else {
console.error('No focused window found to set title.');
}
return projectFilePath;
}
return '';
}
module.exports = {
openProjectRequest,
saveProjectRequest,
};