2022-01-15 21:21:51 +00:00
|
|
|
import * as storage from "electron-json-storage";
|
2022-01-16 18:07:00 +00:00
|
|
|
import * as fs from "fs";
|
|
|
|
import { app } from "electron";
|
|
|
|
|
2021-12-24 21:56:49 +00:00
|
|
|
//utillity functions that are used all over the codebase or just too obscure to be put in the file used in
|
|
|
|
export function addStyle(styleString: string) {
|
2022-01-15 21:21:51 +00:00
|
|
|
const style = document.createElement("style");
|
|
|
|
style.textContent = styleString;
|
|
|
|
document.head.append(style);
|
|
|
|
}
|
2021-12-24 21:56:49 +00:00
|
|
|
|
|
|
|
export function addScript(scriptString: string) {
|
|
|
|
var script = document.createElement("script");
|
|
|
|
script.textContent = scriptString;
|
|
|
|
document.body.append(script);
|
|
|
|
}
|
2022-01-15 21:21:51 +00:00
|
|
|
export function setup() {
|
|
|
|
console.log("Setting up ArmCord settings.");
|
|
|
|
storage.set(
|
|
|
|
"settings",
|
|
|
|
{
|
|
|
|
customTitlebar: true,
|
|
|
|
channel: "stable",
|
|
|
|
firstRun: "done",
|
|
|
|
armcordCSP: true,
|
2022-01-16 18:07:00 +00:00
|
|
|
mods: "none"
|
2022-01-15 21:21:51 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
}
|
|
|
|
);
|
2021-12-26 21:41:09 +00:00
|
|
|
}
|
2022-01-15 21:21:51 +00:00
|
|
|
export async function sleep(ms: number) {
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
export function saveSettings(
|
|
|
|
customTitlebarSetting: boolean,
|
|
|
|
channelSetting: string,
|
|
|
|
armcordCSPSetting: boolean,
|
|
|
|
modsSetting: string
|
|
|
|
) {
|
2021-12-26 21:41:09 +00:00
|
|
|
console.log("Setting up ArmCord settings.");
|
2022-01-15 21:21:51 +00:00
|
|
|
storage.set(
|
|
|
|
"settings",
|
|
|
|
{
|
|
|
|
customTitlebar: customTitlebarSetting,
|
|
|
|
channel: channelSetting,
|
|
|
|
firstRun: "done",
|
|
|
|
armcordCSP: armcordCSPSetting,
|
|
|
|
mods: modsSetting,
|
|
|
|
},
|
|
|
|
function (error) {
|
2021-12-26 21:41:09 +00:00
|
|
|
if (error) throw error;
|
2022-01-15 21:21:51 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2022-01-16 18:07:00 +00:00
|
|
|
export async function getConfigUnsafe(object: string) {
|
|
|
|
const userDataPath = app.getPath("userData");
|
|
|
|
const storagePath = userDataPath + "/storage/";
|
|
|
|
let rawdata = fs.readFileSync(storagePath + "settings.json", "utf-8");
|
|
|
|
let returndata = JSON.parse(rawdata);
|
|
|
|
console.log(returndata[object]);
|
|
|
|
return returndata[object]
|
|
|
|
}
|
2022-01-15 21:21:51 +00:00
|
|
|
export function getVersion() {
|
2022-01-16 18:07:00 +00:00
|
|
|
//to-do better way of doing this
|
|
|
|
return '3.0.1';
|
2022-01-15 18:31:51 +00:00
|
|
|
}
|
2022-01-16 18:07:00 +00:00
|
|
|
|