File size: 5,785 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const electron_1 = require("electron");
const path = __importStar(require("node:path"));
const fssync = __importStar(require("node:fs"));
const audit_1 = require("./audit");
const pythonBackend_1 = require("./pythonBackend");
const isDev = !!process.env.VITE_DEV_SERVER_URL;
function notesPath() {
    return path.join(electron_1.app.getPath('userData'), 'auditor-notes.json');
}
function loadNotes() {
    try {
        const raw = fssync.readFileSync(notesPath(), 'utf8');
        return JSON.parse(raw);
    }
    catch {
        return {};
    }
}
function saveNotes(n) {
    fssync.mkdirSync(path.dirname(notesPath()), { recursive: true });
    fssync.writeFileSync(notesPath(), JSON.stringify(n, null, 2), 'utf8');
}
function createWindow() {
    const win = new electron_1.BrowserWindow({
        width: 1280,
        height: 800,
        minWidth: 960,
        minHeight: 640,
        backgroundColor: '#0d0f12',
        titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default',
        webPreferences: {
            preload: path.join(__dirname, 'preload.js'),
            contextIsolation: true,
            nodeIntegration: false,
            sandbox: false,
        },
    });
    if (isDev) {
        win.loadURL(process.env.VITE_DEV_SERVER_URL);
    }
    else {
        win.loadFile(path.join(__dirname, '../dist/index.html'));
    }
}
electron_1.app.whenReady().then(async () => {
    try {
        await (0, pythonBackend_1.startPythonBackend)();
    }
    catch (e) {
        electron_1.dialog.showErrorBox('Python backend required', `${String(e)}\n\nInstall: cd backend && pip install -r requirements.txt`);
        electron_1.app.quit();
        return;
    }
    electron_1.ipcMain.handle('audit:drives', () => (0, audit_1.getDrivesWin)());
    electron_1.ipcMain.handle('audit:listDir', (_e, dirPath, opts) => (0, audit_1.listDirectory)(dirPath, opts ?? {}));
    electron_1.ipcMain.handle('audit:folderSize', (_e, dirPath) => (0, audit_1.computeFolderSize)(dirPath));
    electron_1.ipcMain.handle('audit:largeFiles', (_e, rootPath, minBytes, maxResults) => (0, audit_1.findLargeFiles)(rootPath, minBytes, maxResults));
    electron_1.ipcMain.handle('audit:processes', () => (0, audit_1.getProcessesWin)());
    electron_1.ipcMain.handle('audit:services', () => (0, audit_1.getServicesWin)());
    electron_1.ipcMain.handle('audit:installed', () => (0, audit_1.getInstalledPrograms)());
    electron_1.ipcMain.handle('audit:system', () => (0, audit_1.getSystemSnapshot)());
    electron_1.ipcMain.handle('audit:network', () => (0, audit_1.getNetworkInterfaces)());
    electron_1.ipcMain.handle('audit:env', (_e, keys) => (0, audit_1.getEnvSnapshot)(keys));
    electron_1.ipcMain.handle('audit:startup', () => (0, audit_1.getStartupFolders)());
    electron_1.ipcMain.handle('audit:temp', () => (0, audit_1.getTempAudit)());
    electron_1.ipcMain.handle('audit:tasks', () => (0, audit_1.getScheduledTasksSummary)());
    electron_1.ipcMain.handle('audit:features', () => (0, audit_1.getWindowsFeaturesSnippet)());
    electron_1.ipcMain.handle('audit:openExplorer', (_e, p) => (0, audit_1.openPathInExplorer)(p));
    electron_1.ipcMain.handle('audit:killProcess', (_e, pid) => (0, audit_1.killProcess)(pid));
    electron_1.ipcMain.handle('audit:openExternal', (_e, url) => electron_1.shell.openExternal(url));
    electron_1.ipcMain.handle('clipboard:writeText', (_e, text) => {
        electron_1.clipboard.writeText(text);
    });
    electron_1.ipcMain.handle('notes:getAll', () => loadNotes());
    electron_1.ipcMain.handle('notes:set', (_e, key, value) => {
        const all = loadNotes();
        if (value.trim() === '')
            delete all[key];
        else
            all[key] = value;
        saveNotes(all);
        return all;
    });
    electron_1.ipcMain.handle('notes:delete', (_e, key) => {
        const all = loadNotes();
        delete all[key];
        saveNotes(all);
        return all;
    });
    createWindow();
    electron_1.app.on('activate', () => {
        if (electron_1.BrowserWindow.getAllWindows().length === 0)
            createWindow();
    });
});
electron_1.app.on('window-all-closed', () => {
    if (process.platform !== 'darwin')
        electron_1.app.quit();
});
electron_1.app.on('before-quit', () => {
    (0, pythonBackend_1.stopPythonBackend)();
});