8000 [pull] dev from Legcord:dev by pull[bot] · Pull Request #11 · imide/Legcord · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] dev from Legcord:dev #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"xml-formatter": "^3.6.6"
},
"dependencies": {
"arrpc": "https://github.com/Legcord/arrpc.git#4a026ad17f9507851d47248f967a3bb7f0ef0ede",
"arrpc": "https://github.com/Legcord/arrpc.git#9abda032465847724d29db9aeeacc0b375c55a86",
"electron-context-menu": "^4.0.4",
"electron-is-dev": "^3.0.1",
"electron-updater": "^6.6.2",
Expand Down
16 changes: 11 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ onlyBuiltDependencies:
- '@parcel/watcher'
- '@vencord/venmic'
- electron
- esbuild
- esbuild
13 changes: 13 additions & 0 deletions src/@types/legcordWindow.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ export interface LegcordWindow {
edit: (id: string) => void;
folder: (id: string) => void;
};
rpc: {
listen: (
callback: (msg: {
activity: {
assets: { large_image: string | null; small_image: string | null };
application_id: number;
name: string;
};
}) => void,
) => void;
getProcessList: () => void;
refreshProcessList: () => void;
};
}
7 changes: 7 additions & 0 deletions src/discord/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isPowerSavingEnabled, setPowerSaving } from "../power.js";
import constPaths from "../shared/consts/paths.js";
import { splashWindow } from "../splash/main.js";
import { refreshGlobalKeybinds } from "./globalKeybinds.js";
import { processList, refreshProcessList } from "./rpcProcess.js";
import { importGuilds, mainTouchBar, setVoiceState, voiceTouchBar } from "./touchbar.js";

const userDataPath = app.getPath("userData");
Expand Down Expand Up @@ -289,4 +290,10 @@ export function registerIpc(passedWindow: BrowserWindow): void {
ipcMain.on("getConstPaths", (event) => {
event.returnValue = constPaths;
});
ipcMain.on("getProcessList", (event) => {
event.returnValue = processList;
});
ipcMain.on("refreshProcessList", () => {
refreshProcessList();
});
}
14 changes: 8 additions & 6 deletions src/discord/preload/bridge.ts
8000
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { LegcordWindow } from "../../@types/legcordWindow.d.ts";
import type { Settings } from "../../@types/settings.js";
import type { ThemeManifest } from "../../@types/themeManifest.js";
import type { venmicListObject } from "../venmic.js";
let windowCallback: (arg0: object) => void;

interface IPCSources {
id: string;
Expand Down Expand Up @@ -88,14 +89,15 @@ contextBridge.exposeInMainWorld("legcord", {
folder: (id: string) => ipcRenderer.send("openThemeFolder", id),
openQuickCss: () => ipcRenderer.send("openQuickCss"),
},
rpc: {
listen: (callback: () => void) => {
windowCallback = callback;
},
refreshProcessList: () => ipcRenderer.send("refreshProcessList"),
getProcessList: () => ipcRenderer.sendSync("getProcessList"),
},
} as unknown as LegcordWindow);

let windowCallback: (arg0: object) => void;
contextBridge.exposeInMainWorld("LegcordRPC", {
listen: (callback: () => void) => {
windowCallback = callback;
},
});
ipcRenderer.on("rpc", (_event, data: object) => {
console.log(data);
windowCallback(data);
Expand Down
49 changes: 27 additions & 22 deletions src/discord/preload/newTitlebar.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ const { ipcRenderer } = require("electron");
import { addStyle } from "../../common/dom.js";
import { sleep } from "../../common/sleep.js";

document.addEventListener("DOMContentLoaded", () => {
document.body.setAttribute("legcord-platform", ipcRenderer.sendSync("getOS"));
addStyle("legcord://assets/css/baseTitlebar.css");
sleep(500);
switch (ipcRenderer.sendSync("getOS")) {
case "darwin":
// breaks traffic lights with bar__ and hidden__ classes
// document.body.setAttribute("class", "platform-osx");
addStyle("legcord://assets/css/darwinTitlebar.css");
break;
case "win32":
document.body.setAttribute("class", "platform-win");
addStyle("legcord://assets/css/winTitlebar.css");
break;
case "linux":
document.body.setAttribute("class", "platform-linux");
addStyle("legcord://assets/css/linuxTitlebar.css");
break;
default:
break;
}
});
if (
ipcRenderer.sendSync("getConfig", "windowStyle") === "default" ||
ipcRenderer.sendSync("getConfig", "windowStyle") === "overlay"
) {
document.addEventListener("DOMContentLoaded", () => {
document.body.setAttribute("legcord-platform", ipcRenderer.sendSync("getOS"));
addStyle("legcord://assets/css/baseTitlebar.css");
sleep(500);
switch (ipcRenderer.sendSync("getOS")) {
case "darwin":
// breaks traffic lights with bar__ and hidden__ classes
// document.body.setAttribute("class", "platform-osx");
addStyle("legcord://assets/css/darwinTitlebar.css");
break;
case "win32":
document.body.setAttribute("class", "platform-win");
addStyle("legcord://assets/css/winTitlebar.css");
break;
case "linux":
document.body.setAttribute("class", "platform-linux");
addStyle("legcord://assets/css/linuxTitlebar.css");
break;
default:
break;
}
});
}
11 changes: 0 additions & 11 deletions src/discord/preload/preload.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,5 @@ window.localStorage.setItem("hideNag", "true");
declare global {
interface Window {
legcord: LegcordWindow;
LegcordRPC: {
listen: (
callback: (msg: {
activity: {
assets: { large_image: string | null; small_image: string | null };
application_id: number;
name: string;
};
}) => void,
) => void;
};
}
}
42 changes: 42 additions & 0 deletions src/discord/rpcProcess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path from "node:path";
import { type BrowserWindow, utilityProcess } from "electron";
import { getDetectables } from "../common/detectables.js";
import { createInviteWindow } from "./window.js";

let child: Electron.UtilityProcess;
export let processList = [];

export function startRPC(window: BrowserWindow) {
child = utilityProcess.fork(path.join(import.meta.dirname, "rpc.js"), undefined, {
env: { detectables: JSON.stringify(getDetectables()) },
});

child.on("spawn", () => {
console.log("[arRPC] process started");
console.log(child.pid);
});

child.on("message", (message) => {
const json = JSON.parse(message);
if (json.type === "invite") {
createInviteWindow(json.code);
} else if (json.type === "activity") {
console.log("activity pulse");
console.log(json.data);
window.webContents.send("rpc", json.data);
} else if (json.type === "processList") {
console.log("[arRPC] updating process list");
console.log(json.data);
processList = json.data;
}
});

child.on("exit", () => {
console.log("[arRPC] process exited");
console.log(child.pid);
});
}

export function refreshProcessList() {
child.postMessage({ message: "refreshProcessList" });
}
28 changes: 2 additions & 26 deletions src/discord/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import {
dialog,
nativeImage,
shell,
utilityProcess,
} from "electron";
import contextMenu from "electron-context-menu";
import { firstRun, getConfig, setConfig } from "../common/config.js";
import { getDetectables } from "../common/detectables.js";
import { forceQuit, setForceQuit } from "../common/forceQuit.js";
import { initQuickCss, injectThemesMain } from "../common/themes.js";
import { getWindowState, setWindowState } from "../common/windowState.js";
import { init } from "../main.js";
import { registerGlobalKeybinds } from "./globalKeybinds.js";
import { registerIpc } from "./ipc.js";
import { setMenu } from "./menu.js";
import { startRPC } from "./rpcProcess.js";
import { registerCustomHandler } from "./screenshare.js";
import { mainTouchBar } from "./touchbar.js";
import { createTray, tray } from "./tray.js";
Expand Down Expand Up @@ -296,30 +295,7 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void {
void passedWindow.webContents.executeJavaScript(`document.body.removeAttribute("isMaximized");`);
});
if (getConfig("inviteWebsocket") && mainWindows.length === 1) {
const child = utilityProcess.fork(path.join(import.meta.dirname, "rpc.js"), undefined, {
env: { detectables: JSON.stringify(getDetectables()) },
});

child.on("spawn", () => {
console.log("arRPC process started");
console.log(child.pid);
});

child.on("message", (message) => {
const json = JSON.parse(message);
if (json.type === "invite") {
createInviteWindow(json.code);
} else if (json.type === "activity") {
console.log("activity pulse");
console.log(json.data);
passedWindow.webContents.send("rpc", json.data);
}
});

child.on("exit", () => {
console.log("arRPC process exited");
console.log(child.pid);
});
startRPC(passedWindow);
}
if (firstRun) {
passedWindow.close();
Expand Down
9 changes: 9 additions & 0 deletions src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ RPC.on("invite", (code: string) => {
const response = { type: "invite", code: code };
process.parentPort.postMessage(JSON.stringify(response));
});

process.parentPort.once("message", async (e) => {
if (e.data.message === "refreshProcessList") {
const processes = await RPC.getProcessesList();
console.log(processes);
const response = { type: "processList", data: processes };
process.parentPort.postMessage(JSON.stringify(response));
}
});
2 changes: 1 addition & 1 deletion src/shelter/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
} = shelter;

export function onLoad() {
window.LegcordRPC.listen(
window.legcord.rpc.listen(
async (msg: {
activity: {
assets: { large_image: string | null | undefined; small_image: string | null | undefined };
Expand Down
Loading
0