mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
f57fe11769
* 2 new things (Read desc.) - Cleaned up ASAR packaging, ignoring unneeded files for building - Moved install location for Windows users ("AppData\Local\Programs" -> "AppData\Local" * 3 things (Read desc.) - Updated things related to Hummus (Hummus settings don't save nor load in it's respective settings window yet, idk why) - Added check for package version (ArmCord's internal version) - Made check for Kernel mod a bit cleaner, it still uses the same jank method * 3 things - Made macOS titlebar more accurate to Discord - Added "unFocused" class when window isn't focused - Added option to uninstall Husky hook for Windows users with reminder to run format script before committing * Resolved a dumb issue My dumbass not knowing the "echo" command existed smh * Made "precommit-fix" warning more noticable * Whoops * Fixed a CSS bug Discord updates are gonna hate us, huh? * 4 things (Formatted) - Updated coding for getting the current version - Updated some context menu and tray stuff - Added current version to the title of the settings window - Added the ability to restart the app within the settings * A few things - Updated tray menu to include the tray icon infront of the ArmCord version - Updated MacOS titlebar to not be broken in setup - Polished settings menu a bit - Polished the Discord tray icon - Added the Classic Discord icon as tray icon option
123 lines
4.4 KiB
TypeScript
123 lines
4.4 KiB
TypeScript
import {BrowserWindow, shell, ipcMain, app, clipboard} from "electron";
|
|
import {
|
|
getConfig,
|
|
setConfigBulk,
|
|
Settings,
|
|
getLang,
|
|
getVersion,
|
|
getConfigLocation,
|
|
getLangName,
|
|
sleep,
|
|
getDisplayVersion
|
|
} from "../utils";
|
|
import path from "path";
|
|
import os from "os";
|
|
import fs from "fs";
|
|
import {mainWindow} from "../window";
|
|
var settingsWindow: BrowserWindow;
|
|
var instance: number = 0;
|
|
const userDataPath = app.getPath("userData");
|
|
const storagePath = path.join(userDataPath, "/storage/");
|
|
const themesPath = path.join(userDataPath, "/themes/");
|
|
const pluginsPath = path.join(userDataPath, "/plugins/");
|
|
export function createSettingsWindow() {
|
|
console.log("Creating a settings window.");
|
|
instance = instance + 1;
|
|
if (instance > 1) {
|
|
if (settingsWindow) {
|
|
settingsWindow.show();
|
|
settingsWindow.restore();
|
|
}
|
|
} else {
|
|
settingsWindow = new BrowserWindow({
|
|
width: 660,
|
|
height: 670,
|
|
title: `ArmCord Settings | Version: ${getDisplayVersion()}`,
|
|
darkTheme: true,
|
|
frame: true,
|
|
autoHideMenuBar: true,
|
|
webPreferences: {
|
|
sandbox: false,
|
|
preload: path.join(__dirname, "preload.js")
|
|
}
|
|
});
|
|
async function settingsLoadPage() {
|
|
if ((await getConfig("channel")) == "hummus") {
|
|
settingsWindow.loadURL(`file://${__dirname}/hummus.html`);
|
|
} else {
|
|
settingsWindow.loadURL(`file://${__dirname}/settings.html`);
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
ipcMain.on("saveSettings", (event, args: Settings) => {
|
|
console.log(args);
|
|
setConfigBulk(args);
|
|
});
|
|
ipcMain.on("openStorageFolder", async (event) => {
|
|
shell.openPath(storagePath);
|
|
await sleep(1000);
|
|
});
|
|
ipcMain.on("openThemesFolder", async (event) => {
|
|
shell.openPath(themesPath);
|
|
await sleep(1000);
|
|
});
|
|
ipcMain.on("openPluginsFolder", async (event) => {
|
|
shell.openPath(pluginsPath);
|
|
await sleep(1000);
|
|
});
|
|
ipcMain.on("getLangName", async (event) => {
|
|
event.returnValue = await getLangName();
|
|
});
|
|
ipcMain.handle("getSetting", (event, toGet: string) => {
|
|
return getConfig(toGet);
|
|
});
|
|
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 +
|
|
"`"
|
|
);
|
|
});
|
|
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
|
|
shell.openExternal(url);
|
|
return {action: "deny"};
|
|
});
|
|
settingsLoadPage();
|
|
settingsWindow.on("close", (event: Event) => {
|
|
ipcMain.removeHandler("getSetting");
|
|
ipcMain.removeAllListeners("saveSettings");
|
|
instance = 0;
|
|
});
|
|
}
|
|
}
|