Initial open-source release

This commit is contained in:
Will Chen
2025-04-11 09:37:05 -07:00
commit 43f67e0739
208 changed files with 45476 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { ipcMain } from "electron";
import type { UserSettings } from "../../lib/schemas";
import { writeSettings } from "../../main/settings";
import { readSettings } from "../../main/settings";
export function registerSettingsHandlers() {
ipcMain.handle("get-user-settings", async () => {
const settings = await readSettings();
// Mask API keys before sending to renderer
if (settings?.providerSettings) {
// Use optional chaining
for (const providerKey in settings.providerSettings) {
// Ensure the key is own property and providerSetting exists
if (
Object.prototype.hasOwnProperty.call(
settings.providerSettings,
providerKey
)
) {
const providerSetting = settings.providerSettings[providerKey];
// Check if apiKey exists and is a non-empty string before masking
if (
providerSetting?.apiKey &&
typeof providerSetting.apiKey === "string" &&
providerSetting.apiKey.length > 0
) {
providerSetting.apiKey = providerSetting.apiKey;
}
}
}
}
return settings;
});
ipcMain.handle(
"set-user-settings",
async (_, settings: Partial<UserSettings>) => {
writeSettings(settings);
return readSettings();
}
);
}