Compare commits

...

5 commits

Author SHA1 Message Date
smartfrigde
bac604a7cc Get rid of electron-json-storage and switch to our own solution 2022-04-18 13:03:26 +02:00
smartfrigde
9d2a1190cf Remove legacy config helper functions 2022-04-18 12:25:10 +02:00
smartfrigde
a39fe281f6 Add ArmCord storage manager 2022-04-18 12:20:38 +02:00
smartfrigde
40239159ed Fix corrupted config checker 2022-04-18 12:06:17 +02:00
smartfrigde
1a461e9a32 Backport things from stable branch back to dev 2022-04-18 12:05:06 +02:00
14 changed files with 1147 additions and 2307 deletions

3021
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -26,16 +26,14 @@
"@types/node": "^17.0.24",
"copyfiles": "^2.4.1",
"electron": "^18.0.4",
"electron-builder": "^23.0.3",
"electron-builder": "^22.5.1",
"husky": "^7.0.4",
"prettier": "^2.5.1",
"typescript": "^4.5.4"
},
"dependencies": {
"electron-context-menu": "^3.1.2",
"electron-json-storage": "^4.5.0",
"electron-tabs": "^0.17.0",
"glasstron": "^0.1.1",
"v8-compile-cache": "^2.3.0"
},
"build": {
@ -55,4 +53,4 @@
]
}
}
}
}

View file

@ -1,5 +1,5 @@
/*CSS ONLY FOR INTERNAL USE (setup and loading)*/
@import url("https://kckarnige.github.io/femboi_owo/discord-font.css");
@import url("https://armcord.smartfridge.space/logofont.css");
:root {
background-color: #2c2f33 !important;

View file

@ -1,4 +1,4 @@
@import url("https://kckarnige.github.io/femboi_owo/discord-font.css");
@import url("https://armcord.smartfridge.space/logofont.css");
:root {
--window-buttons: var(--header-secondary);
--cord-color: var(--header-primary);

View file

@ -22,7 +22,7 @@
text.innerHTML = "You appear to be offline. Please connect to the internet and try again.";
} else {
text.innerHTML = "Starting ArmCord...";
fetch("https://armcord.smartfridge.space/latest.json")
fetch("https://armcord.xyz/latest.json")
.then((response) => response.json())
.then((data) => {
if (data.version !== window.armcord.version) {

View file

@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import electron from "electron";
import * as storage from "electron-json-storage";
import {getConfig} from "../utils";
const otherMods = {
generic: {
electronProxy: require("util").types.isProxy(electron) // Many modern mods overwrite electron with a proxy with a custom BrowserWindow (copied from PowerCord)
@ -55,9 +55,9 @@ const unstrictCSP = () => {
done({responseHeaders});
});
};
storage.get("settings", function (error, data: any) {
if (error) throw error;
if (data.armcordCSP) {
electron.app.whenReady().then(async () => {
if (await getConfig("armcordCSP")) {
unstrictCSP();
} else {
console.log("ArmCord CSP is disabled. The CSP should be managed by third-party plugin.");

View file

@ -1,8 +1,8 @@
//ipc stuff
import {app, ipcMain, shell, desktopCapturer} from "electron";
import {createTabsGuest, mainWindow} from "./window";
import {saveSettings, getVersion} from "./utils";
import {settings, customTitlebar, tabs} from "./main";
import {setConfigBulk, getVersion, getConfig} from "./utils";
import {customTitlebar, tabs} from "./main";
import {createSettingsWindow} from "./settings/main";
export function registerIpc() {
ipcMain.on("get-app-path", (event, arg) => {
@ -46,17 +46,16 @@ export function registerIpc() {
app.exit();
});
ipcMain.on("saveSettings", (event, args) => {
saveSettings(args);
setConfigBulk(args);
});
ipcMain.on("minimizeToTray", (event) => {
console.log(settings.minimizeToTray);
event.returnValue = settings.minimizeToTray;
ipcMain.on("minimizeToTray", async (event) => {
event.returnValue = await getConfig("minimizeToTray");
});
ipcMain.on("channel", (event) => {
event.returnValue = settings.channel;
ipcMain.on("channel", async (event) => {
event.returnValue = await getConfig("channel");
});
ipcMain.on("clientmod", (event, arg) => {
event.returnValue = settings.mods;
ipcMain.on("clientmod", async (event, arg) => {
event.returnValue = await getConfig("mods");
});
ipcMain.on("titlebar", (event, arg) => {
event.returnValue = customTitlebar;
@ -64,14 +63,14 @@ export function registerIpc() {
ipcMain.on("tabs", (event, arg) => {
event.returnValue = tabs;
});
ipcMain.on("shouldPatch", (event, arg) => {
event.returnValue = settings.automaticPatches;
ipcMain.on("shouldPatch", async (event, arg) => {
event.returnValue = await getConfig("automaticPatches");
});
ipcMain.on("openSettingsWindow", (event, arg) => {
createSettingsWindow();
});
ipcMain.on("setting-armcordCSP", (event) => {
if (settings.armcordCSP) {
ipcMain.on("setting-armcordCSP", async (event) => {
if (await getConfig("armcordCSP")) {
event.returnValue = true;
} else {
event.returnValue = false;

View file

@ -1,52 +1,21 @@
// Modules to control application life and create native browser window
import {app, BrowserWindow, session} from "electron";
import * as path from "path";
import {app, BrowserWindow, session, dialog} from "electron";
import "v8-compile-cache";
import * as storage from "electron-json-storage";
import {getConfigUnsafe, setup} from "./utils";
import {getConfig, setup, checkIfConfigExists} from "./utils";
import "./extensions/mods";
import "./extensions/plugin";
import "./tray";
import {mainWindow, createCustomWindow, createNativeWindow, createGlasstronWindow, createTabsHost} from "./window";
import {createCustomWindow, createNativeWindow, createTabsHost} from "./window";
import "./shortcuts";
export var contentPath: string;
var channel: string;
export var settings: any;
export var customTitlebar: boolean;
export var tabs: boolean;
async function appendSwitch() {
if ((await getConfigUnsafe("windowStyle")) == "glasstron") {
console.log("Enabling transparency visuals.");
app.commandLine.appendSwitch("enable-transparent-visuals");
}
}
appendSwitch();
storage.has("settings", function (error, hasKey) {
if (error) throw error;
if (!hasKey) {
console.log("First run of the ArmCord. Starting setup.");
setup();
contentPath = path.join(__dirname, "/content/setup.html");
if (!contentPath.includes("ts-out")) {
contentPath = path.join(__dirname, "/ts-out/content/setup.html");
}
} else {
console.log("ArmCord has been run before. Skipping setup.");
contentPath = path.join(__dirname, "/content/splash.html");
if (!contentPath.includes("ts-out")) {
contentPath = path.join(__dirname, "/ts-out/content/splash.html");
}
}
});
storage.get("settings", function (error, data: any) {
if (error) throw error;
console.log(data);
channel = data.channel;
settings = data;
});
checkIfConfigExists();
app.whenReady().then(async () => {
switch (await getConfigUnsafe("windowStyle")) {
switch (await getConfig("windowStyle")) {
case "default":
createCustomWindow();
customTitlebar = true;
@ -55,15 +24,11 @@ app.whenReady().then(async () => {
createNativeWindow();
break;
case "glasstron":
setTimeout(
createGlasstronWindow,
process.platform == "linux" ? 1000 : 0
// Electron has a bug on linux where it
// won't initialize properly when using
// transparency. To work around that, it
// is necessary to delay the window
// spawn function.
dialog.showErrorBox(
"Glasstron is unsupported.",
"This build doesn't include Glasstron functionality, please edit windowStyle value in your settings.json to something different (default for example)"
);
app.quit();
break;
case "tabs":
createTabsHost();
@ -86,7 +51,7 @@ app.whenReady().then(async () => {
});
app.on("activate", async function () {
if (BrowserWindow.getAllWindows().length === 0)
switch (await getConfigUnsafe("windowStyle")) {
switch (await getConfig("windowStyle")) {
case "default":
createCustomWindow();
break;
@ -94,7 +59,15 @@ app.whenReady().then(async () => {
createNativeWindow();
break;
case "glasstron":
createGlasstronWindow();
dialog.showErrorBox(
"Glasstron is unsupported.",
"This build doesn't include Glasstron functionality, please edit windowStyle value in your settings.json to something different (default for example)"
);
app.quit();
break;
case "tabs":
createTabsHost();
tabs = true;
break;
default:
createCustomWindow();

View file

@ -1,18 +1,17 @@
import {BrowserWindow, shell, ipcMain} from "electron";
import * as storage from "electron-json-storage";
import {getConfigUnsafe, saveSettings, Settings} from "../utils";
import {getConfig, setConfigBulk, Settings} from "../utils";
import path from "path";
var settings: any;
var isAlreadyCreated: boolean = false;
storage.get("settings", function (error, data: any) {
if (error) throw error;
console.log(data);
settings = data;
});
var settingsWindow: BrowserWindow;
var instance: number = 0;
export function createSettingsWindow() {
if (isAlreadyCreated) {
settingsWindow.show();
console.log("Creating a settings window.");
instance = instance + 1;
if (instance > 1) {
if (settingsWindow) {
settingsWindow.show();
settingsWindow.restore();
}
} else {
settingsWindow = new BrowserWindow({
width: 500,
@ -27,20 +26,20 @@ export function createSettingsWindow() {
});
ipcMain.on("saveSettings", (event, args: Settings) => {
console.log(args);
saveSettings(args);
setConfigBulk(args);
});
ipcMain.handle("getSetting", (event, toGet: string) => {
return getConfigUnsafe(toGet);
return getConfig(toGet);
});
settingsWindow.webContents.setWindowOpenHandler(({url}) => {
shell.openExternal(url);
return {action: "deny"};
});
settingsWindow.loadURL(`file://${__dirname}/settings.html`);
settingsWindow.on("close", async (e) => {
e.preventDefault();
settingsWindow.hide();
settingsWindow.on("close", (event: Event) => {
ipcMain.removeHandler("getSetting");
ipcMain.removeAllListeners("saveSettings");
instance = 0;
});
isAlreadyCreated = true;
}
}

View file

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<title>ArmCord Settings</title>
<style>
@import url("settings.css");
@import url("../content/css/settings.css");
</style>
</head>
@ -13,8 +13,6 @@
<select name="theme" id="theme" class="left">
<option value="default">Default</option>
<option value="native">Native</option>
<option value="glasstron">Glasstron (experimental)</option>
<option value="tabs">Tabs (experimental)</option>
</select>
<p class="header">ArmCord theme:</p>
</div>
@ -53,15 +51,7 @@
</select>
<p class="header">Client mod:</p>
</div>
<div class="switch">
<select name="blurType" id="blurType" class="left">
<option value="acrylic">Acrylic</option>
<option value="blurbehind">Blur Behind</option>
<option value="transparent">Transparent</option>
<option value="none">None</option>
</select>
<p class="header">Glasstron blur type:</p>
</div>
<button id="save" class="center">Save settings</button>
</body>
@ -73,20 +63,19 @@
document.getElementById("mod").value = await settings.get("mods");
document.getElementById("channel").value = await settings.get("channel");
document.getElementById("theme").value = await settings.get("windowStyle");
document.getElementById("blurType").value = await settings.get("blurType");
}
loadSettings();
document.getElementById("save").addEventListener("click", function () {
//function saveSettings(windowStyle: string, channelSetting: string, armcordCSPSetting: boolean, minimizeToTray: boolean, automaticPatches: boolean,modsSetting: string, blurType: string)
settings.save(
document.getElementById("theme").value,
document.getElementById("channel").value,
document.getElementById("csp").checked,
document.getElementById("tray").checked,
document.getElementById("patches").checked,
document.getElementById("mod").value,
document.getElementById("blurType").value
);
settings.save({
windowStyle: document.getElementById("theme").value,
channel: document.getElementById("channel").value,
armcordCSP: document.getElementById("csp").checked,
minimizeToTray: document.getElementById("tray").checked,
automaticPatches: document.getElementById("patches").checked,
mods: document.getElementById("mod").value,
blurType: "acrylic"
});
});
</script>
</html>

View file

@ -1,70 +0,0 @@
declare module "glasstron" {
export class BrowserWindow extends Electron.BrowserWindow {
getBlur(): Promise<boolean>;
setBlur(value: boolean): Promise<boolean>;
blurType: WindowsBlurType;
setVibrancy(vibrancy: MacOSVibrancy): void;
}
/**
* @deprecated
*/
export function init(): void;
/**
* @deprecated
*/
export function update(
window: Electron.BrowserWindow,
values: {
windows?: {
blurType: WindowsBlurType;
};
macos?: {
vibrancy: MacOSVibrancy;
};
linux?: {
requestBlur: boolean;
};
}
): void;
export class Hacks {
static injectOnElectron(): void;
static delayReadyEvent(): void;
}
export type WindowsBlurType = "acrylic" | "blurbehind" | "transparent" | "none";
export type MacOSVibrancy =
| (
| "appearance-based"
| "light"
| "dark"
| "titlebar"
| "selection"
| "menu"
| "popover"
| "sidebar"
| "medium-light"
| "ultra-dark"
| "header"
| "sheet"
| "window"
| "hud"
| "fullscreen-ui"
| "tooltip"
| "content"
| "under-window"
| "under-page"
)
| null;
}
declare module "glasstron/src/utils" {
class Utils {
static getSavePath(): string;
static copyToPath(innerFile: string, outerFilename?: string, flags?: number): void;
static removeFromPath(filename: string): void;
static isInPath(filename: string): boolean;
static getPlatform(): any;
static parseKeyValString(string: string, keyvalSeparator?: string, pairSeparator?: string): any;
static makeKeyValString(object: any, keyvalSeparator?: string, pairSeparator?: string): string;
}
export = Utils;
}

View file

@ -1,9 +1,8 @@
import * as storage from "electron-json-storage";
import * as fs from "fs";
import {app} from "electron";
import {app, dialog} from "electron";
import path from "path";
export var firstRun: boolean;
export var contentPath: string;
//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) {
const style = document.createElement("style");
@ -21,21 +20,17 @@ export async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export async function checkIfConfigIsNew() {
if ((await getConfigUnsafe("automaticPatches")) == undefined) {
firstRun = true;
export async function checkIfConfigIsBroken() {
if ((await getConfig("0")) == "d") {
console.log("Detected a corrupted config");
setup();
dialog.showErrorBox(
"Oops, something went wrong.",
"ArmCord has detected that your configuration file is corrupted, please restart the app and set your settings again. If this issue persists, report it on the support server/Github issues."
);
}
}
export interface Settings {
windowStyle: string;
channel: string;
armcordCSP: boolean;
minimizeToTray: boolean;
automaticPatches: boolean;
mods: string;
blurType: string;
}
export function setup() {
console.log("Setting up temporary ArmCord settings.");
const defaults: Settings = {
@ -45,47 +40,14 @@ export function setup() {
minimizeToTray: true,
automaticPatches: false,
mods: "cumcord",
blurType: "acrylic"
blurType: "acrylic",
doneSetup: false
};
storage.set(
"settings",
{
...defaults,
doneSetup: false
},
function (error) {
if (error) throw error;
}
);
setConfigBulk({
...defaults
});
}
export function saveSettings(settings: Settings) {
console.log("Setting up ArmCord settings.");
storage.set(
"settings",
{
...settings,
doneSetup: true
},
function (error) {
if (error) throw error;
}
);
}
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() {
//to-do better way of doing this
return "3.1.0";
@ -99,3 +61,79 @@ export async function injectJS(inject: string) {
document.body.appendChild(el);
}
//ArmCord Settings/Storage manager
export interface Settings {
windowStyle: string;
channel: string;
armcordCSP: boolean;
minimizeToTray: boolean;
automaticPatches: boolean;
mods: string;
blurType: string;
doneSetup: boolean;
}
export async function getConfig(object: string) {
try {
const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/");
const settingsFile = storagePath + "settings.json";
let rawdata = fs.readFileSync(settingsFile, "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 async function setConfig(object: string, toSet: any) {
try {
const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/");
const settingsFile = storagePath + "settings.json";
let rawdata = fs.readFileSync(settingsFile, "utf-8");
let parsed = JSON.parse(rawdata);
parsed[object] = toSet;
let toSave = JSON.stringify(parsed);
fs.writeFileSync(settingsFile, toSave, "utf-8");
} catch (e) {
console.log("Config probably doesn't exist yet. Returning setup value.");
firstRun = true;
return "setup";
}
}
export async function setConfigBulk(object: Settings) {
try {
const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/");
const settingsFile = storagePath + "settings.json";
let toSave = JSON.stringify(object);
fs.writeFileSync(settingsFile, toSave, "utf-8");
} catch (e) {
console.log("Config probably doesn't exist yet. Returning setup value.");
firstRun = true;
return "setup";
}
}
export async function checkIfConfigExists() {
const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/");
const settingsFile = storagePath + "settings.json";
if (!fs.existsSync(settingsFile)) {
console.log("First run of the ArmCord. Starting setup.");
setup();
contentPath = path.join(__dirname, "/content/setup.html");
if (!contentPath.includes("ts-out")) {
contentPath = path.join(__dirname, "/ts-out/content/setup.html");
}
} else {
console.log("ArmCord has been run before. Skipping setup.");
contentPath = path.join(__dirname, "/content/splash.html");
if (!contentPath.includes("ts-out")) {
contentPath = path.join(__dirname, "/ts-out/content/splash.html");
}
}
}

View file

@ -2,14 +2,12 @@
// I had to add most of the window creation code here to split both into seperete functions
// WHY? Because I can't use the same code for both due to annoying bug with value `frame` not responding to variables
// I'm sorry for this mess but I'm not sure how to fix it.
import {BrowserWindow, shell, app, ipcMain} from "electron";
import {BrowserWindow, shell, app, ipcMain, dialog} from "electron";
import path from "path";
import {contentPath} from "./main";
import {checkIfConfigIsNew, firstRun, getConfigUnsafe} from "./utils";
import {checkIfConfigIsBroken, firstRun, getConfig, contentPath} from "./utils";
import {registerIpc} from "./ipc";
import contextMenu from "electron-context-menu";
export let mainWindow: BrowserWindow;
import * as glasstron from "glasstron";
let guestWindows: BrowserWindow[] = [];
contextMenu({
@ -19,7 +17,7 @@ contextMenu({
});
function doAfterDefiningTheWindow() {
checkIfConfigIsNew();
checkIfConfigIsBroken();
registerIpc();
mainWindow.webContents.userAgent =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"; //fake useragent for screenshare to work
@ -32,12 +30,11 @@ function doAfterDefiningTheWindow() {
return callback({});
});
mainWindow.on("close", async (e) => {
if (await getConfigUnsafe("minimizeToTray")) {
if (await getConfig("minimizeToTray")) {
e.preventDefault();
mainWindow.hide();
} else if (!(await getConfigUnsafe("minimizeToTray"))) {
} else if (!(await getConfig("minimizeToTray"))) {
e.preventDefault();
app.exit();
app.quit();
}
});
@ -96,28 +93,12 @@ export function createNativeWindow() {
});
doAfterDefiningTheWindow();
}
export function createGlasstronWindow() {
mainWindow = new glasstron.BrowserWindow({
width: 300,
height: 350,
title: "ArmCord",
darkTheme: true,
icon: path.join(__dirname, "/assets/icon_transparent.png"),
frame: true,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, "preload/preload.js"),
spellcheck: true
}
});
//@ts-expect-error
mainWindow.blurType = getConfigUnsafe("blurType");
//@ts-expect-error
mainWindow.setBlur(true);
doAfterDefiningTheWindow();
}
export function createTabsHost() {
dialog.showErrorBox(
"READ THIS BEFORE USING THE APP",
"ArmCord Tabs are highly experimental and should be only used for strict testing purposes. Please don't ask for support, however you can still report bugs!"
);
guestWindows[1] = mainWindow;
mainWindow = new BrowserWindow({
width: 300,