@@ -180,6 +180,14 @@ function createTray() {
180180 }
181181 } ,
182182 } ,
183+ {
184+ label : "Archive" ,
185+ click : ( ) => {
186+ win ?. show ( ) ;
187+ win ?. focus ( ) ;
188+ win ?. webContents . send ( "navigate" , "archive" ) ;
189+ } ,
190+ } ,
183191 {
184192 label : "Settings" ,
185193 click : ( ) => {
@@ -330,6 +338,101 @@ ipcMain.handle("navigate-to", (_event, page: string) => {
330338 }
331339} ) ;
332340
341+ // Archive-related IPC handlers
342+ ipcMain . handle (
343+ "get-archived-history" ,
344+ ( _event , limit : number = 50 , offset : number = 0 ) => {
345+ return databaseManager ?. getArchivedItems ( limit , offset ) || [ ] ;
346+ }
347+ ) ;
348+
349+ ipcMain . handle ( "unarchive-item" , ( _event , id : number ) => {
350+ try {
351+ if ( ! databaseManager ) {
352+ return { success : false , error : "Database not initialized" } ;
353+ }
354+ const success = databaseManager . unarchiveItem ( id ) ;
355+ if ( success ) {
356+ // Reload clipboard manager's history
357+ clipboardManager ?. loadHistoryFromDB ( ) ;
358+ }
359+ return { success } ;
360+ } catch ( error ) {
361+ log . error ( "Failed to unarchive item:" , error ) ;
362+ return { success : false , error : String ( error ) } ;
363+ }
364+ } ) ;
365+
366+ ipcMain . handle ( "delete-archived-item" , ( _event , id : number ) => {
367+ try {
368+ if ( ! databaseManager ) {
369+ return { success : false , error : "Database not initialized" } ;
370+ }
371+ const success = databaseManager . deleteArchivedItem ( id ) ;
372+ return { success } ;
373+ } catch ( error ) {
374+ log . error ( "Failed to delete archived item:" , error ) ;
375+ return { success : false , error : String ( error ) } ;
376+ }
377+ } ) ;
378+
379+ ipcMain . handle ( "clear-archive" , ( ) => {
380+ try {
381+ if ( ! databaseManager ) {
382+ return { success : false , error : "Database not initialized" } ;
383+ }
384+ databaseManager . clearArchive ( ) ;
385+ return { success : true } ;
386+ } catch ( error ) {
387+ log . error ( "Failed to clear archive:" , error ) ;
388+ return { success : false , error : String ( error ) } ;
389+ }
390+ } ) ;
391+
392+ ipcMain . handle ( "set-retention-period" , ( _event , days : number ) => {
393+ try {
394+ configManager ?. setRetentionPeriodDays ( days ) ;
395+ return { success : true } ;
396+ } catch ( error ) {
397+ log . error ( "Failed to set retention period:" , error ) ;
398+ return { success : false , error : String ( error ) } ;
399+ }
400+ } ) ;
401+
402+ ipcMain . handle ( "archive-old-items" , ( ) => {
403+ try {
404+ if ( ! databaseManager || ! configManager ) {
405+ return { success : false , error : "Services not initialized" } ;
406+ }
407+ const retentionDays = configManager . getRetentionPeriodDays ( ) ;
408+ const count = databaseManager . archiveOldItems ( retentionDays ) ;
409+
410+ // Reload clipboard manager to reflect changes
411+ clipboardManager ?. loadHistoryFromDB ( ) ;
412+
413+ return { success : true , count } ;
414+ } catch ( error ) {
415+ log . error ( "Failed to archive items:" , error ) ;
416+ return { success : false , error : String ( error ) } ;
417+ }
418+ } ) ;
419+
420+ ipcMain . handle (
421+ "semantic-search-archive" ,
422+ async ( _event , query : string , limit : number = 10 ) => {
423+ try {
424+ if ( ! databaseManager || ! embeddingService ) {
425+ throw new Error ( "Services not initialized" ) ;
426+ }
427+ const queryEmbedding = await embeddingService . getEmbedding ( query ) ;
428+ return databaseManager . semanticSearchArchive ( queryEmbedding , limit ) ;
429+ } catch ( error ) {
430+ log . error ( "Failed to perform archive semantic search:" , error ) ;
431+ throw error ;
432+ }
433+ }
434+ ) ;
435+
333436function registerGlobalShortcut ( shortcut : string = "CommandOrControl+Shift+V" ) {
334437 globalShortcut . unregisterAll ( ) ;
335438
@@ -371,6 +474,10 @@ app.whenReady().then(() => {
371474 databaseManager = new DatabaseManager ( ) ;
372475 embeddingService = new EmbeddingService ( configManager ) ;
373476
477+ const retentionDays = configManager . getRetentionPeriodDays ( ) ;
478+ const archivedCount = databaseManager . archiveOldItems ( retentionDays ) ;
479+ log . info ( `Auto-archival complete: ${ archivedCount } items archived` ) ;
480+
374481 app . setLoginItemSettings ( {
375482 openAtLogin : true ,
376483 } ) ;
0 commit comments