mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Remove legacy config helper functions
This commit is contained in:
parent
a39fe281f6
commit
9d2a1190cf
5 changed files with 15 additions and 37 deletions
|
@ -1,7 +1,7 @@
|
||||||
//ipc stuff
|
//ipc stuff
|
||||||
import {app, ipcMain, shell, desktopCapturer} from "electron";
|
import {app, ipcMain, shell, desktopCapturer} from "electron";
|
||||||
import {createTabsGuest, mainWindow} from "./window";
|
import {createTabsGuest, mainWindow} from "./window";
|
||||||
import {saveSettings, getVersion} from "./utils";
|
import {setConfigBulk, getVersion} from "./utils";
|
||||||
import {settings, customTitlebar, tabs} from "./main";
|
import {settings, customTitlebar, tabs} from "./main";
|
||||||
import {createSettingsWindow} from "./settings/main";
|
import {createSettingsWindow} from "./settings/main";
|
||||||
export function registerIpc() {
|
export function registerIpc() {
|
||||||
|
@ -46,7 +46,7 @@ export function registerIpc() {
|
||||||
app.exit();
|
app.exit();
|
||||||
});
|
});
|
||||||
ipcMain.on("saveSettings", (event, args) => {
|
ipcMain.on("saveSettings", (event, args) => {
|
||||||
saveSettings(args);
|
setConfigBulk(args);
|
||||||
});
|
});
|
||||||
ipcMain.on("minimizeToTray", (event) => {
|
ipcMain.on("minimizeToTray", (event) => {
|
||||||
console.log(settings.minimizeToTray);
|
console.log(settings.minimizeToTray);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {app, BrowserWindow, session, dialog} from "electron";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import "v8-compile-cache";
|
import "v8-compile-cache";
|
||||||
import * as storage from "electron-json-storage";
|
import * as storage from "electron-json-storage";
|
||||||
import {getConfigUnsafe, setup} from "./utils";
|
import {getConfig, setup} from "./utils";
|
||||||
import "./extensions/mods";
|
import "./extensions/mods";
|
||||||
import "./extensions/plugin";
|
import "./extensions/plugin";
|
||||||
import "./tray";
|
import "./tray";
|
||||||
|
@ -15,7 +15,7 @@ export var settings: any;
|
||||||
export var customTitlebar: boolean;
|
export var customTitlebar: boolean;
|
||||||
export var tabs: boolean;
|
export var tabs: boolean;
|
||||||
async function appendSwitch() {
|
async function appendSwitch() {
|
||||||
if ((await getConfigUnsafe("windowStyle")) == "glasstron") {
|
if ((await getConfig("windowStyle")) == "glasstron") {
|
||||||
console.log("Enabling transparency visuals.");
|
console.log("Enabling transparency visuals.");
|
||||||
app.commandLine.appendSwitch("enable-transparent-visuals");
|
app.commandLine.appendSwitch("enable-transparent-visuals");
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ storage.get("settings", function (error, data: any) {
|
||||||
settings = data;
|
settings = data;
|
||||||
});
|
});
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
switch (await getConfigUnsafe("windowStyle")) {
|
switch (await getConfig("windowStyle")) {
|
||||||
case "default":
|
case "default":
|
||||||
createCustomWindow();
|
createCustomWindow();
|
||||||
customTitlebar = true;
|
customTitlebar = true;
|
||||||
|
@ -79,7 +79,7 @@ app.whenReady().then(async () => {
|
||||||
});
|
});
|
||||||
app.on("activate", async function () {
|
app.on("activate", async function () {
|
||||||
if (BrowserWindow.getAllWindows().length === 0)
|
if (BrowserWindow.getAllWindows().length === 0)
|
||||||
switch (await getConfigUnsafe("windowStyle")) {
|
switch (await getConfig("windowStyle")) {
|
||||||
case "default":
|
case "default":
|
||||||
createCustomWindow();
|
createCustomWindow();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {BrowserWindow, shell, ipcMain, app} from "electron";
|
import {BrowserWindow, shell, ipcMain, app} from "electron";
|
||||||
import {getConfigUnsafe, saveSettings, Settings} from "../utils";
|
import {getConfig, setConfigBulk, Settings} from "../utils";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
var settingsWindow: BrowserWindow;
|
var settingsWindow: BrowserWindow;
|
||||||
var instance: number = 0;
|
var instance: number = 0;
|
||||||
|
@ -26,10 +26,10 @@ export function createSettingsWindow() {
|
||||||
});
|
});
|
||||||
ipcMain.on("saveSettings", (event, args: Settings) => {
|
ipcMain.on("saveSettings", (event, args: Settings) => {
|
||||||
console.log(args);
|
console.log(args);
|
||||||
saveSettings(args);
|
setConfigBulk(args);
|
||||||
});
|
});
|
||||||
ipcMain.handle("getSetting", (event, toGet: string) => {
|
ipcMain.handle("getSetting", (event, toGet: string) => {
|
||||||
return getConfigUnsafe(toGet);
|
return getConfig(toGet);
|
||||||
});
|
});
|
||||||
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
|
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
|
|
28
src/utils.ts
28
src/utils.ts
|
@ -21,7 +21,7 @@ export async function sleep(ms: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkIfConfigIsBroken() {
|
export async function checkIfConfigIsBroken() {
|
||||||
if ((await getConfigUnsafe("0")) == "d") {
|
if ((await getConfig("0")) == "d") {
|
||||||
console.log("Detected a corrupted config");
|
console.log("Detected a corrupted config");
|
||||||
setup();
|
setup();
|
||||||
dialog.showErrorBox(
|
dialog.showErrorBox(
|
||||||
|
@ -50,30 +50,8 @@ export function setup() {
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//LEGACY WRAPPER
|
|
||||||
export function saveSettings(settings: Settings) {
|
|
||||||
console.log("Setting up ArmCord settings.");
|
|
||||||
setConfigBulk(
|
|
||||||
{
|
|
||||||
...settings,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
//LEGACY
|
|
||||||
export async function getConfigUnsafe(object: string) {
|
|
||||||
try {
|
|
||||||
const userDataPath = app.getPath("userData");
|
|
||||||
const storagePath = path.join(userDataPath, "/storage/");
|
|
||||||
let rawdata = fs.readFileSync(storagePath + "settings.json", "utf-8");
|
|
||||||
let returndata = JSON.parse(rawdata);
|
|
||||||
console.log(returndata[object]);
|
|
||||||
return returndata[object];
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Config probably doesn't exist yet. Returning setup value.");
|
|
||||||
firstRun = true;
|
|
||||||
return "setup";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export function getVersion() {
|
export function getVersion() {
|
||||||
//to-do better way of doing this
|
//to-do better way of doing this
|
||||||
return "3.1.0";
|
return "3.1.0";
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import {BrowserWindow, shell, app, ipcMain, dialog} from "electron";
|
import {BrowserWindow, shell, app, ipcMain, dialog} from "electron";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {contentPath} from "./main";
|
import {contentPath} from "./main";
|
||||||
import {checkIfConfigIsBroken, firstRun, getConfigUnsafe} from "./utils";
|
import {checkIfConfigIsBroken, firstRun, getConfig} from "./utils";
|
||||||
import {registerIpc} from "./ipc";
|
import {registerIpc} from "./ipc";
|
||||||
import contextMenu from "electron-context-menu";
|
import contextMenu from "electron-context-menu";
|
||||||
export let mainWindow: BrowserWindow;
|
export let mainWindow: BrowserWindow;
|
||||||
|
@ -31,10 +31,10 @@ function doAfterDefiningTheWindow() {
|
||||||
return callback({});
|
return callback({});
|
||||||
});
|
});
|
||||||
mainWindow.on("close", async (e) => {
|
mainWindow.on("close", async (e) => {
|
||||||
if (await getConfigUnsafe("minimizeToTray")) {
|
if (await getConfig("minimizeToTray")) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
} else if (!(await getConfigUnsafe("minimizeToTray"))) {
|
} else if (!(await getConfig("minimizeToTray"))) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue