2022-04-18 11:03:26 +00:00
|
|
|
import {BrowserWindow, shell, ipcMain} from "electron";
|
2022-04-18 10:25:10 +00:00
|
|
|
import {getConfig, setConfigBulk, Settings} from "../utils";
|
2022-01-30 19:48:32 +00:00
|
|
|
import path from "path";
|
2022-03-04 17:53:18 +00:00
|
|
|
var settingsWindow: BrowserWindow;
|
2022-04-18 10:05:06 +00:00
|
|
|
var instance: number = 0;
|
|
|
|
|
2022-01-30 19:48:32 +00:00
|
|
|
export function createSettingsWindow() {
|
2022-04-18 10:05:06 +00:00
|
|
|
console.log("Creating a settings window.");
|
|
|
|
instance = instance + 1;
|
|
|
|
if (instance > 1) {
|
|
|
|
if (settingsWindow) {
|
|
|
|
settingsWindow.show();
|
|
|
|
settingsWindow.restore();
|
|
|
|
}
|
2022-03-04 17:53:18 +00:00
|
|
|
} else {
|
|
|
|
settingsWindow = new BrowserWindow({
|
|
|
|
width: 500,
|
2022-05-14 19:02:09 +00:00
|
|
|
height: 555,
|
2022-03-04 17:53:18 +00:00
|
|
|
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);
|
2022-04-18 10:25:10 +00:00
|
|
|
setConfigBulk(args);
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
|
|
|
ipcMain.handle("getSetting", (event, toGet: string) => {
|
2022-04-18 10:25:10 +00:00
|
|
|
return getConfig(toGet);
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
|
|
|
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
|
|
|
|
shell.openExternal(url);
|
|
|
|
return {action: "deny"};
|
|
|
|
});
|
|
|
|
settingsWindow.loadURL(`file://${__dirname}/settings.html`);
|
2022-04-18 10:05:06 +00:00
|
|
|
settingsWindow.on("close", (event: Event) => {
|
|
|
|
ipcMain.removeHandler("getSetting");
|
|
|
|
ipcMain.removeAllListeners("saveSettings");
|
|
|
|
instance = 0;
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
|
|
|
}
|
2022-01-30 19:48:32 +00:00
|
|
|
}
|