33 */
44
55import { ipcMain , dialog , BrowserWindow } from 'electron' ;
6- import { setConfiguredOutputPath , getConfiguredOutputPath } from '../state' ;
6+ import { setConfiguredOutputDir , getConfiguredOutputDir } from '../state' ;
7+ import { loadConfig , saveConfig } from '../state' ;
8+ import type { UserConfig } from '../state' ;
79
810/**
911 * Register dialog-related IPC handlers
@@ -14,31 +16,29 @@ export function registerDialogHandlers(
1416) : void {
1517 ipcMain . handle ( 'select-output-path' , async ( ) => {
1618 const mainWindow = getMainWindow ( ) ;
17- const result = await dialog . showSaveDialog ( mainWindow ! , {
18- title : 'Save Recording' ,
19- defaultPath : `recording_${ Date . now ( ) } .mp4` ,
20- filters : [
21- { name : 'Video Files' , extensions : [ 'mp4' , 'mov' ] } ,
22- { name : 'All Files' , extensions : [ '*' ] } ,
23- ] ,
19+ const currentDir = getConfiguredOutputDir ( ) ;
20+ const result = await dialog . showOpenDialog ( mainWindow ! , {
21+ title : 'Select Save Location' ,
22+ defaultPath : currentDir || undefined ,
23+ properties : [ 'openDirectory' , 'createDirectory' ] ,
2424 } ) ;
2525
26- if ( result . canceled ) {
26+ if ( result . canceled || ! result . filePaths || result . filePaths . length === 0 ) {
2727 return null ;
2828 }
2929
30- // Store the configured output path
31- setConfiguredOutputPath ( result . filePath || null ) ;
32- return result . filePath ;
30+ const dir = result . filePaths [ 0 ] ;
31+ setConfiguredOutputDir ( dir ) ;
32+ return dir ;
3333 } ) ;
3434
35- ipcMain . handle ( 'set-output-path' , async ( _ , path : string | null ) => {
36- setConfiguredOutputPath ( path ) ;
35+ ipcMain . handle ( 'set-output-path' , async ( _ , dir : string | null ) => {
36+ setConfiguredOutputDir ( dir ) ;
3737 return { success : true } ;
3838 } ) ;
3939
4040 ipcMain . handle ( 'get-output-path' , async ( ) => {
41- return getConfiguredOutputPath ( ) ;
41+ return getConfiguredOutputDir ( ) ;
4242 } ) ;
4343
4444 ipcMain . handle ( 'select-video-file' , async ( ) => {
@@ -76,4 +76,15 @@ export function registerDialogHandlers(
7676
7777 return result . filePaths [ 0 ] ;
7878 } ) ;
79+
80+ ipcMain . handle ( 'get-user-config' , async ( ) => {
81+ return loadConfig ( ) ;
82+ } ) ;
83+
84+ ipcMain . handle ( 'set-user-config' , async ( _ , partial : Partial < UserConfig > ) => {
85+ const config = loadConfig ( ) ;
86+ Object . assign ( config , partial ) ;
87+ saveConfig ( config ) ;
88+ return { success : true } ;
89+ } ) ;
7990}
0 commit comments