+
+
+
diff --git a/src/content/index.html b/src/content/splash.html
similarity index 100%
rename from src/content/index.html
rename to src/content/splash.html
diff --git a/src/extensions/mods.ts b/src/extensions/mods.ts
index 5581e3b..6dfc5d6 100644
--- a/src/extensions/mods.ts
+++ b/src/extensions/mods.ts
@@ -8,36 +8,35 @@ 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 electron from "electron";
+import * as storage from "electron-json-storage";
const otherMods = {
- generic: {
- electronProxy: require('util').types.isProxy(electron) // Many modern mods overwrite electron with a proxy with a custom BrowserWindow (copied from PowerCord)
- }
- };
+ generic: {
+ electronProxy: require("util").types.isProxy(electron), // Many modern mods overwrite electron with a proxy with a custom BrowserWindow (copied from PowerCord)
+ },
+};
+
const unstrictCSP = () => {
- console.log('Setting up CSP unstricter...');
+ console.log("Setting up CSP unstricter...");
- const cspAllowAll = [
- 'connect-src',
- 'style-src',
- 'img-src',
- 'font-src'
- ];
+ const cspAllowAll = ["connect-src", "style-src", "img-src", "font-src"];
- const corsAllowUrls = [
- 'https://github.com/GooseMod/GooseMod/releases/download/dev/index.js',
- 'https://github-releases.githubusercontent.com/',
- 'https://raw.githubusercontent.com/Cumcord/Cumcord/stable/dist/build.js',
- 'https://raw.githubusercontent.com/Cumcord/Cumcord/master/dist/build.js',
- 'https://raw.githubusercontent.com/FlickerMod/dist/main/build.js'
- ];
+ const corsAllowUrls = [
+ "https://github.com/GooseMod/GooseMod/releases/download/dev/index.js",
+ "https://github-releases.githubusercontent.com/",
+ "https://api.goosemod.com/inject.js",
+ "https://raw.githubusercontent.com/Cumcord/Cumcord/stable/dist/build.js",
+ "https://raw.githubusercontent.com/Cumcord/Cumcord/master/dist/build.js",
+ "https://raw.githubusercontent.com/FlickerMod/dist/main/build.js",
+ ];
- electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, done) => {
- let csp = responseHeaders!['content-security-policy'];
+ electron.session.defaultSession.webRequest.onHeadersReceived(
+ ({ responseHeaders, url }, done) => {
+ let csp = responseHeaders!["content-security-policy"];
- if (otherMods.generic.electronProxy) { // Since patch v16, override other mod's onHeadersRecieved (Electron only allows 1 listener); because they rely on 0 CSP at all (GM just unrestricts some areas), remove it fully if we detect other mods
- delete responseHeaders!['content-security-policy'];
+ if (otherMods.generic.electronProxy) {
+ // Since patch v16, override other mod's onHeadersRecieved (Electron only allows 1 listener); because they rely on 0 CSP at all (GM just unrestricts some areas), remove it fully if we detect other mods
+ delete responseHeaders!["content-security-policy"];
csp = [];
}
@@ -47,21 +46,24 @@ const unstrictCSP = () => {
}
// Fix Discord's broken CSP which disallows unsafe-inline due to having a nonce (which they don't even use?)
- csp[0] = csp[0].replace(/'nonce-.*?' /, '');
+ csp[0] = csp[0].replace(/'nonce-.*?' /, "");
}
if (corsAllowUrls.some((x) => url.startsWith(x))) {
- responseHeaders!['access-control-allow-origin'] = ['*'];
+ responseHeaders!["access-control-allow-origin"] = ["*"];
}
done({ responseHeaders });
- });
- };
- storage.get('settings', function(error, data:any) {
- if (error) throw error;
- if (data.armcordCSP) {
- unstrictCSP();
- } else {
- console.log('ArmCord CSP is disabled. The CSP should be managed by third-party plugin.');
}
- });
+ );
+};
+storage.get("settings", function (error, data: any) {
+ if (error) throw error;
+ if (data.armcordCSP) {
+ unstrictCSP();
+ } else {
+ console.log(
+ "ArmCord CSP is disabled. The CSP should be managed by third-party plugin."
+ );
+ }
+});
diff --git a/src/main.ts b/src/main.ts
index 1c242e9..ec88964 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -3,13 +3,15 @@ import { app, BrowserWindow, ipcMain, shell, desktopCapturer } from "electron";
import * as path from "path";
import "v8-compile-cache";
import * as storage from "electron-json-storage";
-import { setup } from "./utils";
+import { saveSettings } from "./utils";
+import "./extensions/mods";
import "./extensions/plugin";
import "./tray";
var isSetup = null;
var contentPath: string = "null";
var frame: boolean;
export var mainWindow: BrowserWindow;
+
storage.keys(function (error, keys) {
if (error) throw error;
@@ -17,18 +19,18 @@ storage.keys(function (error, keys) {
console.log("There is a key called: " + key);
}
});
-storage.has("firstRun", function (error, hasKey) {
+storage.has("settings", function (error, hasKey) {
if (error) throw error;
if (!hasKey) {
console.log("First run of the ArmCord. Starting setup.");
isSetup = true;
- setup();
+ // setup(); will be done at setup
contentPath = __dirname + "/content/setup.html";
} else {
console.log("ArmCord has been run before. Skipping setup.");
isSetup = false;
- contentPath = __dirname + "/content/index.html";
+ contentPath = __dirname + "/content/splash.html";
}
});
storage.get("settings", function (error, data: any) {
@@ -78,7 +80,30 @@ function createWindow() {
mainWindow.setSize(800, 600);
});
ipcMain.on("channel", (event) => {
- event.returnValue = storage.getSync("channel");
+ storage.get("settings", function (error, data: any) {
+ if (error) throw error;
+ event.returnValue = data.channel;
+ });
+ });
+ ipcMain.on("saveSettings", (event, ...args) => {
+ //@ts-ignore
+ saveSettings(...args);
+ });
+ ipcMain.on('clientmod' , (event, arg) => {
+ storage.get("settings", function (error, data: any) {
+ if (error) throw error;
+ event.returnValue = data.mods;
+ });
+ })
+ ipcMain.on("setting-armcordCSP", (event) => {
+ storage.get("settings", function (error, data: any) {
+ if (error) throw error;
+ if (data.armcordCSP) {
+ event.returnValue = true;
+ } else {
+ event.returnValue = false;
+ }
+ });
});
ipcMain.handle("DESKTOP_CAPTURER_GET_SOURCES", (event, opts) =>
desktopCapturer.getSources(opts)
diff --git a/src/preload/bridge.ts b/src/preload/bridge.ts
index 1fac186..78f84db 100644
--- a/src/preload/bridge.ts
+++ b/src/preload/bridge.ts
@@ -1,7 +1,8 @@
-
import { contextBridge, ipcRenderer } from 'electron';
import {getDisplayMediaSelector} from './capturer';
+console.log(ipcRenderer.send('channel'))
+
contextBridge.exposeInMainWorld("armcord", {
window: {
show: () => ipcRenderer.send('win-show'),
@@ -12,6 +13,8 @@ contextBridge.exposeInMainWorld("armcord", {
electron: process.versions.electron,
version: ipcRenderer.send('get-app-version', 'app-version'),
getDisplayMediaSelector: getDisplayMediaSelector,
+ saveSettings: (...args: any) => ipcRenderer.send('saveSettings', ...args),
splashEnd: () => ipcRenderer.send('splashEnd'),
channel: ipcRenderer.send('channel')
-});
\ No newline at end of file
+});
+contextBridge.exposeInMainWorld("electron", {}) //deprecated, used for legacy purposes, will be removed in future versions
\ No newline at end of file
diff --git a/src/preload/preload.ts b/src/preload/preload.ts
index 108a374..71d26bb 100644
--- a/src/preload/preload.ts
+++ b/src/preload/preload.ts
@@ -1,6 +1,46 @@
import "./capturer";
import "./bridge";
import { injectTitlebar } from "./titlebar";
+import { ipcRenderer } from "electron";
+declare global {
+ interface Window {
+ splash: any;
+ }
+}
+
+const clientMods = {
+ goosemod: "https://api.goosemod.com/inject.js",
+ cumcord:
+ "https://raw.githubusercontent.com/Cumcord/Cumcord/stable/dist/build.js",
+ flicker: "https://raw.githubusercontent.com/FlickerMod/dist/main/build.js",
+};
+async function injectJS(inject: string) {
+ const js = await (await fetch(`${inject}`)).text();
+
+ const el = document.createElement("script");
+
+ el.appendChild(document.createTextNode(js));
+
+ document.body.appendChild(el);
+}
-injectTitlebar();
console.log("ArmCord");
+if (window.location.href.indexOf("splash.html") > -1) {
+ console.log("Skipping titlebar injection and client mod injection.");
+} else {
+ injectTitlebar();
+ switch (ipcRenderer.sendSync("clientmod")) {
+ case "goosemod":
+ injectJS(clientMods.goosemod);
+ console.log("Loading GooseMod...");
+ break;
+ case "cumcord":
+ injectJS(clientMods.cumcord);
+ console.log("Loading Cumcord...");
+ break;
+ case "flicker":
+ injectJS(clientMods.flicker);
+ console.log("Loading FlickerMod...");
+ break;
+ }
+}
diff --git a/src/utils.ts b/src/utils.ts
index 8c29e92..e88950a 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,7 +1,4 @@
-/*--------------------------------------------------------------------------------------------------------
- * This file has parts of one or more project files (VS Code) from Microsoft
- * You can check your respective license and the original file in https://github.com/Microsoft/vscode/
- *-------------------------------------------------------------------------------------------------------*/
+
import * as storage from 'electron-json-storage';
//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) {
@@ -21,10 +18,12 @@ export function setup(){
if (error) throw error;
});
}
-export function append(parent: HTMLElement, ...children: T[]): T {
- children.forEach(child => parent.appendChild(child));
- return children[children.length - 1];
-}
export async function sleep(ms:number) {
return new Promise(resolve => setTimeout(resolve, ms));
+}
+export function saveSettings(customTitlebarSetting: boolean, channelSetting: string, armcordCSPSetting: boolean, modsSetting: string) {
+ console.log("Setting up ArmCord settings.");
+ storage.set('settings', { customTitlebar: customTitlebarSetting, channel: channelSetting, firstRun: 'done', armcordCSP: armcordCSPSetting, mods: modsSetting }, function(error) {
+ if (error) throw error;
+ });
}
\ No newline at end of file