diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 016a061..32cc83d 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -3,151 +3,83 @@ on: push: branches: - dev - -env: - FORCE_COLOR: true - jobs: - build-linux: - runs-on: ubuntu-latest + build: + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + arch: [arm64, amd64] + include: + - arch: arm64 + os: windows-latest + flags: "--arm64 --windows" + target: "arm64-win" + + - arch: amd64 + os: windows-latest + flags: "--x64 --windows" + target: "amd64-win" + + - arch: arm64 + os: ubuntu-latest + flags: "--arm64 --linux" + target: "arm64-linux" + + - arch: amd64 + os: ubuntu-latest + flags: "--x64 --linux" + target: "amd64-linux" + + - arch: arm64 + os: macos-latest + flags: "--arm64 --macos" + target: "arm64-mac" + + - arch: amd64 + os: macos-latest + flags: "--x64 --macos" + target: "amd64-mac" + + runs-on: ${{matrix.os}} steps: - name: Checkout code uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 + - name: Prepeare PNPM + uses: pnpm/action-setup@v4 - - name: Use Node.js 22 + - name: Prepare Node.js uses: actions/setup-node@v4 with: node-version: 22 - cache: "pnpm" + cache: pnpm - - name: Install Node dependencies + - name: Install dependencies run: pnpm i - - name: Build - run: pnpm run build && pnpm electron-builder --linux zip + - name: Build TypeScript + run: pnpm build - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ArmCordLinux - path: dist/armcord-*.zip - build-snap: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: pnpm/action-setup@v4 - - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "pnpm" - - - name: Install Node dependencies - run: pnpm i - - - name: Build - run: pnpm run build && pnpm electron-builder --linux snap --config.snap.grade=devel - - - uses: snapcore/action-publish@v1 + - name: Build Electron + run: pnpm electron-builder ${{matrix.flags}} zip env: - SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_STORE_LOGIN }} - with: - snap: dist/armcord_3.3.0_amd64.snap - release: edge - build-linux-arm: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: pnpm/action-setup@v4 - - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "pnpm" - - - name: Install Node dependencies - run: pnpm i - - - name: Build - run: pnpm run build && pnpm electron-builder --arm64 --linux zip + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} # MacOS needs the token or it will fail to build - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: ArmCordLinuxArm64 - path: dist/armcord-*-arm64.zip - - build-windows: - runs-on: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: pnpm/action-setup@v4 - - - name: Use Node.js 22 - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "pnpm" - - - name: Install Node dependencies - run: pnpm i - - - name: Build - run: pnpm run build && pnpm electron-builder --windows zip - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ArmCordWindows - path: dist/armcord-3.3.0-win.zip - - build-windows-arm: - runs-on: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: "22" - - - name: Set architecture - run: set npm_config_arch=arm64 - - - uses: pnpm/action-setup@v4 # Install pnpm using packageManager key in package.json - - - name: Install Node dependencies - run: pnpm i - - - name: Build - run: pnpm run build && pnpm electron-builder --windows zip --arm64 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ArmCordWindowsArm64 - path: dist\armcord-3.3.0-arm64-win.zip + name: ${{matrix.target}} + path: dist/ release: runs-on: ubuntu-latest - needs: [build-linux, build-windows, build-windows-arm, build-linux-arm] + needs: build steps: - name: Checkout code uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v4 with: path: release-files @@ -155,18 +87,19 @@ jobs: id: vars run: echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT - - run: gh release delete devbuild -y --cleanup-tag + - name: Delete old devbuild + run: gh release delete devbuild -y --cleanup-tag env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} - - name: Create Release + - name: Create release uses: ncipollo/release-action@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: bodyFile: .github/release.md - generateReleaseNotes: false - name: Dev Build ${{ steps.vars.outputs.sha_short }} + name: Dev Build ${{steps.vars.outputs.sha_short}} prerelease: true + draft: false tag: devbuild - artifacts: "release-files/**/*.zip" + artifacts: release-files/**/*.zip diff --git a/assets/lang/en-US.json b/assets/lang/en-US.json index eea1056..3b8d182 100644 --- a/assets/lang/en-US.json +++ b/assets/lang/en-US.json @@ -20,7 +20,7 @@ "settings-theme-native": "Native", "settings-theme-transparent": "Transparent", "settings-csp-desc": "ArmCord CSP is our system that manages loading custom content loading into the Discord app. Stuff like\n client mods and themes depend on it. Disable if you want to get rid of mods and custom styles.", - "settings-mintoTray": "Minimize to tray", + "settings-mintoTray": "Work in background", "settings-mintoTray-desc": "When disabled, ArmCord will close like any other window when closed, otherwise it'll sit back and relax\n in your system tray for later.", "settings-startMinimized": "Start minimized", "settings-startMinimized-desc": "ArmCord starts in background and remains out of your way.", diff --git a/package.json b/package.json index df4a7f2..1584342 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "watch": "tsc -w", "start": "pnpm run build && electron --trace-warnings ./ts-out/main.js", "startThemeManager": "pnpm run build && electron ./ts-out/main.js themes", - "startKeybindManager": "pnpm run build && electron ./ts-out/main.js keybinds", "startWayland": "pnpm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations --disable-gpu", "package": "pnpm run build && electron-builder", "packageQuick": "pnpm run build && electron-builder --dir", @@ -50,6 +49,7 @@ "arrpc": "github:OpenAsar/arrpc#c62ec6a04c8d870530aa6944257fe745f6c59a24", "cross-fetch": "^4.0.0", "electron-context-menu": "^4.0.0", + "electron-is-dev": "^3.0.1", "extract-zip": "^2.0.1", "v8-compile-cache": "^2.4.0", "ws": "^8.17.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0f696da..23cbe5f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: electron-context-menu: specifier: ^4.0.0 version: 4.0.0 + electron-is-dev: + specifier: ^3.0.1 + version: 3.0.1 extract-zip: specifier: ^2.0.1 version: 2.0.1 diff --git a/src/common/config.ts b/src/common/config.ts index 65b638d..75758e8 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -1,5 +1,6 @@ import {app, dialog} from "electron"; import path from "path"; +import isDev from "electron-is-dev"; import fs from "fs"; import type {Settings} from "../types/settings.d.js"; import {getWindowStateLocation} from "./windowState.js"; @@ -10,7 +11,7 @@ export function checkForDataFolder(): void { console.log("Found armcord-data folder. Running in portable mode."); app.setPath("userData", dataPath); } - if (path.join(app.getPath("appData"), "ArmCord")) { + if (path.join(app.getPath("appData"), "ArmCord") && !isDev) { console.log("Found existing ArmCord folder."); app.setPath("userData", path.join(app.getPath("appData"), "ArmCord")); } diff --git a/src/common/forceQuit.ts b/src/common/forceQuit.ts new file mode 100644 index 0000000..b5e4021 --- /dev/null +++ b/src/common/forceQuit.ts @@ -0,0 +1,5 @@ +export let forceQuit = false; + +export function setForceQuit(e: boolean): void { + forceQuit = e; +} diff --git a/src/common/version.ts b/src/common/version.ts index 57055dd..d4e8954 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1,13 +1,14 @@ import {app} from "electron"; +import isDev from "electron-is-dev"; export function getVersion(): string { - if ((app.getVersion() == process.versions.electron) == true) { - return "3.3.0"; + if (isDev) { + return "0.0.0"; } return app.getVersion(); } export function getDisplayVersion(): string { - if ((app.getVersion() == process.versions.electron) == true) { + if (isDev) { return "Dev Build"; } return app.getVersion(); diff --git a/src/discord/menu.ts b/src/discord/menu.ts index 40c2054..41d16a1 100644 --- a/src/discord/menu.ts +++ b/src/discord/menu.ts @@ -1,6 +1,7 @@ import {BrowserWindow, Menu, app} from "electron"; import {mainWindows} from "./window.js"; import {createSettingsWindow} from "../settings/main.js"; +import {setForceQuit} from "../common/forceQuit.js"; export function setMenu(): void { const template: Electron.MenuItemConstructorOptions[] = [ @@ -48,6 +49,7 @@ export function setMenu(): void { label: "Quit", accelerator: "CmdOrCtrl+Q", click() { + setForceQuit(true); app.quit(); } } diff --git a/src/discord/window.ts b/src/discord/window.ts index 7b1ad2c..2bbfe4d 100644 --- a/src/discord/window.ts +++ b/src/discord/window.ts @@ -12,14 +12,14 @@ import * as fs from "fs"; import contextMenu from "electron-context-menu"; import os from "os"; import RPCServer from "arrpc"; -import {isQuitting, tray} from "../tray.js"; +import {tray} from "../tray.js"; import {iconPath, init} from "../main.js"; import {getConfig, setConfig, firstRun} from "../common/config.js"; import {getWindowState, setWindowState} from "../common/windowState.js"; +import {forceQuit, setForceQuit} from "../common/forceQuit.js"; export let mainWindows: BrowserWindow[] = []; export let inviteWindow: BrowserWindow; -export let forceQuit = false; -let osType = os.type(); + contextMenu({ showSaveImageAs: true, showCopyImageAddress: true, @@ -65,11 +65,11 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void { passedWindow.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()})`; - } - passedWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36`; //fake useragent for screenshare to work + let osType = process.platform === "darwin" ? "Macintosh" : process.platform === "win32" ? "Windows" : "Linux"; + if (osType === "Linux") osType = "X11; " + osType; + const chromeVersion = process.versions.chrome; + const userAgent = `Mozilla/5.0 (${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`; + passedWindow.webContents.userAgent = userAgent; } if (mainWindows.length === 1) { app.on("second-instance", (_event, _commandLine, _workingDirectory, additionalData) => { @@ -96,6 +96,10 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void { passedWindow.webContents.setWindowOpenHandler(({url}) => { // Allow about:blank (used by Vencord QuickCss popup) if (url === "about:blank") return {action: "allow"}; + // Saving ics files on future events + if (url.startsWith("blob:https://discord.com/")) { + return {action: "allow", overrideBrowserWindowOptions: {show: false}}; + } // Allow Discord stream popout if ( url === "https://discord.com/popout" || @@ -138,6 +142,7 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void { } }); } + return {action: "deny"}; }); if (getConfig("useLegacyCapturer") == false) { @@ -238,39 +243,28 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void { }); setMenu(); passedWindow.on("close", (e) => { - if (process.platform === "darwin" && forceQuit) { - passedWindow.close(); - } else if (mainWindows.length > 1) { + if (mainWindows.length > 1) { mainWindows = mainWindows.filter((mainWindow) => mainWindow.id != passedWindow.id); passedWindow.destroy(); - } else { - const [width, height] = passedWindow.getSize(); - setWindowState({ - width, - height, - isMaximized: passedWindow.isMaximized(), - x: passedWindow.getPosition()[0], - y: passedWindow.getPosition()[1] - }); - if (getConfig("minimizeToTray") && !isQuitting) { - e.preventDefault(); - passedWindow.hide(); - } else if (!getConfig("minimizeToTray")) { - e.preventDefault(); - app.quit(); - } + } + if (getConfig("minimizeToTray") && !forceQuit) { + e.preventDefault(); + passedWindow.hide(); + } else if (!getConfig("minimizeToTray")) { + app.quit(); } }); - if (process.platform === "darwin") { - app.on("before-quit", function (event) { - if (!forceQuit) { - event.preventDefault(); - forceQuit = true; - app.quit(); - } + app.on("before-quit", () => { + const [width, height] = passedWindow.getSize(); + setWindowState({ + width, + height, + isMaximized: passedWindow.isMaximized(), + x: passedWindow.getPosition()[0], + y: passedWindow.getPosition()[1] }); - } - + setForceQuit(true); + }); // REVIEW - Awaiting javascript execution is silly passedWindow.on("focus", () => { void passedWindow.webContents.executeJavaScript(`document.body.removeAttribute("unFocused");`); diff --git a/src/main.ts b/src/main.ts index 8f163f6..55ef99b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,7 +31,7 @@ app.on("render-process-gone", (_event, _webContents, details) => { app.relaunch(); } }); -async function args(): Promise { +function args(): void { let argNum = 2; if (process.argv[0] == "electron") argNum++; const args = process.argv[argNum]; @@ -44,7 +44,7 @@ async function args(): Promise { app.relaunch(); app.exit(); } else if (args == "themes") { - await app.whenReady().then(async () => { + void app.whenReady().then(async () => { await createTManagerWindow(); }); } @@ -74,7 +74,7 @@ export async function init(): Promise { break; } } -await args(); // i want my top level awaits - IMPLEMENTED :) +args(); if (!app.requestSingleInstanceLock()) { // if value isn't set after 3.2.4 // kill if 2nd instance @@ -117,31 +117,7 @@ if (!app.requestSingleInstanceLock()) { } else { iconPath = path.join(import.meta.dirname, "../", "/assets/desktop.png"); } - async function init(): Promise { - if (getConfig("skipSplash") == false) { - void createSplashWindow(); // REVIEW - Awaiting will hang at start - } - if (firstRun == true) { - setLang(new Intl.DateTimeFormat().resolvedOptions().locale); - await createSetupWindow(); - } - switch (getConfig("windowStyle")) { - case "default": - createCustomWindow(); - customTitlebar = true; - break; - case "native": - createNativeWindow(); - break; - case "transparent": - createTransparentWindow(); - break; - default: - createCustomWindow(); - customTitlebar = true; - break; - } - } + // Patch for linux bug to insure things are loaded before window creation (fixes transparency on some linux systems) await new Promise((resolve) => setTimeout(() => (init(), resolve()), 1500)); await installModLoader(); diff --git a/src/splash/main.ts b/src/splash/main.ts index 0e47edc..e36a7f5 100644 --- a/src/splash/main.ts +++ b/src/splash/main.ts @@ -1,6 +1,7 @@ -import {BrowserWindow} from "electron"; +import {BrowserWindow, ipcMain} from "electron"; import {iconPath} from "../main.js"; import path from "path"; +import isDev from "electron-is-dev"; export let splashWindow: BrowserWindow; export async function createSplashWindow(): Promise { @@ -19,5 +20,8 @@ export async function createSplashWindow(): Promise { preload: path.join(import.meta.dirname, "preload.mjs") } }); + ipcMain.on("isDev", (event) => { + event.returnValue = isDev; + }); await splashWindow.loadFile(path.join(import.meta.dirname, "splash.html")); } diff --git a/src/splash/preload.mts b/src/splash/preload.mts index 2f584e1..c7695d6 100644 --- a/src/splash/preload.mts +++ b/src/splash/preload.mts @@ -4,6 +4,7 @@ contextBridge.exposeInMainWorld("internal", { restart: () => ipcRenderer.send("restart"), installState: ipcRenderer.sendSync("modInstallState") as string, version: ipcRenderer.sendSync("get-app-version", "app-version") as string, + isDev: ipcRenderer.sendSync("isDev") as string, getLang: (toGet: string) => ipcRenderer.invoke("getLang", toGet).then((result: string) => { return result; diff --git a/src/splash/splash.html b/src/splash/splash.html index e50adf4..bd0d817 100644 --- a/src/splash/splash.html +++ b/src/splash/splash.html @@ -35,7 +35,7 @@ window.internal.restart(); } else { text.innerHTML = await internal.getLang("loading_screen_start"); - if (window.internal.version === "3.3.0") { + if (internal.isDev) { console.log("Running a development build of ArmCord. Skipping updater."); } else { const response = await fetch("https://armcord.app/latest.json"); diff --git a/src/tray.ts b/src/tray.ts index e5816be..34522d7 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -5,8 +5,9 @@ import path from "path"; import {createSettingsWindow} from "./settings/main.js"; import {getConfig, getConfigLocation, setConfig} from "./common/config.js"; import {getDisplayVersion} from "./common/version.js"; +import {setForceQuit} from "./common/forceQuit.js"; export let tray: Tray; -export let isQuitting = false; + let trayIcon = "ac_plug_colored"; void app.whenReady().then(async () => { // REVIEW - app will hang at startup if line above is awaited. @@ -86,8 +87,7 @@ void app.whenReady().then(async () => { { label: `Quit ${clientName}`, click() { - //NOTE - It would be better to unify isQuitting with forceQuit in window.ts that's used on macOS - isQuitting = true; + setForceQuit(true); app.quit(); } }