2024-02-28 14:09:42 +08:00
|
|
|
import { Theme } from "../../managers/themes";
|
2024-02-23 00:33:40 +08:00
|
|
|
|
|
|
|
|
// @ts-ignore
|
2024-02-23 13:29:06 +08:00
|
|
|
const pyonLoaderIdentity = globalThis.__PYON_LOADER__;
|
2024-02-23 00:33:40 +08:00
|
|
|
// @ts-ignore
|
2024-02-23 13:29:06 +08:00
|
|
|
const vendettaLoaderIdentity = globalThis.__vendetta_loader;
|
2024-02-23 00:33:40 +08:00
|
|
|
|
2024-02-23 15:11:35 +08:00
|
|
|
export interface VendettaLoaderIdentity {
|
|
|
|
|
name: string;
|
|
|
|
|
features: {
|
|
|
|
|
loaderConfig?: boolean;
|
|
|
|
|
devtools?: {
|
|
|
|
|
prop: string;
|
|
|
|
|
version: string;
|
|
|
|
|
},
|
|
|
|
|
themes?: {
|
|
|
|
|
prop: string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 00:33:40 +08:00
|
|
|
export function isVendettaLoader() {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity != null;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isPyonLoader() {
|
2024-02-23 13:29:06 +08:00
|
|
|
return pyonLoaderIdentity != null;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-02-23 13:29:06 +08:00
|
|
|
function polyfillVendettaLoaderIdentity() {
|
2024-02-23 00:33:40 +08:00
|
|
|
if (!isPyonLoader() || isVendettaLoader()) return null;
|
|
|
|
|
|
|
|
|
|
const loader = {
|
2024-02-23 13:29:06 +08:00
|
|
|
name: pyonLoaderIdentity.loaderName,
|
2024-02-23 00:33:40 +08:00
|
|
|
features: {} as Record<string, any>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isLoaderConfigSupported()) loader.features.loaderConfig = true;
|
|
|
|
|
if (isSysColorsSupported()) {
|
|
|
|
|
loader.features.syscolors = {
|
|
|
|
|
prop: "__vendetta_syscolors"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(globalThis, "__vendetta_syscolors", {
|
|
|
|
|
get: () => getSysColors(),
|
|
|
|
|
configurable: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (isThemeSupported()) {
|
|
|
|
|
loader.features.themes = {
|
|
|
|
|
prop: "__vendetta_theme"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(globalThis, "__vendetta_theme", {
|
|
|
|
|
get: () => getStoredTheme(),
|
|
|
|
|
configurable: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(globalThis, "__vendetta_loader", {
|
|
|
|
|
get: () => loader,
|
|
|
|
|
configurable: true
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-23 15:11:35 +08:00
|
|
|
return loader as VendettaLoaderIdentity;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-02-28 14:09:42 +08:00
|
|
|
export function getLoaderIdentity() {
|
|
|
|
|
if (isPyonLoader()) {
|
|
|
|
|
return pyonLoaderIdentity;
|
|
|
|
|
} else if (isVendettaLoader()) {
|
|
|
|
|
return getVendettaLoaderIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 15:11:35 +08:00
|
|
|
export function getVendettaLoaderIdentity(): VendettaLoaderIdentity | null {
|
2024-02-23 00:33:40 +08:00
|
|
|
// @ts-ignore
|
|
|
|
|
if (globalThis.__vendetta_loader) return globalThis.__vendetta_loader;
|
2024-02-23 13:29:06 +08:00
|
|
|
return polyfillVendettaLoaderIdentity();
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add to __vendetta_loader anyway
|
2024-02-23 13:29:06 +08:00
|
|
|
getVendettaLoaderIdentity();
|
2024-02-23 00:33:40 +08:00
|
|
|
|
|
|
|
|
export function getLoaderName() {
|
2024-02-23 13:29:06 +08:00
|
|
|
if (isPyonLoader()) return pyonLoaderIdentity.loaderName;
|
|
|
|
|
else if (isVendettaLoader()) return vendettaLoaderIdentity.name;
|
2024-02-23 00:33:40 +08:00
|
|
|
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isLoaderConfigSupported() {
|
|
|
|
|
if (isPyonLoader()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.loaderConfig;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isThemeSupported() {
|
|
|
|
|
if (isPyonLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return pyonLoaderIdentity.hasThemeSupport;
|
2024-02-23 00:33:40 +08:00
|
|
|
} else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.themes != null;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getStoredTheme(): Theme | null {
|
|
|
|
|
if (isPyonLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return pyonLoaderIdentity.storedTheme;
|
2024-02-23 00:33:40 +08:00
|
|
|
} else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
const themeProp = vendettaLoaderIdentity!!.features.themes?.prop;
|
2024-02-23 00:33:40 +08:00
|
|
|
if (!themeProp) return null;
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return globalThis[themeProp] || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getThemeFilePath() {
|
|
|
|
|
if (isPyonLoader()) {
|
|
|
|
|
return "pyoncord/current-theme.json"
|
|
|
|
|
} else if (isVendettaLoader()) {
|
|
|
|
|
return "vendetta_theme.json";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isReactDevToolsPreloaded() {
|
|
|
|
|
if (isPyonLoader()) return false;
|
|
|
|
|
else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.devtools != null;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getReactDevToolsProp(): string | null {
|
|
|
|
|
if (!isReactDevToolsPreloaded()) return null;
|
|
|
|
|
|
|
|
|
|
if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.devtools!!.prop;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getReactDevToolsVersion() {
|
|
|
|
|
if (!isReactDevToolsPreloaded()) return null;
|
|
|
|
|
|
|
|
|
|
if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.devtools!!.version
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isSysColorsSupported() {
|
2024-02-23 13:29:06 +08:00
|
|
|
if (isPyonLoader()) return pyonLoaderIdentity.isSysColorsSupported;
|
2024-02-23 00:33:40 +08:00
|
|
|
else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.syscolors != null;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSysColors() {
|
|
|
|
|
if (!isSysColorsSupported()) return null;
|
|
|
|
|
if (isPyonLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return pyonLoaderIdentity.sysColors;
|
2024-02-23 00:33:40 +08:00
|
|
|
} else if (isVendettaLoader()) {
|
2024-02-23 13:29:06 +08:00
|
|
|
return vendettaLoaderIdentity!!.features.syscolors!!.prop;
|
2024-02-23 00:33:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getLoaderConfigPath() {
|
|
|
|
|
if (isPyonLoader()) {
|
|
|
|
|
return "pyoncord/loader.json";
|
|
|
|
|
} else if (isVendettaLoader()) {
|
|
|
|
|
return "vendetta_loader.json";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "loader.json";
|
|
|
|
|
}
|