@@ -5,7 +5,7 @@ import * as os from 'os';
55import { spawn } from 'child_process' ;
66import * as pty from 'node-pty' ;
77import { FileHandler , filterLineToVisibleColumns , ColumnConfig } from './fileHandler' ;
8- import { IPC , SearchOptions , Bookmark , Highlight , HighlightGroup , SearchConfig , ActivityEntry , LocalFileData } from '../shared/types' ;
8+ import { IPC , SearchOptions , Bookmark , Highlight , HighlightGroup , SearchConfig , SearchConfigSession , ActivityEntry , LocalFileData } from '../shared/types' ;
99import * as Diff from 'diff' ;
1010import { analyzerRegistry , AnalyzerOptions } from './analyzers' ;
1111import { loadDatadogConfig , saveDatadogConfig , clearDatadogConfig , fetchDatadogLogs , DatadogConfig , DatadogFetchParams } from './datadogClient' ;
@@ -2141,6 +2141,98 @@ ipcMain.handle(IPC.SEARCH_CONFIG_EXPORT, async (_, configId: string, lines: stri
21412141 }
21422142} ) ;
21432143
2144+ ipcMain . handle ( IPC . SEARCH_CONFIG_EXPORT_ALL , async ( _ , content : string ) => {
2145+ if ( ! currentFilePath ) return { success : false , error : 'No file open' } ;
2146+
2147+ try {
2148+ const baseName = path . basename ( currentFilePath , path . extname ( currentFilePath ) ) ;
2149+ const date = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, '-' ) . substring ( 0 , 19 ) ;
2150+ const exportName = `${ baseName } _multi-search_${ date } .txt` ;
2151+ const exportPath = path . join ( path . dirname ( currentFilePath ) , exportName ) ;
2152+ fs . writeFileSync ( exportPath , content , 'utf-8' ) ;
2153+ return { success : true , filePath : exportPath } ;
2154+ } catch ( error ) {
2155+ return { success : false , error : String ( error ) } ;
2156+ }
2157+ } ) ;
2158+
2159+ // === Search Config Sessions ===
2160+
2161+ const getSearchConfigSessionsPath = ( ) => path . join ( getConfigDir ( ) , 'search-config-sessions.json' ) ;
2162+
2163+ function loadGlobalSearchConfigSessions ( ) : SearchConfigSession [ ] {
2164+ try {
2165+ const filePath = getSearchConfigSessionsPath ( ) ;
2166+ if ( fs . existsSync ( filePath ) ) {
2167+ return JSON . parse ( fs . readFileSync ( filePath , 'utf-8' ) ) ;
2168+ }
2169+ } catch { /* ignore */ }
2170+ return [ ] ;
2171+ }
2172+
2173+ function saveGlobalSearchConfigSessions ( sessions : SearchConfigSession [ ] ) : void {
2174+ ensureConfigDir ( ) ;
2175+ fs . writeFileSync ( getSearchConfigSessionsPath ( ) , JSON . stringify ( sessions , null , 2 ) , 'utf-8' ) ;
2176+ }
2177+
2178+ function loadLocalSearchConfigSessions ( filePath : string ) : SearchConfigSession [ ] {
2179+ try {
2180+ const data = loadLocalFileData ( filePath ) ;
2181+ return ( data as any ) . searchConfigSessions || [ ] ;
2182+ } catch { /* ignore */ }
2183+ return [ ] ;
2184+ }
2185+
2186+ function saveLocalSearchConfigSessions ( filePath : string , sessions : SearchConfigSession [ ] ) : void {
2187+ const data = loadLocalFileData ( filePath ) ;
2188+ ( data as any ) . searchConfigSessions = sessions ;
2189+ saveLocalFileData ( filePath , data ) ;
2190+ }
2191+
2192+ ipcMain . handle ( IPC . SEARCH_CONFIG_SESSION_LIST , async ( ) => {
2193+ const globalSessions = loadGlobalSearchConfigSessions ( ) . map ( s => ( { ...s , isGlobal : true } ) ) ;
2194+ const localSessions = currentFilePath
2195+ ? loadLocalSearchConfigSessions ( currentFilePath ) . map ( s => ( { ...s , isGlobal : false } ) )
2196+ : [ ] ;
2197+ return { success : true , sessions : [ ...globalSessions , ...localSessions ] } ;
2198+ } ) ;
2199+
2200+ ipcMain . handle ( IPC . SEARCH_CONFIG_SESSION_SAVE , async ( _ , session : SearchConfigSession ) => {
2201+ if ( session . isGlobal ) {
2202+ const sessions = loadGlobalSearchConfigSessions ( ) ;
2203+ const existingIdx = sessions . findIndex ( s => s . id === session . id ) ;
2204+ if ( existingIdx >= 0 ) {
2205+ sessions [ existingIdx ] = session ;
2206+ } else {
2207+ sessions . push ( session ) ;
2208+ }
2209+ saveGlobalSearchConfigSessions ( sessions ) ;
2210+ } else {
2211+ if ( ! currentFilePath ) return { success : false , error : 'No file open' } ;
2212+ const sessions = loadLocalSearchConfigSessions ( currentFilePath ) ;
2213+ const existingIdx = sessions . findIndex ( s => s . id === session . id ) ;
2214+ if ( existingIdx >= 0 ) {
2215+ sessions [ existingIdx ] = session ;
2216+ } else {
2217+ sessions . push ( session ) ;
2218+ }
2219+ saveLocalSearchConfigSessions ( currentFilePath , sessions ) ;
2220+ }
2221+ return { success : true } ;
2222+ } ) ;
2223+
2224+ ipcMain . handle ( IPC . SEARCH_CONFIG_SESSION_DELETE , async ( _ , sessionId : string , isGlobal : boolean ) => {
2225+ if ( isGlobal ) {
2226+ const sessions = loadGlobalSearchConfigSessions ( ) . filter ( s => s . id !== sessionId ) ;
2227+ saveGlobalSearchConfigSessions ( sessions ) ;
2228+ } else {
2229+ if ( ! currentFilePath ) return { success : false , error : 'No file open' } ;
2230+ const sessions = loadLocalSearchConfigSessions ( currentFilePath ) . filter ( s => s . id !== sessionId ) ;
2231+ saveLocalSearchConfigSessions ( currentFilePath , sessions ) ;
2232+ }
2233+ return { success : true } ;
2234+ } ) ;
2235+
21442236// === Utility ===
21452237
21462238ipcMain . handle ( 'get-file-info' , async ( ) => {
0 commit comments