2022-10-21 19:17:06 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
/// <reference path="../src/modules.d.ts" />
|
|
|
|
/// <reference path="../src/globals.d.ts" />
|
|
|
|
|
2023-09-18 22:07:24 -04:00
|
|
|
import monacoHtmlLocal from "~fileContent/monacoWin.html";
|
|
|
|
import monacoHtmlCdn from "~fileContent/../src/main/monacoWin.html";
|
2022-10-21 17:58:41 -04:00
|
|
|
import * as DataStore from "../src/api/DataStore";
|
2023-05-01 20:50:51 -04:00
|
|
|
import { debounce } from "../src/utils";
|
2023-09-18 22:07:24 -04:00
|
|
|
import { EXTENSION_BASE_URL } from "../src/utils/web-metadata";
|
2023-05-01 20:50:51 -04:00
|
|
|
import { getTheme, Theme } from "../src/utils/discord";
|
2023-08-04 13:52:20 -04:00
|
|
|
import { getThemeInfo } from "../src/main/themes";
|
2022-10-03 18:52:42 -04:00
|
|
|
|
|
|
|
// Discord deletes this so need to store in variable
|
2022-10-21 17:58:41 -04:00
|
|
|
const { localStorage } = window;
|
|
|
|
|
|
|
|
// listeners for ipc.on
|
2023-05-01 20:50:51 -04:00
|
|
|
const cssListeners = new Set<(css: string) => void>();
|
|
|
|
const NOOP = () => { };
|
|
|
|
const NOOP_ASYNC = async () => { };
|
2022-10-03 18:52:42 -04:00
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
const setCssDebounced = debounce((css: string) => VencordNative.quickCss.set(css));
|
2022-10-03 18:52:42 -04:00
|
|
|
|
2023-08-04 13:52:20 -04:00
|
|
|
const themeStore = DataStore.createStore("VencordThemes", "VencordThemeData");
|
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
// probably should make this less cursed at some point
|
|
|
|
window.VencordNative = {
|
2023-08-04 13:52:20 -04:00
|
|
|
themes: {
|
|
|
|
uploadTheme: (fileName: string, fileData: string) => DataStore.set(fileName, fileData, themeStore),
|
|
|
|
deleteTheme: (fileName: string) => DataStore.del(fileName, themeStore),
|
|
|
|
getThemesDir: async () => "",
|
|
|
|
getThemesList: () => DataStore.entries(themeStore).then(entries =>
|
|
|
|
entries.map(([name, css]) => getThemeInfo(css, name.toString()))
|
|
|
|
),
|
|
|
|
getThemeData: (fileName: string) => DataStore.get(fileName, themeStore)
|
|
|
|
},
|
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
native: {
|
|
|
|
getVersions: () => ({}),
|
|
|
|
openExternal: async (url) => void open(url, "_blank")
|
2022-10-21 17:58:41 -04:00
|
|
|
},
|
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
updater: {
|
|
|
|
getRepo: async () => ({ ok: true, value: "https://github.com/Vendicated/Vencord" }),
|
|
|
|
getUpdates: async () => ({ ok: true, value: [] }),
|
|
|
|
update: async () => ({ ok: true, value: false }),
|
|
|
|
rebuild: async () => ({ ok: true, value: true }),
|
|
|
|
},
|
2022-10-03 18:52:42 -04:00
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
quickCss: {
|
|
|
|
get: () => DataStore.get("VencordQuickCss").then(s => s ?? ""),
|
|
|
|
set: async (css: string) => {
|
|
|
|
await DataStore.set("VencordQuickCss", css);
|
|
|
|
cssListeners.forEach(l => l(css));
|
|
|
|
},
|
|
|
|
addChangeListener(cb) {
|
|
|
|
cssListeners.add(cb);
|
|
|
|
},
|
2023-08-04 13:52:20 -04:00
|
|
|
addThemeChangeListener: NOOP,
|
2023-05-01 20:50:51 -04:00
|
|
|
openFile: NOOP_ASYNC,
|
|
|
|
async openEditor() {
|
|
|
|
const features = `popup,width=${Math.min(window.innerWidth, 1000)},height=${Math.min(window.innerHeight, 1000)}`;
|
|
|
|
const win = open("about:blank", "VencordQuickCss", features);
|
|
|
|
if (!win) {
|
|
|
|
alert("Failed to open QuickCSS popup. Make sure to allow popups!");
|
|
|
|
return;
|
|
|
|
}
|
2022-10-03 18:52:42 -04:00
|
|
|
|
2023-09-18 22:07:24 -04:00
|
|
|
win.baseUrl = EXTENSION_BASE_URL;
|
2023-05-01 20:50:51 -04:00
|
|
|
win.setCss = setCssDebounced;
|
|
|
|
win.getCurrentCss = () => VencordNative.quickCss.get();
|
|
|
|
win.getTheme = () =>
|
|
|
|
getTheme() === Theme.Light
|
|
|
|
? "vs-light"
|
|
|
|
: "vs-dark";
|
2022-10-03 18:52:42 -04:00
|
|
|
|
2023-09-18 22:07:24 -04:00
|
|
|
win.document.write(IS_EXTENSION ? monacoHtmlLocal : monacoHtmlCdn);
|
2022-10-03 18:52:42 -04:00
|
|
|
},
|
|
|
|
},
|
2023-05-01 20:50:51 -04:00
|
|
|
|
|
|
|
settings: {
|
|
|
|
get: () => localStorage.getItem("VencordSettings") || "{}",
|
|
|
|
set: async (s: string) => localStorage.setItem("VencordSettings", s),
|
|
|
|
getSettingsDir: async () => "LocalStorage"
|
2023-08-04 13:52:20 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
pluginHelpers: {} as any,
|
2022-10-03 18:52:42 -04:00
|
|
|
};
|