1- const { dialog } = require ( 'electron' ) ;
1+ const { dialog, BrowserWindow } = require ( 'electron' ) ;
2+ const fs = require ( 'fs' ) ;
23const path = require ( 'path' ) ;
34
45function openProjectRequest ( parent ) {
@@ -14,16 +15,34 @@ function openProjectRequest(parent) {
1415}
1516
1617function saveProjectRequest ( parent ) {
17- let filename = dialog . showSaveDialogSync ( parent , {
18- properties : [ 'showOverwriteConfirmation' ] ,
19- title : 'Save project file... ' ,
20- filters : [ { name : ' Project file (*.rpe)' , extensions : [ 'rpe' ] } ] ,
21- defaultPath : 'project.rpe' ,
18+ const folderPath = dialog . showSaveDialogSync ( parent , {
19+ title : 'Save project folder...' ,
20+ defaultPath : 'project' ,
21+ buttonLabel : 'Save Project Folder' ,
22+ properties : [ 'createDirectory' ] ,
2223 } ) ;
23- if ( filename !== undefined ) {
24- if ( path . extname ( filename ) !== '.rpe' ) filename += '.rpe' ;
24+
25+ if ( folderPath ) {
26+ if ( ! fs . existsSync ( folderPath ) ) {
27+ fs . mkdirSync ( folderPath , { recursive : true } ) ;
28+ }
29+
30+ const folderName = path . basename ( folderPath ) ;
31+ const projectFileName = `${ folderName } .rpe` ;
32+ const projectFilePath = path . join ( folderPath , projectFileName ) ;
33+ fs . writeFileSync ( projectFilePath , '' ) ;
34+
35+ const currentWindow = BrowserWindow . getFocusedWindow ( ) ;
36+ if ( currentWindow ) {
37+ currentWindow . setTitle ( `${ projectFileName } - Rapid Power Estimator` ) ;
38+ } else {
39+ console . error ( 'No focused window found to set title.' ) ;
40+ }
41+
42+ return projectFilePath ;
2543 }
26- return filename === undefined ? '' : filename ;
44+
45+ return '' ;
2746}
2847
2948module . exports = {
0 commit comments