1- import { ipcMain , app } from 'electron'
1+ import { app } from 'electron'
22import path from 'node:path'
33import fs from 'node:fs'
4+ import { handle } from './handle'
45import * as samples from '../db/queries/samples'
56
67const AUDIO_EXTS = new Set ( [ 'wav' , 'mp3' , 'flac' , 'aiff' , 'aif' , 'ogg' , 'm4a' ] )
@@ -27,19 +28,19 @@ import { syncProjectChopsToLibrary } from '../services/materializeChops'
2728import type { Sample , Project , ProjectRegion } from '../../types'
2829
2930export function registerLibraryHandlers ( ) : void {
30- ipcMain . handle ( 'library:getSamples' , ( _ , filters ?: { bpm ?: number ; key ?: string ; tags ?: string [ ] ; projectId ?: string } ) => {
31+ handle ( 'library:getSamples' , ( _ , filters ?: { bpm ?: number ; key ?: string ; tags ?: string [ ] ; projectId ?: string } ) => {
3132 return samples . getAllSamples ( filters )
3233 } )
3334
34- ipcMain . handle ( 'library:addSample' , ( _ , data : { name : string ; filePath : string ; duration ?: number } ) => {
35+ handle ( 'library:addSample' , ( _ , data : { name : string ; filePath : string ; duration ?: number } ) => {
3536 return samples . addSample ( data )
3637 } )
3738
38- ipcMain . handle ( 'library:updateSample' , ( _ , id : string , data : Partial < Pick < Sample , 'name' | 'bpm' | 'musicalKey' | 'tags' | 'waveformData' > > ) => {
39+ handle ( 'library:updateSample' , ( _ , id : string , data : Partial < Pick < Sample , 'name' | 'bpm' | 'musicalKey' | 'tags' | 'waveformData' > > ) => {
3940 samples . updateSample ( id , data )
4041 } )
4142
42- ipcMain . handle ( 'library:importFolder' , ( _ , folderPath : string ) => {
43+ handle ( 'library:importFolder' , ( _ , folderPath : string ) => {
4344 const existing = new Set ( samples . getAllSamples ( ) . map ( ( s ) => s . filePath ) )
4445 const allFiles = scanAudioFiles ( folderPath )
4546 const newFiles = allFiles . filter ( ( f ) => ! existing . has ( f ) )
@@ -50,14 +51,14 @@ export function registerLibraryHandlers(): void {
5051 return { imported : newFiles . length , skipped : allFiles . length - newFiles . length }
5152 } )
5253
53- ipcMain . handle ( 'library:deleteSample' , ( _ , id : string ) => {
54+ handle ( 'library:deleteSample' , ( _ , id : string ) => {
5455 const filePath = samples . deleteSample ( id )
5556 if ( filePath ) {
5657 try { fs . unlinkSync ( filePath ) } catch { /* file already gone, ignore */ }
5758 }
5859 } )
5960
60- ipcMain . handle ( 'library:saveChops' , async ( _ , params : {
61+ handle ( 'library:saveChops' , async ( _ , params : {
6162 sourceFilePath : string
6263 regions : Array < { start : number ; end : number ; name : string } >
6364 projectId ?: string
@@ -90,40 +91,40 @@ export function registerLibraryHandlers(): void {
9091 return saved
9192 } )
9293
93- ipcMain . handle ( 'projects:getAll' , ( ) => {
94+ handle ( 'projects:getAll' , ( ) => {
9495 return projects . getAllProjects ( )
9596 } )
9697
97- ipcMain . handle ( 'projects:get' , ( _ , id : string ) => {
98+ handle ( 'projects:get' , ( _ , id : string ) => {
9899 return projects . getProject ( id )
99100 } )
100101
101- ipcMain . handle ( 'projects:save' , async ( _ , data : { name : string ; sourcePath : string | null ; sourceName ?: string | null ; source ?: 'local' | 'freesound' ; regions : ProjectRegion [ ] } ) => {
102+ handle ( 'projects:save' , async ( _ , data : { name : string ; sourcePath : string | null ; sourceName ?: string | null ; source ?: 'local' | 'freesound' ; regions : ProjectRegion [ ] } ) => {
102103 const project = projects . saveProject ( data )
103104 await syncProjectChopsToLibrary ( project . id )
104105 return project
105106 } )
106107
107- ipcMain . handle ( 'projects:update' , async ( _ , id : string , data : Partial < Pick < Project , 'name' | 'sourcePath' | 'regions' > > ) => {
108+ handle ( 'projects:update' , async ( _ , id : string , data : Partial < Pick < Project , 'name' | 'sourcePath' | 'regions' > > ) => {
108109 projects . updateProject ( id , data )
109110 if ( data . regions !== undefined ) await syncProjectChopsToLibrary ( id )
110111 } )
111112
112- ipcMain . handle ( 'projects:getChops' , ( _ , projectId : string ) => {
113+ handle ( 'projects:getChops' , ( _ , projectId : string ) => {
113114 return projects . getProjectChops ( projectId )
114115 } )
115116
116- ipcMain . handle ( 'projects:getAllChops' , ( ) => {
117+ handle ( 'projects:getAllChops' , ( ) => {
117118 return projects . getAllProjectChops ( )
118119 } )
119120
120- ipcMain . handle ( 'projects:upsertChops' , async ( _ , projectId : string , regions : ProjectRegion [ ] ) => {
121+ handle ( 'projects:upsertChops' , async ( _ , projectId : string , regions : ProjectRegion [ ] ) => {
121122 const chops = projects . upsertProjectChops ( projectId , regions )
122123 await syncProjectChopsToLibrary ( projectId )
123124 return chops
124125 } )
125126
126- ipcMain . handle ( 'projects:delete' , ( _ , id : string ) => {
127+ handle ( 'projects:delete' , ( _ , id : string ) => {
127128 // The library is a projection of projects, so a deleted project's materialized chops leave the
128129 // library too (rows + files). Pack slots that referenced them are left intact — packs are
129130 // independent snapshots.
@@ -137,21 +138,21 @@ export function registerLibraryHandlers(): void {
137138 projects . deleteProject ( id )
138139 } )
139140
140- ipcMain . handle ( 'projects:duplicate' , async ( _ , id : string ) => {
141+ handle ( 'projects:duplicate' , async ( _ , id : string ) => {
141142 const project = projects . duplicateProject ( id )
142143 if ( project ) await syncProjectChopsToLibrary ( project . id )
143144 return project
144145 } )
145146
146- ipcMain . handle ( 'library:getPackSlotRefCount' , ( _ , id : string ) => {
147+ handle ( 'library:getPackSlotRefCount' , ( _ , id : string ) => {
147148 return samples . getSamplePackSlotRefCount ( id )
148149 } )
149150
150- ipcMain . handle ( 'library:getOrphans' , ( ) => {
151+ handle ( 'library:getOrphans' , ( ) => {
151152 return samples . getAllSamples ( ) . filter ( ( s ) => ! fs . existsSync ( s . filePath ) )
152153 } )
153154
154- ipcMain . handle ( 'library:deleteOrphans' , ( _ , ids : string [ ] ) => {
155+ handle ( 'library:deleteOrphans' , ( _ , ids : string [ ] ) => {
155156 for ( const id of ids ) samples . deleteSample ( id )
156157 return { deleted : ids . length }
157158 } )
0 commit comments