2022-07-15 21:04:00 +00:00
|
|
|
import {BrowserWindow, shell, ipcMain, app, clipboard} from "electron";
|
2022-09-25 18:30:09 +00:00
|
|
|
import {
|
|
|
|
getConfig,
|
|
|
|
setConfigBulk,
|
|
|
|
Settings,
|
|
|
|
getLang,
|
|
|
|
getVersion,
|
|
|
|
getConfigLocation,
|
|
|
|
getLangName,
|
|
|
|
sleep,
|
|
|
|
getDisplayVersion
|
|
|
|
} from "../utils";
|
2022-01-30 19:48:32 +00:00
|
|
|
import path from "path";
|
2022-07-15 21:04:00 +00:00
|
|
|
import os from "os";
|
|
|
|
import fs from "fs";
|
2022-08-25 16:40:43 +00:00
|
|
|
import {mainWindow} from "../window";
|
2022-03-04 17:53:18 +00:00
|
|
|
var settingsWindow: BrowserWindow;
|
2022-04-18 10:05:06 +00:00
|
|
|
var instance: number = 0;
|
2022-07-15 21:04:00 +00:00
|
|
|
const userDataPath = app.getPath("userData");
|
|
|
|
const storagePath = path.join(userDataPath, "/storage/");
|
|
|
|
const themesPath = path.join(userDataPath, "/themes/");
|
|
|
|
const pluginsPath = path.join(userDataPath, "/plugins/");
|
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({
|
2022-07-14 17:46:01 +00:00
|
|
|
width: 660,
|
|
|
|
height: 670,
|
2022-09-25 18:30:09 +00:00
|
|
|
title: `ArmCord Settings | Version: ${getDisplayVersion()}`,
|
2022-03-04 17:53:18 +00:00
|
|
|
darkTheme: true,
|
|
|
|
frame: true,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
webPreferences: {
|
2022-08-25 14:10:26 +00:00
|
|
|
sandbox: false,
|
2022-03-04 17:53:18 +00:00
|
|
|
preload: path.join(__dirname, "preload.js")
|
|
|
|
}
|
|
|
|
});
|
2022-08-22 09:24:55 +00:00
|
|
|
async function settingsLoadPage() {
|
|
|
|
if ((await getConfig("channel")) == "hummus") {
|
|
|
|
settingsWindow.loadURL(`file://${__dirname}/hummus.html`);
|
|
|
|
} else {
|
|
|
|
settingsWindow.loadURL(`file://${__dirname}/settings.html`);
|
|
|
|
}
|
|
|
|
}
|
2022-08-25 16:40:43 +00:00
|
|
|
const userDataPath = app.getPath("userData");
|
|
|
|
const themesFolder = userDataPath + "/themes/";
|
|
|
|
if (!fs.existsSync(themesFolder)) {
|
|
|
|
fs.mkdirSync(themesFolder);
|
|
|
|
console.log("Created missing theme folder");
|
|
|
|
}
|
|
|
|
settingsWindow.webContents.on("did-finish-load", () => {
|
|
|
|
fs.readdirSync(themesFolder).forEach((file) => {
|
|
|
|
try {
|
|
|
|
const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8");
|
|
|
|
var themeFile = JSON.parse(manifest);
|
|
|
|
settingsWindow.webContents.send(
|
|
|
|
"themeLoader",
|
|
|
|
fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8")
|
|
|
|
);
|
|
|
|
console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red");
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
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
|
|
|
});
|
2022-08-25 16:40:43 +00:00
|
|
|
ipcMain.on("openStorageFolder", async (event) => {
|
2022-07-15 21:04:00 +00:00
|
|
|
shell.openPath(storagePath);
|
2022-08-25 16:40:43 +00:00
|
|
|
await sleep(1000);
|
2022-07-15 21:04:00 +00:00
|
|
|
});
|
2022-08-25 16:40:43 +00:00
|
|
|
ipcMain.on("openThemesFolder", async (event) => {
|
2022-07-15 21:04:00 +00:00
|
|
|
shell.openPath(themesPath);
|
2022-08-25 16:40:43 +00:00
|
|
|
await sleep(1000);
|
2022-07-15 21:04:00 +00:00
|
|
|
});
|
2022-08-25 16:40:43 +00:00
|
|
|
ipcMain.on("openPluginsFolder", async (event) => {
|
2022-07-15 21:04:00 +00:00
|
|
|
shell.openPath(pluginsPath);
|
2022-08-25 16:40:43 +00:00
|
|
|
await sleep(1000);
|
2022-07-15 21:04:00 +00:00
|
|
|
});
|
2022-08-24 15:25:12 +00:00
|
|
|
ipcMain.on("getLangName", async (event) => {
|
|
|
|
event.returnValue = await getLangName();
|
|
|
|
});
|
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
|
|
|
});
|
2022-07-15 21:04:00 +00:00
|
|
|
ipcMain.on("copyDebugInfo", (event) => {
|
|
|
|
let settingsFileContent = fs.readFileSync(getConfigLocation(), "utf-8");
|
|
|
|
clipboard.writeText(
|
|
|
|
"**OS:** " +
|
|
|
|
os.platform() +
|
|
|
|
" " +
|
|
|
|
os.version() +
|
|
|
|
"\n**Architecture:** " +
|
|
|
|
os.arch() +
|
|
|
|
"\n**ArmCord version:** " +
|
|
|
|
getVersion() +
|
|
|
|
"\n**Electron version:** " +
|
|
|
|
process.versions.electron +
|
|
|
|
"\n`" +
|
|
|
|
settingsFileContent +
|
|
|
|
"`"
|
|
|
|
);
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
|
|
|
|
shell.openExternal(url);
|
|
|
|
return {action: "deny"};
|
|
|
|
});
|
2022-08-22 09:24:55 +00:00
|
|
|
settingsLoadPage();
|
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
|
|
|
}
|