@@ -124,15 +124,28 @@ ipcMain.handle('fs:readDir', async (_event, dirPath: string) => {
124124 }
125125} )
126126
127- ipcMain . handle ( 'fs:readFunscript' , async ( _event , videoPath : string ) => {
127+ ipcMain . handle ( 'fs:readFunscript' , async ( _event , videoPath : string , scriptFolder ?: string ) => {
128128 const ext = path . extname ( videoPath )
129+ const baseName = path . basename ( videoPath , ext )
130+
131+ // 1. Check next to video file
129132 const scriptPath = videoPath . replace ( ext , '.funscript' )
130133 try {
131134 const content = fs . readFileSync ( scriptPath , 'utf-8' )
132135 return JSON . parse ( content )
133- } catch {
134- return null
136+ } catch { }
137+
138+ // 2. Fallback: check script storage folder
139+ if ( scriptFolder ) {
140+ try {
141+ const fallbackPath = path . join ( scriptFolder , baseName + '.funscript' )
142+ const content = fs . readFileSync ( fallbackPath , 'utf-8' )
143+ console . log ( '[Script] Found in script folder:' , fallbackPath )
144+ return JSON . parse ( content )
145+ } catch { }
135146 }
147+
148+ return null
136149} )
137150
138151ipcMain . handle ( 'fs:saveFunscript' , async ( _event , videoPath : string , data : string ) => {
@@ -641,13 +654,15 @@ ipcMain.handle('eroscripts:fetch', async (_event, url: string) => {
641654 }
642655} )
643656
644- ipcMain . handle ( 'eroscripts:download' , async ( _event , url : string ) => {
657+ ipcMain . handle ( 'eroscripts:download' , async ( _event , url : string , scriptFolder ?: string , saveName ?: string ) => {
645658 try {
646- const tempDir = path . join ( app . getPath ( 'temp' ) , 'scriptplayerplus-ero' )
647- if ( ! fs . existsSync ( tempDir ) ) fs . mkdirSync ( tempDir , { recursive : true } )
659+ // Use script folder if set, otherwise temp
660+ const saveDir = scriptFolder || path . join ( app . getPath ( 'temp' ) , 'scriptplayerplus-ero' )
661+ if ( ! fs . existsSync ( saveDir ) ) fs . mkdirSync ( saveDir , { recursive : true } )
648662
649- const fileName = decodeURIComponent ( url . split ( '/' ) . pop ( ) || 'script.funscript' )
650- const localPath = path . join ( tempDir , fileName )
663+ const fileName = saveName || decodeURIComponent ( url . split ( '/' ) . pop ( ) || 'script.funscript' )
664+ const localPath = path . join ( saveDir , fileName )
665+ console . log ( '[EroScripts] Downloading to:' , localPath )
651666
652667 await new Promise < void > ( ( resolve , reject ) => {
653668 const parsed = new URL ( url )
0 commit comments