Styles: Migrate core CSS injection

This commit is contained in:
Sqaaakoi 2025-01-20 07:33:22 +13:00
parent 494681477f
commit bf684366e7
No known key found for this signature in database
5 changed files with 17 additions and 17 deletions

View file

@ -187,11 +187,9 @@ async function buildExtension(target, files) {
const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content => { const appendCssRuntime = readFile("dist/Vencord.user.css", "utf-8").then(content => {
const cssRuntime = ` const cssRuntime = `
;document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild( ;document.addEventListener("DOMContentLoaded", () => Vencord.Api.Styles.createStyle(
Object.assign(document.createElement("style"), { "vencord-css-core",
textContent: \`${content.replaceAll("`", "\\`")}\`, \`${content.replaceAll("`", "\\`")}\`
id: "vencord-css-core"
})
), { once: true }); ), { once: true });
`; `;

View file

@ -28,6 +28,7 @@ export { PlainSettings, Settings };
import "./utils/quickCss"; import "./utils/quickCss";
import "./webpack/patchWebpack"; import "./webpack/patchWebpack";
import { createStyle } from "@api/Styles";
import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab"; import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab";
import { StartAt } from "@utils/types"; import { StartAt } from "@utils/types";
@ -142,9 +143,6 @@ document.addEventListener("DOMContentLoaded", () => {
startAllPlugins(StartAt.DOMContentLoaded); startAllPlugins(StartAt.DOMContentLoaded);
if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) {
document.head.append(Object.assign(document.createElement("style"), { createStyle("vencord-native-titlebar-style", "[class*=titleBar]{display: none!important}");
id: "vencord-native-titlebar-style",
textContent: "[class*=titleBar]{display: none!important}"
}));
} }
}, { once: true }); }, { once: true });

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { createStyle } from "@api/Styles";
import { debounce } from "@shared/debounce"; import { debounce } from "@shared/debounce";
import { contextBridge, webFrame } from "electron"; import { contextBridge, webFrame } from "electron";
import { readFileSync, watch } from "fs"; import { readFileSync, watch } from "fs";
@ -30,14 +31,12 @@ if (location.protocol !== "data:") {
// #region cssInsert // #region cssInsert
const rendererCss = join(__dirname, IS_VESKTOP ? "vencordDesktopRenderer.css" : "renderer.css"); const rendererCss = join(__dirname, IS_VESKTOP ? "vencordDesktopRenderer.css" : "renderer.css");
const style = document.createElement("style"); const injectStyle = () => createStyle("vencord-css-core", readFileSync(rendererCss, "utf-8"));
style.id = "vencord-css-core";
style.textContent = readFileSync(rendererCss, "utf-8");
if (document.readyState === "complete") { if (document.readyState === "complete") {
document.documentElement.appendChild(style); injectStyle();
} else { } else {
document.addEventListener("DOMContentLoaded", () => document.documentElement.appendChild(style), { document.addEventListener("DOMContentLoaded", injectStyle, {
once: true once: true
}); });
} }
@ -45,9 +44,7 @@ if (location.protocol !== "data:") {
if (IS_DEV) { if (IS_DEV) {
// persistent means keep process running if watcher is the only thing still running // persistent means keep process running if watcher is the only thing still running
// which we obviously don't want // which we obviously don't want
watch(rendererCss, { persistent: false }, () => { watch(rendererCss, { persistent: false }, injectStyle);
document.getElementById("vencord-css-core")!.textContent = readFileSync(rendererCss, "utf-8");
});
} }
// #endregion // #endregion

View file

@ -56,6 +56,7 @@ export let EmojiStore: t.EmojiStore;
export let ThemeStore: t.ThemeStore; export let ThemeStore: t.ThemeStore;
export let WindowStore: t.WindowStore; export let WindowStore: t.WindowStore;
export let DraftStore: t.DraftStore; export let DraftStore: t.DraftStore;
export let PopoutWindowStore: t.PopoutWindowStore;
/** /**
* React hook that returns stateful data for one or more stores * React hook that returns stateful data for one or more stores
@ -86,3 +87,4 @@ waitForStore("MessageStore", m => MessageStore = m);
waitForStore("WindowStore", m => WindowStore = m); waitForStore("WindowStore", m => WindowStore = m);
waitForStore("EmojiStore", m => EmojiStore = m); waitForStore("EmojiStore", m => EmojiStore = m);
waitForStore("ThemeStore", m => ThemeStore = m); waitForStore("ThemeStore", m => ThemeStore = m);
waitForStore("PopoutWindowStore", m => PopoutWindowStore = m);

View file

@ -228,6 +228,11 @@ export class ThemeStore extends FluxStore {
systemTheme: null; systemTheme: null;
} }
export class PopoutWindowStore extends FluxStore {
getWindow(windowKey: string): Window;
getWindowKeys(): string[];
}
export type useStateFromStores = <T>( export type useStateFromStores = <T>(
stores: t.FluxStore[], stores: t.FluxStore[],
mapper: () => T, mapper: () => T,