mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-10 07:03:06 -04:00
Progress
This commit is contained in:
parent
af498e7829
commit
876e622f4f
17 changed files with 289 additions and 34 deletions
|
@ -1,3 +1,5 @@
|
|||
import "./utils/patchWebpack";
|
||||
import "./utils/quickCss";
|
||||
|
||||
export const Webpack = {};
|
||||
export const Webpack = {};
|
||||
import "./plugins";
|
||||
|
|
11
src/VencordNative.ts
Normal file
11
src/VencordNative.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { IPC_QUICK_CSS_UPDATE, IPC_GET_QUICK_CSS } from './utils/ipcEvents';
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
export default {
|
||||
handleQuickCssUpdate(cb: (s: string) => void) {
|
||||
ipcRenderer.on(IPC_QUICK_CSS_UPDATE, (_, css) => {
|
||||
cb(css);
|
||||
});
|
||||
},
|
||||
getQuickCss: () => ipcRenderer.invoke(IPC_GET_QUICK_CSS)
|
||||
};
|
13
src/globals.d.ts
vendored
13
src/globals.d.ts
vendored
|
@ -1,9 +1,14 @@
|
|||
declare var appSettings: any;
|
||||
import TVencordNative from "./VencordNative";
|
||||
|
||||
declare global {
|
||||
export var VencordNative: typeof TVencordNative;
|
||||
export var appSettings: {
|
||||
set(setting: string, v: any): void;
|
||||
};
|
||||
|
||||
interface Window {
|
||||
webpackChunkdiscord_app: { push(chunk): any; };
|
||||
webpackChunkdiscord_app: {
|
||||
push(chunk: any): any;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { };
|
25
src/ipcMain.ts
Normal file
25
src/ipcMain.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { app, BrowserWindow, ipcMain } from "electron";
|
||||
import { fstat, watch } from "fs";
|
||||
import { open, readFile } from "fs/promises";
|
||||
import { join } from 'path';
|
||||
import { IPC_GET_SETTINGS_DIR, IPC_GET_QUICK_CSS, IPC_QUICK_CSS_UPDATE } from './utils/ipcEvents';
|
||||
|
||||
const DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
|
||||
const SETTINGS_DIR = join(DATA_DIR, "settings");
|
||||
const QUICKCSS_PATH = join(SETTINGS_DIR, "quickCss.css");
|
||||
|
||||
function readCss() {
|
||||
return readFile(QUICKCSS_PATH, "utf-8").catch(() => "");
|
||||
}
|
||||
|
||||
ipcMain.handle(IPC_GET_SETTINGS_DIR, () => SETTINGS_DIR);
|
||||
ipcMain.handle(IPC_GET_QUICK_CSS, () => readCss());
|
||||
|
||||
export function initIpc(mainWindow: BrowserWindow) {
|
||||
open(QUICKCSS_PATH, "a+").then(fd => {
|
||||
fd.close();
|
||||
watch(QUICKCSS_PATH, async () => {
|
||||
mainWindow.webContents.postMessage(IPC_QUICK_CSS_UPDATE, await readCss());
|
||||
});
|
||||
});
|
||||
}
|
|
@ -2,20 +2,21 @@
|
|||
import electron, { app, BrowserWindowConstructorOptions } from "electron";
|
||||
import installExt, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer";
|
||||
import { join } from "path";
|
||||
import { initIpc } from './ipcMain';
|
||||
|
||||
console.log("[Vencord] Starting up...");
|
||||
|
||||
class BrowserWindow extends electron.BrowserWindow {
|
||||
|
||||
constructor(options: BrowserWindowConstructorOptions) {
|
||||
if (options?.webPreferences?.preload && options.title) {
|
||||
const original = options.webPreferences.preload;
|
||||
options.webPreferences.preload = join(__dirname, "preload.js");
|
||||
|
||||
process.env.APP_PATH = app.getAppPath();
|
||||
process.env.DISCORD_PRELOAD = original;
|
||||
}
|
||||
super(options);
|
||||
|
||||
super(options);
|
||||
initIpc(this);
|
||||
} else super(options);
|
||||
}
|
||||
}
|
||||
Object.assign(BrowserWindow, electron.BrowserWindow);
|
||||
|
@ -28,10 +29,11 @@ require.cache[electronPath]!.exports = {
|
|||
BrowserWindow
|
||||
};
|
||||
|
||||
// Patch appSettingsa to force enable devtools
|
||||
// Patch appSettings to force enable devtools
|
||||
Object.defineProperty(global, "appSettings", {
|
||||
set: (v) => {
|
||||
set: (v: typeof global.appSettings) => {
|
||||
v.set("DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING", true);
|
||||
// @ts-ignore
|
||||
delete global.appSettings;
|
||||
global.appSettings = v;
|
||||
},
|
||||
|
@ -41,20 +43,17 @@ Object.defineProperty(global, "appSettings", {
|
|||
process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
|
||||
|
||||
electron.app.whenReady().then(() => {
|
||||
/* installExt(REACT_DEVELOPER_TOOLS)
|
||||
installExt(REACT_DEVELOPER_TOOLS)
|
||||
.then(() => console.log("Installed React DevTools"))
|
||||
.catch((err) => console.error("Failed to install React DevTools", err)); */
|
||||
.catch((err) => console.error("Failed to install React DevTools", err));
|
||||
|
||||
// Remove CSP
|
||||
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, cb) => {
|
||||
if (responseHeaders && url.endsWith(".css")) {
|
||||
if (responseHeaders) {
|
||||
delete responseHeaders["content-security-policy-report-only"];
|
||||
delete responseHeaders["content-security-policy"];
|
||||
// probably makes github raw work? not tested.
|
||||
responseHeaders["content-type"] = ["text/css"];
|
||||
responseHeaders;
|
||||
}
|
||||
cb({ cancel: false, responseHeaders: responseHeaders });
|
||||
cb({ cancel: false, responseHeaders });
|
||||
});
|
||||
|
||||
// Drop science and sentry requests
|
||||
|
|
4
src/plugins.d.ts
vendored
Normal file
4
src/plugins.d.ts
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
declare module "plugins" {
|
||||
var plugins: Record<string, any>[];
|
||||
export default plugins;
|
||||
}
|
3
src/plugins/bar.ts
Normal file
3
src/plugins/bar.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
name: "bar"
|
||||
};
|
3
src/plugins/foo.ts
Normal file
3
src/plugins/foo.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
name: "foo"
|
||||
};
|
3
src/plugins/index.ts
Normal file
3
src/plugins/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import plugins from "plugins";
|
||||
|
||||
console.log(plugins);
|
|
@ -1,14 +1,10 @@
|
|||
import { contextBridge, webFrame } from "electron";
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import Vencord from "./Vencord";
|
||||
import VencordNative from "./VencordNative";
|
||||
|
||||
contextBridge.exposeInMainWorld("VencordNative", {
|
||||
getSettings: () => "hi"
|
||||
});
|
||||
contextBridge.exposeInMainWorld("VencordNative", VencordNative);
|
||||
|
||||
webFrame.executeJavaScript(readFileSync(join(__dirname, "renderer.js"), "utf-8"));
|
||||
|
||||
require(process.env.DISCORD_PRELOAD!);
|
||||
|
||||
window.onload = () => console.log("hi");
|
|
@ -1,4 +1 @@
|
|||
import { join } from 'path';
|
||||
|
||||
export const WEBPACK_CHUNK = "webpackChunkdiscord_app";
|
||||
// export const SETTINGS_DIR = join(process.env.DATA_DIR!, "settings");
|
||||
|
|
3
src/utils/ipcEvents.ts
Normal file
3
src/utils/ipcEvents.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const IPC_QUICK_CSS_UPDATE = "VencordQuickCssUpdate";
|
||||
export const IPC_GET_QUICK_CSS = "VencordGetQuickCss";
|
||||
export const IPC_GET_SETTINGS_DIR = "VencordGetSettingsDir";
|
6
src/utils/quickCss.ts
Normal file
6
src/utils/quickCss.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const style = document.createElement("style");
|
||||
document.head.appendChild(style);
|
||||
VencordNative.handleQuickCssUpdate((css: string) => style.innerText = css);
|
||||
style.innerText = await VencordNative.getQuickCss();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue