Initial open-source release
This commit is contained in:
44
src/ipc/handlers/settings_handlers.ts
Normal file
44
src/ipc/handlers/settings_handlers.ts
Normal 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();
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user