-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmain.ts
More file actions
133 lines (117 loc) · 3.89 KB
/
main.ts
File metadata and controls
133 lines (117 loc) · 3.89 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
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
import { app, protocol } from "electron";
import path from "path";
import fs from "fs-extra";
import { updateElectronApp } from "update-electron-app";
import log from "electron-log/main";
import { loadIpcInterfaceInMain } from "./main/ipc/ipc-connector";
import { mainApi } from "./main/ipc/main-api";
import { modelsApi } from "./main/ipc/models-api";
import { historyApi } from "./main/ipc/history-api";
import * as history from "./main/domain/history";
import * as searchIndex from "./main/domain/search";
import * as settings from "./main/domain/settings";
import * as vectorSearch from "./main/domain/vector-search";
import { registerTray } from "./main/domain/tray";
import * as windows from "./main/domain/windows";
import { windowsApi } from "./main/ipc/windows-api";
import { recorderIpcApi } from "./main/ipc/recorder-ipc";
import started from "electron-squirrel-startup";
log.initialize({ spyRendererConsole: true });
updateElectronApp();
const lock = app.requestSingleInstanceLock();
if (!lock) {
app.quit();
} else {
app.on("second-instance", () => {
const mainWindow = windows.getMainWindow();
if (!mainWindow) return;
if (!windows.isMainWindowOpen()) windows.openMainWindowNormally();
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
});
}
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
// eslint-disable-next-line global-require
if (started) {
app.quit();
}
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
protocol.registerSchemesAsPrivileged([
{
scheme: "recording",
privileges: {
bypassCSP: true,
// supportFetchAPI: true,
// secure: true,
stream: true,
},
},
]);
app.whenReady().then(async () => {
await history.init();
loadIpcInterfaceInMain("main", mainApi);
loadIpcInterfaceInMain("windows", windowsApi);
loadIpcInterfaceInMain("history", historyApi);
loadIpcInterfaceInMain("models", modelsApi);
loadIpcInterfaceInMain("recorderIpc", recorderIpcApi);
searchIndex.initializeSearchIndex().then(() => {
log.info("Search index initialized.");
});
// Initialize vector store for semantic search
vectorSearch.initializeVectorStore().then((success) => {
if (success) {
log.info("Vector store initialized successfully.");
} else {
log.info("Vector store initialization failed or disabled.");
}
});
if (!settings.existsSettingsFile()) {
await settings.initSettingsFile();
await mainApi.setAutoStart(true);
}
// protocol.handle("recording" doesn't produce a seekable stream
protocol.registerFileProtocol("recording", async (request, callback) => {
const recordingId = request.url.replace("recording://", "");
const mp3 = path.join(
await history.getRecordingsFolder(),
recordingId,
"recording.mp3",
);
if (fs.existsSync(mp3)) {
callback({ path: mp3 });
} else {
console.error(`Recording audio not found: ${mp3}`);
callback({ statusCode: 404 });
}
});
protocol.registerFileProtocol("screenshot", async (request, callback) => {
const fileName = request.url.replace("screenshot://", "");
if (!/^[\w-_]+\/[\w]+\.png$/.test(fileName)) {
console.error(`Invalid image loaded: ${fileName}`);
callback({ statusCode: 400 });
return;
}
const imageFile = path.join(await history.getRecordingsFolder(), fileName);
if (fs.existsSync(imageFile)) {
callback({ path: imageFile });
} else {
console.error(`Image not found: ${fileName}`);
callback({ statusCode: 404 });
}
});
windows.initializeMainWindow();
const hidden = process.argv.join(" ").includes("hidden");
log.info(
`App ready, running ${hidden ? "hidden" : "normally"}. Args: ${process.argv.join(" ")}`,
);
if (!hidden) {
windows.openMainWindowNormally();
} else {
// windows.hideMainWindow();
}
registerTray();
});