File size: 2,573 Bytes
b4143a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { contextBridge, ipcRenderer } from 'electron'

export interface AuditorAPI {
  drives: () => Promise<unknown>
  listDir: (dirPath: string, opts?: { maxEntries?: number }) => Promise<unknown>
  folderSize: (dirPath: string) => Promise<unknown>
  largeFiles: (rootPath: string, minBytes: number, maxResults: number) => Promise<unknown>
  processes: () => Promise<unknown>
  services: () => Promise<unknown>
  installed: () => Promise<unknown>
  system: () => Promise<unknown>
  network: () => Promise<unknown>
  env: (keys?: string[]) => Promise<unknown>
  startup: () => Promise<unknown>
  temp: () => Promise<unknown>
  tasks: () => Promise<unknown>
  features: () => Promise<string>
  openExplorer: (p: string) => Promise<void>
  killProcess: (pid: number) => Promise<void>
  openExternal: (url: string) => Promise<void>
  clipboardWriteText: (text: string) => Promise<void>
  notesGetAll: () => Promise<Record<string, string>>
  notesSet: (key: string, value: string) => Promise<Record<string, string>>
  notesDelete: (key: string) => Promise<Record<string, string>>
}

const api: AuditorAPI = {
  drives: () => ipcRenderer.invoke('audit:drives'),
  listDir: (dirPath, opts) => ipcRenderer.invoke('audit:listDir', dirPath, opts),
  folderSize: (dirPath) => ipcRenderer.invoke('audit:folderSize', dirPath),
  largeFiles: (rootPath, minBytes, maxResults) =>
    ipcRenderer.invoke('audit:largeFiles', rootPath, minBytes, maxResults),
  processes: () => ipcRenderer.invoke('audit:processes'),
  services: () => ipcRenderer.invoke('audit:services'),
  installed: () => ipcRenderer.invoke('audit:installed'),
  system: () => ipcRenderer.invoke('audit:system'),
  network: () => ipcRenderer.invoke('audit:network'),
  env: (keys) => ipcRenderer.invoke('audit:env', keys),
  startup: () => ipcRenderer.invoke('audit:startup'),
  temp: () => ipcRenderer.invoke('audit:temp'),
  tasks: () => ipcRenderer.invoke('audit:tasks'),
  features: () => ipcRenderer.invoke('audit:features'),
  openExplorer: (p) => ipcRenderer.invoke('audit:openExplorer', p),
  killProcess: (pid) => ipcRenderer.invoke('audit:killProcess', pid),
  openExternal: (url) => ipcRenderer.invoke('audit:openExternal', url),
  clipboardWriteText: (text) => ipcRenderer.invoke('clipboard:writeText', text),
  notesGetAll: () => ipcRenderer.invoke('notes:getAll'),
  notesSet: (key, value) => ipcRenderer.invoke('notes:set', key, value),
  notesDelete: (key) => ipcRenderer.invoke('notes:delete', key),
}

contextBridge.exposeInMainWorld('auditor', api)