-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (53 loc) Β· 2.1 KB
/
index.js
File metadata and controls
67 lines (53 loc) Β· 2.1 KB
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
const fileInput = document.getElementById("fileInput");
const generateBtn = document.getElementById("generate");
const fileLabel = document.getElementById("fileLabel");
const mergeBtn = document.getElementById("mergeFiles");
const mergeInput = document.getElementById("mergeInput");
if (!window.electronAPI) {
console.warn("β οΈ window.electronAPI is not available. Check preload.js exposure.");
}
fileInput.addEventListener("change", () => {
fileLabel.innerHTML = fileInput.files.length
? "π <span class='uploaded'>chat.db ready β
</span>"
: "π Select <code>chat.db</code>";
});
generateBtn.addEventListener("click", async () => {
const filePath = await window.electronAPI.chooseChatDb();
if (!filePath) {
return alert("β No chat.db file selected.");
}
console.log("π¦ Selected file path:", filePath);
console.log("π Sending to extractor:", { dbPath: filePath });
try {
const result = await window.electronAPI.runExtractor({ dbPath: filePath });
alert(`β
Export complete.\nCheck terminal or output folder.`);
console.log(result);
} catch (err) {
console.error("β Extractor error:", err);
alert(`β Unexpected error:\n${err?.message || err}`);
}
});
mergeBtn.addEventListener("click", async () => {
if (!mergeInput.files.length || !fileInput.files.length) {
return alert("β Select both: .shm/.wal AND main .db file.");
}
const dbFile = fileInput.files[0];
const otherFiles = Array.from(mergeInput.files);
if (otherFiles.length !== 2) {
return alert("β Select exactly 2 companion files: .shm and .wal");
}
const allFiles = [dbFile, ...otherFiles];
const paths = allFiles.map((file) => file.path);
console.log("π§ͺ Paths to merge:", paths);
try {
const result = await window.electronAPI.finalizeDatabase(paths);
alert("β
Merge complete.\nNow generate your report.");
console.log(result);
if (!result.success) {
console.error("β Merge process failed with error:", result.error);
}
} catch (err) {
console.error("β Merge failed:", err);
alert(`β Merge error:\n${err?.message || err}`);
}
});