2022-10-22 02:17:06 +03: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-02 03:50:51 +03:00
|
|
|
/// <reference path="../src/modules.d.ts" />
|
|
|
|
/// <reference path="../src/globals.d.ts" />
|
|
|
|
|
2023-09-19 05:07:24 +03:00
|
|
|
import monacoHtmlLocal from "~fileContent/monacoWin.html";
|
|
|
|
import monacoHtmlCdn from "~fileContent/../src/main/monacoWin.html";
|
2022-10-22 00:58:41 +03:00
|
|
|
import * as DataStore from "../src/api/DataStore";
|
2023-05-02 03:50:51 +03:00
|
|
|
import { debounce } from "../src/utils";
|
2023-09-19 05:07:24 +03:00
|
|
|
import { EXTENSION_BASE_URL } from "../src/utils/web-metadata";
|
2023-05-02 03:50:51 +03:00
|
|
|
import { getTheme, Theme } from "../src/utils/discord";
|
2023-08-04 20:52:20 +03:00
|
|
|
import { getThemeInfo } from "../src/main/themes";
|
2022-10-04 01:52:42 +03:00
|
|
|
|
|
|
|
// Discord deletes this so need to store in variable
|
2022-10-22 00:58:41 +03:00
|
|
|
const { localStorage } = window;
|
|
|
|
|
|
|
|
// listeners for ipc.on
|
2023-05-02 03:50:51 +03:00
|
|
|
const cssListeners = new Set<(css: string) => void>();
|
|
|
|
const NOOP = () => { };
|
|
|
|
const NOOP_ASYNC = async () => { };
|
2022-10-04 01:52:42 +03:00
|
|
|
|
2023-05-02 03:50:51 +03:00
|
|
|
const setCssDebounced = debounce((css: string) => VencordNative.quickCss.set(css));
|
2022-10-04 01:52:42 +03:00
|
|
|
|
2023-08-04 20:52:20 +03:00
|
|
|
const themeStore = DataStore.createStore("VencordThemes", "VencordThemeData");
|
|
|
|
|
2023-05-02 03:50:51 +03:00
|
|
|
// probably should make this less cursed at some point
|
|
|
|
window.VencordNative = {
|
2023-08-04 20:52:20 +03: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()))
|
|
|
|
),
|
2023-09-25 19:53:10 +03:00
|
|
|
getThemeData: (fileName: string) => DataStore.get(fileName, themeStore),
|
|
|
|
getSystemValues: async () => ({}),
|
2023-08-04 20:52:20 +03:00
|
|
|
},
|
|
|
|
|
2023-05-02 03:50:51 +03:00
|
|
|
native: {
|
|
|
|
getVersions: () => ({}),
|
|
|
|
openExternal: async (url) => void open(url, "_blank")
|
2022-10-22 00:58:41 +03:00
|
|
|
},
|
|
|
|
|
2023-05-02 03:50:51 +03: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-04 01:52:42 +03:00
|
|
|
|
2023-05-02 03:50:51 +03: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 20:52:20 +03:00
|
|
|
addThemeChangeListener: NOOP,
|
2023-05-02 03:50:51 +03: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-04 01:52:42 +03:00
|
|
|
|
2023-09-19 05:07:24 +03:00
|
|
|
win.baseUrl = EXTENSION_BASE_URL;
|
2023-05-02 03:50:51 +03:00
|
|
|
win.setCss = setCssDebounced;
|
|
|
|
win.getCurrentCss = () => VencordNative.quickCss.get();
|
|
|
|
win.getTheme = () =>
|
|
|
|
getTheme() === Theme.Light
|
|
|
|
? "vs-light"
|
|
|
|
: "vs-dark";
|
2022-10-04 01:52:42 +03:00
|
|
|
|
2023-09-19 05:07:24 +03:00
|
|
|
win.document.write(IS_EXTENSION ? monacoHtmlLocal : monacoHtmlCdn);
|
2022-10-04 01:52:42 +03:00
|
|
|
},
|
|
|
|
},
|
2023-05-02 03:50:51 +03:00
|
|
|
|
|
|
|
settings: {
|
|
|
|
get: () => localStorage.getItem("VencordSettings") || "{}",
|
|
|
|
set: async (s: string) => localStorage.setItem("VencordSettings", s),
|
|
|
|
getSettingsDir: async () => "LocalStorage"
|
2023-08-04 20:52:20 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
pluginHelpers: {} as any,
|
2022-10-04 01:52:42 +03:00
|
|
|
};
|