From 0d55c30810326af5cedb27383779861d94dd54a9 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 19:07:00 +0100 Subject: [PATCH 1/8] Fix ArmCord not starting --- src/main.ts | 82 +++++++++++++++++++++++++++------------------------- src/tray.ts | 5 ++-- src/utils.ts | 21 ++++++++++---- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/main.ts b/src/main.ts index 842fa6a..370aa7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,16 @@ // Modules to control application life and create native browser window -import { app, BrowserWindow, ipcMain, shell, desktopCapturer, session } from "electron"; +import { + app, + BrowserWindow, + ipcMain, + shell, + desktopCapturer, + session, +} from "electron"; import * as path from "path"; import "v8-compile-cache"; import * as storage from "electron-json-storage"; -import { saveSettings, getVersion, setup } from "./utils"; +import { saveSettings, getVersion, setup, getConfigUnsafe } from "./utils"; import "./extensions/mods"; import "./extensions/plugin"; import "./tray"; @@ -11,7 +18,6 @@ import "./shortcuts"; var contentPath: string = "null"; var frame: boolean; var channel: string; -var titlebar: boolean; export var mainWindow: BrowserWindow; var settings: any; @@ -30,22 +36,21 @@ storage.has("settings", function (error, hasKey) { storage.get("settings", function (error, data: any) { if (error) throw error; console.log(data); - titlebar = data.customTitlebar; channel = data.channel; settings = data; - if ((titlebar = true)) { - frame = false; - } else { - frame = true; - } + }); +var titlebar:any = getConfigUnsafe("customTitlebar") +console.log(!titlebar) function createWindow() { mainWindow = new BrowserWindow({ width: 300, height: 350, title: "ArmCord", - icon: "./assets/ac_icon_transparent.png", - frame: frame, + darkTheme: true, + icon: path.join(__dirname, "/assets/icon_transparent.png"), + frame: !titlebar, + autoHideMenuBar: true, webPreferences: { preload: path.join(__dirname, "preload/preload.js"), }, @@ -81,9 +86,8 @@ function createWindow() { mainWindow.setSize(800, 600); }); ipcMain.on("restart", (event, arg) => { - app.relaunch(); - app.exit(); - + app.relaunch(); + app.exit(); }); ipcMain.on("saveSettings", (event, ...args) => { @@ -122,32 +126,32 @@ function createWindow() { app.whenReady().then(() => { createWindow(); -session - .fromPartition("some-partition") - .setPermissionRequestHandler((webContents, permission, callback) => { - const url = webContents.getURL(); //unused? + session + .fromPartition("some-partition") + .setPermissionRequestHandler((webContents, permission, callback) => { + const url = webContents.getURL(); //unused? - if (permission === "notifications") { - // Approves the permissions request - callback(true); - } - if (permission === "media") { - // Approves the permissions request - callback(true); - } - if (url.startsWith("discord://")) { - // Denies the permissions request - return callback(false); - } - if (url.startsWith("discord.com/science")) { - // Denies the permissions request - return callback(false); - } - if (url.startsWith("discord.com/tracing")) { - // Denies the permissions request - return callback(false); - } - }); + if (permission === "notifications") { + // Approves the permissions request + callback(true); + } + if (permission === "media") { + // Approves the permissions request + callback(true); + } + if (url.startsWith("discord://")) { + // Denies the permissions request + return callback(false); + } + if (url.startsWith("discord.com/science")) { + // Denies the permissions request + return callback(false); + } + if (url.startsWith("discord.com/tracing")) { + // Denies the permissions request + return callback(false); + } + }); app.on("activate", function () { if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); diff --git a/src/tray.ts b/src/tray.ts index e84ee85..8bd4057 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -1,8 +1,9 @@ import { app, Menu, Tray } from 'electron'; import {mainWindow} from './main'; +import * as path from 'path' let tray = null app.whenReady().then(() => { - tray = new Tray('./assets/ac_plug.png') + tray = new Tray(path.join(__dirname, "../", "/assets/ac_plug.png")) const contextMenu = Menu.buildFromTemplate([ { label: "Open ArmCord", @@ -25,6 +26,6 @@ app.whenReady().then(() => { }, ]); - tray.setToolTip('ArmCord' + process.env.npm_package_version) + tray.setToolTip('ArmCord ' + process.env.npm_package_version) tray.setContextMenu(contextMenu) }) \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index f59a220..9a9972f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,7 @@ -import * as fs from "fs"; import * as storage from "electron-json-storage"; +import * as fs from "fs"; +import { app } from "electron"; + //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,6 +23,7 @@ export function setup() { channel: "stable", firstRun: "done", armcordCSP: true, + mods: "none" }, function (error) { if (error) throw error; @@ -51,8 +54,16 @@ export function saveSettings( } ); } - -export function getVersion() { - const pkgjson = fs.readFileSync("./package.json", "utf8"); - return JSON.parse(pkgjson).version; +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] } +export function getVersion() { + //to-do better way of doing this + return '3.0.1'; +} + \ No newline at end of file From 3c4056a0fc9b4617f20f09ba7a0924eff84797f5 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 19:14:26 +0100 Subject: [PATCH 2/8] Add titlebar related stuff to context bridge --- src/preload/bridge.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/preload/bridge.ts b/src/preload/bridge.ts index f932325..5916881 100644 --- a/src/preload/bridge.ts +++ b/src/preload/bridge.ts @@ -1,6 +1,6 @@ import { contextBridge, ipcRenderer } from "electron"; import { getDisplayMediaSelector } from "./capturer"; - +import { injectTitlebar } from "./titlebar"; contextBridge.exposeInMainWorld("armcord", { window: { @@ -9,6 +9,9 @@ contextBridge.exposeInMainWorld("armcord", { minimize: () => ipcRenderer.send("win-minimize"), maximize: () => ipcRenderer.send("win-maximize"), }, + titlebar: { + injectTitlebar: () => injectTitlebar(), + }, electron: process.versions.electron, channel: ipcRenderer.sendSync("channel"), version: ipcRenderer.sendSync("get-app-version", "app-version"), From 92a452cea40b261b4e9b3939b9d669444db7bc6e Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 19:14:57 +0100 Subject: [PATCH 3/8] v3.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3deb972..e610754 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ArmCord", - "version": "3.0.0", + "version": "3.0.1", "description": "ArmCord is a custom client designed to enhance your Discord experience while keeping everything lightweight.", "main": "ts-out/main.js", "scripts": { From 883bee623695d52e52d46840fbd4b1c99f1ee60a Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:31:03 +0100 Subject: [PATCH 4/8] Fix Windows --- src/main.ts | 16 ++++++++++------ src/utils.ts | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 370aa7b..129dcec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,8 +15,7 @@ import "./extensions/mods"; import "./extensions/plugin"; import "./tray"; import "./shortcuts"; -var contentPath: string = "null"; -var frame: boolean; +var contentPath: string; var channel: string; export var mainWindow: BrowserWindow; var settings: any; @@ -27,10 +26,10 @@ storage.has("settings", function (error, hasKey) { if (!hasKey) { console.log("First run of the ArmCord. Starting setup."); setup(); - contentPath = __dirname + "/content/setup.html"; + contentPath = "content/setup.html"; } else { console.log("ArmCord has been run before. Skipping setup."); - contentPath = __dirname + "/content/splash.html"; + contentPath = "content/splash.html"; } }); storage.get("settings", function (error, data: any) { @@ -120,8 +119,13 @@ function createWindow() { shell.openExternal(url); return { action: "deny" }; }); - - mainWindow.loadFile(contentPath); + console.log(contentPath) + try { + mainWindow.loadFile(contentPath); + } catch(e) { + console.log("Major error detected while starting up. User is most likely on Windows platform. Fallback to alternative startup.") + mainWindow.loadURL(`file://${__dirname}/content/splash.html`); + } } app.whenReady().then(() => { diff --git a/src/utils.ts b/src/utils.ts index 9a9972f..902a2d1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -23,7 +23,7 @@ export function setup() { channel: "stable", firstRun: "done", armcordCSP: true, - mods: "none" + mods: "cumcord" }, function (error) { if (error) throw error; From 9fbfc778cc6e59254f7f85f7e4e026230b101278 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:31:36 +0100 Subject: [PATCH 5/8] v3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e610754..9ae640b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ArmCord", - "version": "3.0.1", + "version": "3.0.2", "description": "ArmCord is a custom client designed to enhance your Discord experience while keeping everything lightweight.", "main": "ts-out/main.js", "scripts": { From 6d2831d5c708eb358135c429aa20caccb71363c1 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:39:04 +0100 Subject: [PATCH 6/8] i broke linux --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 129dcec..e46374c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,10 +26,10 @@ storage.has("settings", function (error, hasKey) { if (!hasKey) { console.log("First run of the ArmCord. Starting setup."); setup(); - contentPath = "content/setup.html"; + contentPath = __dirname + "/content/setup.html"; } else { console.log("ArmCord has been run before. Skipping setup."); - contentPath = "content/splash.html"; + contentPath = __dirname + "/content/splash.html"; } }); storage.get("settings", function (error, data: any) { From 414dbb4f55cd32c082162ee4431f3ad79aa6945f Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:40:03 +0100 Subject: [PATCH 7/8] maybe not --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ae640b..e610754 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ArmCord", - "version": "3.0.2", + "version": "3.0.1", "description": "ArmCord is a custom client designed to enhance your Discord experience while keeping everything lightweight.", "main": "ts-out/main.js", "scripts": { From eb1e908b691d6a1c155db825aaccb98863dc0c02 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:40:14 +0100 Subject: [PATCH 8/8] v3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e610754..9ae640b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ArmCord", - "version": "3.0.1", + "version": "3.0.2", "description": "ArmCord is a custom client designed to enhance your Discord experience while keeping everything lightweight.", "main": "ts-out/main.js", "scripts": {