armcord/src/settings/main.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-03-04 17:53:18 +00:00
import {BrowserWindow, shell, ipcMain} from "electron";
import * as storage from "electron-json-storage";
2022-03-04 16:30:23 +00:00
import {getConfigUnsafe, saveSettings, Settings} from "../utils";
2022-01-30 19:48:32 +00:00
import path from "path";
2022-03-04 17:53:18 +00:00
var settings: any;
var isAlreadyCreated: boolean = false;
2022-02-26 21:26:16 +00:00
storage.get("settings", function (error, data: any) {
2022-03-04 17:53:18 +00:00
if (error) throw error;
console.log(data);
settings = data;
2022-02-26 21:26:16 +00:00
});
2022-03-04 17:53:18 +00:00
var settingsWindow: BrowserWindow;
2022-01-30 19:48:32 +00:00
export function createSettingsWindow() {
2022-03-04 17:53:18 +00:00
if (isAlreadyCreated) {
settingsWindow.show();
} else {
settingsWindow = new BrowserWindow({
width: 500,
height: 500,
title: "ArmCord Settings",
darkTheme: true,
frame: true,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, "preload.js")
}
});
ipcMain.on("saveSettings", (event, args: Settings) => {
console.log(args);
saveSettings(args);
});
ipcMain.handle("getSetting", (event, toGet: string) => {
return getConfigUnsafe(toGet);
});
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
shell.openExternal(url);
return {action: "deny"};
});
settingsWindow.loadURL(`file://${__dirname}/settings.html`);
settingsWindow.on("close", async (e) => {
e.preventDefault();
settingsWindow.hide();
});
isAlreadyCreated = true;
}
2022-01-30 19:48:32 +00:00
}