33 */
44import { ipcRenderer } from 'electron' ;
55import { t } from 'fyo' ;
6+ import { BaseError } from 'fyo/utils/errors' ;
7+ import { BackendResponse } from 'utils/ipc/types' ;
68import { IPC_ACTIONS , IPC_MESSAGES } from 'utils/messages' ;
79import { setLanguageMap } from './language' ;
8- import { showToast } from './ui' ;
10+ import { showMessageDialog , showToast } from './ui' ;
911
1012export async function checkForUpdates ( ) {
1113 await ipcRenderer . invoke ( IPC_ACTIONS . CHECK_FOR_UPDATES ) ;
@@ -17,7 +19,32 @@ export async function openLink(link: string) {
1719}
1820
1921export async function deleteDb ( filePath : string ) {
20- await ipcRenderer . invoke ( IPC_ACTIONS . DELETE_FILE , filePath ) ;
22+ const { error } = ( await ipcRenderer . invoke (
23+ IPC_ACTIONS . DELETE_FILE ,
24+ filePath
25+ ) ) as BackendResponse ;
26+
27+ if ( error ?. code === 'EBUSY' ) {
28+ showMessageDialog ( {
29+ message : t `Delete Failed` ,
30+ detail : t `Please restart and try again` ,
31+ } ) ;
32+ } else if ( error ?. code === 'ENOENT' ) {
33+ showMessageDialog ( {
34+ message : t `Delete Failed` ,
35+ detail : t `File ${ filePath } does not exist` ,
36+ } ) ;
37+ } else if ( error ?. code === 'EPERM' ) {
38+ showMessageDialog ( {
39+ message : t `Cannot Delete` ,
40+ detail : t `Close Frappe Books and try manually` ,
41+ } ) ;
42+ } else if ( error ) {
43+ const err = new BaseError ( 500 , error . message ) ;
44+ err . name = error . name ;
45+ err . stack = error . stack ;
46+ throw err ;
47+ }
2148}
2249
2350export async function saveData ( data : string , savePath : string ) {
0 commit comments