@@ -3,8 +3,15 @@ import { app, ipcMain } from 'electron'
33import { join } from 'path'
44import * as fs from 'fs'
55import * as unzipper from 'unzipper'
6- import { getAppData , setAppData , getAppByName , addAppManifest , getConfig } from './configHandler'
7- import { getData , setData , addData } from './dataHandler'
6+ import {
7+ getAppData ,
8+ setAppData ,
9+ getAppByName ,
10+ addAppManifest ,
11+ getConfig ,
12+ purgeAppConfig
13+ } from './configHandler'
14+ import { getData , setData , addData , purgeData } from './dataHandler'
815import { sendIpcMessage , openAuthWindow } from '../index'
916import { sendMessageToClients } from './websocketServer'
1017interface AppInstance {
@@ -82,7 +89,6 @@ function handleDataFromApp(app: string, type: string, ...args: any[]): void {
8289 }
8390}
8491async function requestAuthData ( appName : string , scope : Array < string > ) : Promise < void > {
85-
8692 // Send IPC message to renderer to display the form
8793 sendIpcMessage ( 'request-user-data' , appName , scope )
8894
@@ -339,6 +345,21 @@ async function addApp(_event, appName: string): Promise<void> {
339345 console . error ( 'Error adding app:' , error )
340346 }
341347}
348+ async function purgeAppData ( _event , appName : string ) : Promise < void > {
349+ console . log ( 'SERVER: Purging Data...' )
350+ purgeData ( appName )
351+ console . log ( 'SERVER: Purging Config...' )
352+ purgeAppConfig ( appName )
353+
354+ console . log ( 'SERVER: Purging File...' )
355+ const appDirectory = join ( app . getPath ( 'userData' ) , 'apps' , appName )
356+ if ( fs . existsSync ( appDirectory ) ) {
357+ fs . rmSync ( appDirectory , { recursive : true } )
358+ console . log ( `Deleted app directory: ${ appDirectory } ` )
359+ } else {
360+ console . log ( `App directory not found: ${ appDirectory } ` )
361+ }
362+ }
342363
343364export {
344365 runApp ,
@@ -348,5 +369,6 @@ export {
348369 handleZip ,
349370 loadAndRunEnabledApps ,
350371 addApp ,
351- disableApp
372+ disableApp ,
373+ purgeAppData
352374}
0 commit comments