From d6cbbcba7da2f26f18c55145958c4641f97d556b Mon Sep 17 00:00:00 2001 From: smartfridge <37928912+smartfrigde@users.noreply.github.com> Date: Mon, 11 Jul 2022 19:13:52 +0200 Subject: [PATCH] Add mobile mode --- .idea/.gitignore | 5 +++++ .idea/ArmCord.iml | 12 ++++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ assets/lang/en-US.json | 1 + src/content/css/mobile.css | 6 ++++++ src/content/setup.html | 6 +++--- src/content/splash.html | 3 --- src/ipc.ts | 3 +++ src/preload/mobile.ts | 19 +++++++++++++++++++ src/preload/preload.ts | 4 ++++ src/settings/settings.html | 10 +++++++++- src/tray.ts | 12 +++++++----- src/utils.ts | 15 +++++++++++++-- src/window.ts | 14 +++++++++----- 15 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/ArmCord.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 src/content/css/mobile.css create mode 100644 src/preload/mobile.ts diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/ArmCord.iml b/.idea/ArmCord.iml new file mode 100644 index 0000000..0c8867d --- /dev/null +++ b/.idea/ArmCord.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0f0b0aa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/assets/lang/en-US.json b/assets/lang/en-US.json index e598f49..5c963b1 100644 --- a/assets/lang/en-US.json +++ b/assets/lang/en-US.json @@ -18,6 +18,7 @@ "settings-theme-native": "Native", "settings-tray": "Minimize to tray", "settings-patches": "Automatic Patches", + "settings-mobileMode": "Mobile mode", "settings-channel": "Discord channel:", "settings-invitewebsocket": "Invite Websocket", "settings-mod": "Client mod:", diff --git a/src/content/css/mobile.css b/src/content/css/mobile.css new file mode 100644 index 0000000..a71ed39 --- /dev/null +++ b/src/content/css/mobile.css @@ -0,0 +1,6 @@ +[aria-label~="Mute"] { + display: none; +} +[aria-label~="Deafen"] { + display: none; +} diff --git a/src/content/setup.html b/src/content/setup.html index dfc317e..a19c248 100644 --- a/src/content/setup.html +++ b/src/content/setup.html @@ -31,7 +31,6 @@ -

@@ -121,6 +120,7 @@ automaticPatches: false, mods: "cumcord", inviteWebsocket: true, + mobileMode: false, trayIcon: "ac_plug_colored", performanceMode: "none" }); @@ -148,8 +148,8 @@ windowStyle: "default", channel: options.channel, armcordCSP: true, - autoLaunch: true, minimizeToTray: true, + mobileMode: false, automaticPatches: false, performanceMode: "none", trayIcon: "ac_plug_colored", @@ -165,7 +165,7 @@ armcordCSP: true, minimizeToTray: true, automaticPatches: false, - autoLaunch: true, + mobileMode: false, mods: "none", performanceMode: "none", trayIcon: "ac_plug_colored", diff --git a/src/content/splash.html b/src/content/splash.html index 90b6fcb..8bca30c 100644 --- a/src/content/splash.html +++ b/src/content/splash.html @@ -58,9 +58,6 @@ case "ptb": window.location.replace("https://ptb.discord.com/app"); break; - case "foss": - window.location.replace("https://dev.fosscord.com/app"); - break; case undefined: window.location.replace("https://discord.com/app"); break; diff --git a/src/ipc.ts b/src/ipc.ts index 52e1c68..bc41125 100644 --- a/src/ipc.ts +++ b/src/ipc.ts @@ -83,6 +83,9 @@ export function registerIpc() { ipcMain.on("titlebar", (event, arg) => { event.returnValue = customTitlebar; }); + ipcMain.on("mobileMode", async (event, arg) => { + event.returnValue = await getConfig("mobileMode"); + }); ipcMain.on("shouldPatch", async (event, arg) => { event.returnValue = await getConfig("automaticPatches"); }); diff --git a/src/preload/mobile.ts b/src/preload/mobile.ts new file mode 100644 index 0000000..213deb6 --- /dev/null +++ b/src/preload/mobile.ts @@ -0,0 +1,19 @@ +import {ipcRenderer} from "electron"; +import {addStyle} from "../utils"; +import * as fs from "fs"; +import * as path from "path"; +export function injectMobileStuff() { + document.addEventListener("DOMContentLoaded", function (event) { + const mobileCSS = path.join(__dirname, "../", "/content/css/mobile.css"); + addStyle(fs.readFileSync(mobileCSS, "utf8")); + + var logo = document.getElementById("window-title"); + logo!.addEventListener("click", () => { + if (ipcRenderer.sendSync("minimizeToTray") === true) { + ipcRenderer.send("win-hide"); + } else if (ipcRenderer.sendSync("minimizeToTray") === false) { + ipcRenderer.send("win-quit"); + } + }); + }); +} diff --git a/src/preload/preload.ts b/src/preload/preload.ts index 6089430..5f91140 100644 --- a/src/preload/preload.ts +++ b/src/preload/preload.ts @@ -6,6 +6,7 @@ import * as path from "path"; import {injectTitlebar} from "./titlebar"; import {sleep, addStyle, injectJS, addScript} from "../utils"; import {ipcRenderer} from "electron"; +import {injectMobileStuff} from "./mobile"; var version = ipcRenderer.sendSync("get-app-version", "app-version"); async function updateLang() { if (window.location.href.indexOf("setup.html") > -1) { @@ -37,6 +38,9 @@ if (window.location.href.indexOf("splash.html") > -1) { if (ipcRenderer.sendSync("titlebar")) { injectTitlebar(); } + if (ipcRenderer.sendSync("mobileMode")) { + injectMobileStuff(); + } sleep(5000).then(async () => { const cssPath = path.join(__dirname, "../", "/content/css/discord.css"); addStyle(fs.readFileSync(cssPath, "utf8")); diff --git a/src/settings/settings.html b/src/settings/settings.html index 31e38ff..8b7ab13 100644 --- a/src/settings/settings.html +++ b/src/settings/settings.html @@ -40,12 +40,17 @@ +
+

+ + + +

Discord channel:

@@ -89,6 +94,7 @@ ); document.getElementById("settings-patches").innerHTML = await settings.getLang("settings-patches"); document.getElementById("settings-tray").innerHTML = await settings.getLang("settings-tray"); + document.getElementById("settings-mobileMode").innerHTML = await settings.getLang("settings-mobileMode"); document.getElementById("settings-theme").innerHTML = await settings.getLang("settings-theme"); //select stuff document.getElementById("mod").options[3].text = await settings.getLang("settings-none"); @@ -107,6 +113,7 @@ document.getElementById("csp").checked = await settings.get("armcordCSP"); document.getElementById("tray").checked = await settings.get("minimizeToTray"); document.getElementById("websocket").checked = await settings.get("inviteWebsocket"); + document.getElementById("mobile").checked = await settings.get("mobileMode"); document.getElementById("patches").value = await settings.get("automaticPatches"); document.getElementById("mod").value = await settings.get("mods"); document.getElementById("channel").value = await settings.get("channel"); @@ -123,6 +130,7 @@ minimizeToTray: document.getElementById("tray").checked, automaticPatches: document.getElementById("patches").checked, mods: document.getElementById("mod").value, + mobileMode: document.getElementById("mobile").checked, inviteWebsocket: document.getElementById("websocket").checked, performanceMode: document.getElementById("prfmMode").value, trayIcon: document.getElementById("trayIcon").value, diff --git a/src/tray.ts b/src/tray.ts index 9241e8e..3d8731a 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import { app, Menu, Tray } from "electron"; +import { app, Menu, Tray, nativeImage} from "electron"; import { mainWindow } from "./window"; import { getConfig, getConfigLocation, setWindowState } from "./utils"; import * as path from "path"; @@ -7,10 +7,13 @@ import { createSettingsWindow } from "./settings/main"; let tray: any = null; app.whenReady().then(async () => { let finishedSetup = (await getConfig("doneSetup")); + var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored"; + let trayPath = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/${trayIcon}.png`)); + if(process.platform === "darwin" && trayPath.getSize().height > 22) + trayPath = trayIcon.resize({height: 22}); if ((await getConfig("windowStyle")) == "basic") { var clientName = (await getConfig("clientName")) ?? "ArmCord"; - var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored"; - tray = new Tray(path.join(__dirname, "../", `/assets/${trayIcon}.png`)); + tray = new Tray(trayPath); const contextMenu = function () { if (finishedSetup == false) { return Menu.buildFromTemplate([ @@ -57,8 +60,7 @@ app.whenReady().then(async () => { tray.setContextMenu(contextMenu); } else { var clientName = (await getConfig("clientName")) ?? "ArmCord"; - var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored"; - tray = new Tray(path.join(__dirname, "../", `/assets/${trayIcon}.png`)); + tray = new Tray(trayPath); if (finishedSetup == false) { const contextMenu = Menu.buildFromTemplate([ { diff --git a/src/utils.ts b/src/utils.ts index 6c0ef26..d51256c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,7 +4,7 @@ import path from "path"; export var firstRun: boolean; export var isSetup: 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 +//utility 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"); style.textContent = styleString; @@ -43,6 +43,7 @@ export function setup() { mods: "cumcord", performanceMode: "none", inviteWebsocket: true, + mobileMode: false, trayIcon: "ac_plug_colored", doneSetup: false }; @@ -140,7 +141,16 @@ export async function getLang(object: string) { } let rawdata = fs.readFileSync(langPath, "utf-8"); let parsed = JSON.parse(rawdata); - return parsed[object]; + if (parsed[object] == undefined) { + console.log(object + " is undefined in " + language) + langPath = path.join(__dirname, "../", "/assets/lang/en-US.json"); + rawdata = fs.readFileSync(langPath, "utf-8"); + parsed = JSON.parse(rawdata); + return parsed[object] + } else { + return parsed[object]; + } + } //ArmCord Window State manager @@ -178,6 +188,7 @@ export interface Settings { minimizeToTray: boolean; automaticPatches: boolean; mods: string; + mobileMode: boolean, performanceMode: string; inviteWebsocket: boolean; trayIcon: string; diff --git a/src/window.ts b/src/window.ts index 5a6fe4c..07a9e89 100644 --- a/src/window.ts +++ b/src/window.ts @@ -25,12 +25,16 @@ async function doAfterDefiningTheWindow() { var ignoreProtocolWarning = await getConfig("ignoreProtocolWarning"); checkIfConfigIsBroken(); registerIpc(); - - // A little sloppy but it works :p - if (osType == 'Windows_NT') { - osType = "Windows " + os.release().split('.')[0] + " (" + os.release() + ")"; + if (await getConfig("mobileMode")) { + mainWindow.webContents.userAgent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.149 Mobile Safari/537.36" + } else { + // A little sloppy but it works :p + if (osType == 'Windows_NT') { + osType = "Windows " + os.release().split('.')[0] + " (" + os.release() + ")"; + } + mainWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`; //fake useragent for screenshare to work } - mainWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`; //fake useragent for screenshare to work + mainWindow.webContents.setWindowOpenHandler(({ url }) => { if (url.startsWith("https:" || url.startsWith("http:") || url.startsWith("mailto:"))) { shell.openExternal(url);