mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-20 03:47:01 -04:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
4a2ee88cf1
9 changed files with 39 additions and 35 deletions
|
@ -41,12 +41,13 @@ window.VencordNative = {
|
||||||
themes: {
|
themes: {
|
||||||
uploadTheme: (fileName: string, fileData: string) => DataStore.set(fileName, fileData, themeStore),
|
uploadTheme: (fileName: string, fileData: string) => DataStore.set(fileName, fileData, themeStore),
|
||||||
deleteTheme: (fileName: string) => DataStore.del(fileName, themeStore),
|
deleteTheme: (fileName: string) => DataStore.del(fileName, themeStore),
|
||||||
getThemesDir: async () => "",
|
|
||||||
getThemesList: () => DataStore.entries(themeStore).then(entries =>
|
getThemesList: () => DataStore.entries(themeStore).then(entries =>
|
||||||
entries.map(([name, css]) => ({ fileName: name as string, content: css }))
|
entries.map(([name, css]) => ({ fileName: name as string, content: css }))
|
||||||
),
|
),
|
||||||
getThemeData: (fileName: string) => DataStore.get(fileName, themeStore),
|
getThemeData: (fileName: string) => DataStore.get(fileName, themeStore),
|
||||||
getSystemValues: async () => ({}),
|
getSystemValues: async () => ({}),
|
||||||
|
|
||||||
|
openFolder: async () => Promise.reject("themes:openFolder is not supported on web"),
|
||||||
},
|
},
|
||||||
|
|
||||||
native: {
|
native: {
|
||||||
|
@ -110,7 +111,7 @@ window.VencordNative = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: async (s: Settings) => localStorage.setItem("EquicordSettings", JSON.stringify(s)),
|
set: async (s: Settings) => localStorage.setItem("EquicordSettings", JSON.stringify(s)),
|
||||||
getSettingsDir: async () => "LocalStorage"
|
openFolder: async () => Promise.reject("settings:openFolder is not supported on web"),
|
||||||
},
|
},
|
||||||
|
|
||||||
pluginHelpers: {} as any,
|
pluginHelpers: {} as any,
|
||||||
|
|
|
@ -33,10 +33,11 @@ export default {
|
||||||
themes: {
|
themes: {
|
||||||
uploadTheme: (fileName: string, fileData: string) => invoke<void>(IpcEvents.UPLOAD_THEME, fileName, fileData),
|
uploadTheme: (fileName: string, fileData: string) => invoke<void>(IpcEvents.UPLOAD_THEME, fileName, fileData),
|
||||||
deleteTheme: (fileName: string) => invoke<void>(IpcEvents.DELETE_THEME, fileName),
|
deleteTheme: (fileName: string) => invoke<void>(IpcEvents.DELETE_THEME, fileName),
|
||||||
getThemesDir: () => invoke<string>(IpcEvents.GET_THEMES_DIR),
|
|
||||||
getThemesList: () => invoke<Array<{ fileName: string; content: string; }>>(IpcEvents.GET_THEMES_LIST),
|
getThemesList: () => invoke<Array<{ fileName: string; content: string; }>>(IpcEvents.GET_THEMES_LIST),
|
||||||
getThemeData: (fileName: string) => invoke<string | undefined>(IpcEvents.GET_THEME_DATA, fileName),
|
getThemeData: (fileName: string) => invoke<string | undefined>(IpcEvents.GET_THEME_DATA, fileName),
|
||||||
getSystemValues: () => invoke<Record<string, string>>(IpcEvents.GET_THEME_SYSTEM_VALUES),
|
getSystemValues: () => invoke<Record<string, string>>(IpcEvents.GET_THEME_SYSTEM_VALUES),
|
||||||
|
|
||||||
|
openFolder: () => invoke<void>(IpcEvents.OPEN_THEMES_FOLDER),
|
||||||
},
|
},
|
||||||
|
|
||||||
updater: {
|
updater: {
|
||||||
|
@ -49,7 +50,8 @@ export default {
|
||||||
settings: {
|
settings: {
|
||||||
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
||||||
set: (settings: Settings, pathToNotify?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, pathToNotify),
|
set: (settings: Settings, pathToNotify?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, pathToNotify),
|
||||||
getSettingsDir: () => invoke<string>(IpcEvents.GET_SETTINGS_DIR),
|
|
||||||
|
openFolder: () => invoke<void>(IpcEvents.OPEN_SETTINGS_FOLDER),
|
||||||
},
|
},
|
||||||
|
|
||||||
quickCss: {
|
quickCss: {
|
||||||
|
|
|
@ -33,7 +33,7 @@ import { openInviteModal } from "@utils/discord";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import { openModal } from "@utils/modal";
|
import { openModal } from "@utils/modal";
|
||||||
import { relaunch, showItemInFolder } from "@utils/native";
|
import { relaunch } from "@utils/native";
|
||||||
import { useAwaiter, useForceUpdater } from "@utils/react";
|
import { useAwaiter, useForceUpdater } from "@utils/react";
|
||||||
import type { ThemeHeader } from "@utils/themes";
|
import type { ThemeHeader } from "@utils/themes";
|
||||||
import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd";
|
import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd";
|
||||||
|
@ -201,7 +201,6 @@ function ThemesTab() {
|
||||||
const [themeLinkValid, setThemeLinkValid] = useState(false);
|
const [themeLinkValid, setThemeLinkValid] = useState(false);
|
||||||
const [userThemes, setUserThemes] = useState<ThemeHeader[] | null>(null);
|
const [userThemes, setUserThemes] = useState<ThemeHeader[] | null>(null);
|
||||||
const [onlineThemes, setOnlineThemes] = useState<(UserThemeHeader & { link: string; })[] | null>(null);
|
const [onlineThemes, setOnlineThemes] = useState<(UserThemeHeader & { link: string; })[] | null>(null);
|
||||||
const [themeDir, , themeDirPending] = useAwaiter(VencordNative.themes.getThemesDir);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateThemes();
|
updateThemes();
|
||||||
|
@ -345,8 +344,7 @@ function ThemesTab() {
|
||||||
) : (
|
) : (
|
||||||
<QuickAction
|
<QuickAction
|
||||||
text="Open Themes Folder"
|
text="Open Themes Folder"
|
||||||
action={() => showItemInFolder(themeDir!)}
|
action={() => VencordNative.themes.openFolder()}
|
||||||
disabled={themeDirPending}
|
|
||||||
Icon={FolderIcon}
|
Icon={FolderIcon}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -519,13 +517,13 @@ export function CspErrorCard() {
|
||||||
const isImgurHtmlDomain = (url: string) => url.startsWith("https://imgur.com/");
|
const isImgurHtmlDomain = (url: string) => url.startsWith("https://imgur.com/");
|
||||||
|
|
||||||
const allowUrl = async (url: string) => {
|
const allowUrl = async (url: string) => {
|
||||||
const { origin: baseUrl, hostname } = new URL(url);
|
const { origin: baseUrl, host } = new URL(url);
|
||||||
|
|
||||||
const result = await VencordNative.csp.requestAddOverride(baseUrl, ["connect-src", "img-src", "style-src", "font-src"], "Vencord Themes");
|
const result = await VencordNative.csp.requestAddOverride(baseUrl, ["connect-src", "img-src", "style-src", "font-src"], "Vencord Themes");
|
||||||
if (result !== "ok") return;
|
if (result !== "ok") return;
|
||||||
|
|
||||||
CspBlockedUrls.forEach(url => {
|
CspBlockedUrls.forEach(url => {
|
||||||
if (new URL(url).hostname === hostname) {
|
if (new URL(url).host === host) {
|
||||||
CspBlockedUrls.delete(url);
|
CspBlockedUrls.delete(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,8 +16,7 @@ import { gitRemote } from "@shared/vencordUserAgent";
|
||||||
import { DONOR_ROLE_ID, GUILD_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID } from "@utils/constants";
|
import { DONOR_ROLE_ID, GUILD_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID } from "@utils/constants";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { identity, isEquicordPluginDev, isPluginDev } from "@utils/misc";
|
import { identity, isEquicordPluginDev, isPluginDev } from "@utils/misc";
|
||||||
import { relaunch, showItemInFolder } from "@utils/native";
|
import { relaunch } from "@utils/native";
|
||||||
import { useAwaiter } from "@utils/react";
|
|
||||||
import { Button, Forms, GuildMemberStore, React, Select, Switch, UserStore } from "@webpack/common";
|
import { Button, Forms, GuildMemberStore, React, Select, Switch, UserStore } from "@webpack/common";
|
||||||
|
|
||||||
import BadgeAPI from "../../plugins/_api/badges";
|
import BadgeAPI from "../../plugins/_api/badges";
|
||||||
|
@ -43,9 +42,6 @@ type KeysOfType<Object, Type> = {
|
||||||
}[keyof Object];
|
}[keyof Object];
|
||||||
|
|
||||||
function EquicordSettings() {
|
function EquicordSettings() {
|
||||||
const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, {
|
|
||||||
fallbackValue: "Loading..."
|
|
||||||
});
|
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
|
|
||||||
const donateImage = React.useMemo(
|
const donateImage = React.useMemo(
|
||||||
|
@ -183,7 +179,7 @@ function EquicordSettings() {
|
||||||
<QuickAction
|
<QuickAction
|
||||||
Icon={FolderIcon}
|
Icon={FolderIcon}
|
||||||
text="Open Settings Folder"
|
text="Open Settings Folder"
|
||||||
action={() => showItemInFolder(settingsDir)}
|
action={() => VencordNative.settings.openFolder()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<QuickAction
|
<QuickAction
|
||||||
|
|
|
@ -19,8 +19,10 @@ export const ImageScriptsAndCssSrc = [...ImageAndCssSrc, "script-src", "worker-s
|
||||||
// script and just adding to it. But generally, you should just edit this file instead
|
// script and just adding to it. But generally, you should just edit this file instead
|
||||||
|
|
||||||
export const CspPolicies: PolicyMap = {
|
export const CspPolicies: PolicyMap = {
|
||||||
"localhost": ImageAndCssSrc,
|
"http://localhost:*": ImageAndCssSrc,
|
||||||
"127.0.0.1": ImageAndCssSrc,
|
"http://127.0.0.1:*": ImageAndCssSrc,
|
||||||
|
"localhost:*": ImageAndCssSrc,
|
||||||
|
"127.0.0.1:*": ImageAndCssSrc,
|
||||||
|
|
||||||
"*.github.io": ImageAndCssSrc, // GitHub pages, used by most themes
|
"*.github.io": ImageAndCssSrc, // GitHub pages, used by most themes
|
||||||
"github.com": ImageAndCssSrc, // GitHub content (stuff uploaded to markdown forms), used by most themes
|
"github.com": ImageAndCssSrc, // GitHub content (stuff uploaded to markdown forms), used by most themes
|
||||||
|
|
|
@ -20,9 +20,9 @@ export function registerCspIpcHandlers() {
|
||||||
|
|
||||||
function validate(url: string, directives: string[]) {
|
function validate(url: string, directives: string[]) {
|
||||||
try {
|
try {
|
||||||
const { hostname } = new URL(url);
|
const { host } = new URL(url);
|
||||||
|
|
||||||
if (/[;'"\\]/.test(hostname)) return false;
|
if (/[;'"\\]/.test(host)) return false;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ function validate(url: string, directives: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMessage(url: string, directives: string[], callerName: string) {
|
function getMessage(url: string, directives: string[], callerName: string) {
|
||||||
const domain = new URL(url).hostname;
|
const domain = new URL(url).host;
|
||||||
|
|
||||||
const message = `${callerName} wants to allow connections to ${domain}`;
|
const message = `${callerName} wants to allow connections to ${domain}`;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ async function addCspRule(_: IpcMainInvokeEvent, url: string, directives: string
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = new URL(url).hostname;
|
const domain = new URL(url).host;
|
||||||
|
|
||||||
if (domain in NativeSettings.store.customCspRules) {
|
if (domain in NativeSettings.store.customCspRules) {
|
||||||
return "conflict";
|
return "conflict";
|
||||||
|
@ -113,7 +113,7 @@ function removeCspRule(_: IpcMainInvokeEvent, domain: string) {
|
||||||
|
|
||||||
function isDomainAllowed(_: IpcMainInvokeEvent, url: string, directives: string[]) {
|
function isDomainAllowed(_: IpcMainInvokeEvent, url: string, directives: string[]) {
|
||||||
try {
|
try {
|
||||||
const domain = new URL(url).hostname;
|
const domain = new URL(url).host;
|
||||||
|
|
||||||
const ruleForDomain = CspPolicies[domain] ?? NativeSettings.store.customCspRules[domain];
|
const ruleForDomain = CspPolicies[domain] ?? NativeSettings.store.customCspRules[domain];
|
||||||
if (!ruleForDomain) return false;
|
if (!ruleForDomain) return false;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import { open, readdir, readFile } from "fs/promises";
|
||||||
import { join, normalize } from "path";
|
import { join, normalize } from "path";
|
||||||
|
|
||||||
import { registerCspIpcHandlers } from "./csp/manager";
|
import { registerCspIpcHandlers } from "./csp/manager";
|
||||||
import { ALLOWED_PROTOCOLS, QUICKCSS_PATH, THEMES_DIR } from "./utils/constants";
|
import { ALLOWED_PROTOCOLS, QUICKCSS_PATH, SETTINGS_DIR, THEMES_DIR } from "./utils/constants";
|
||||||
import { makeLinksOpenExternally } from "./utils/externalLinks";
|
import { makeLinksOpenExternally } from "./utils/externalLinks";
|
||||||
|
|
||||||
mkdirSync(THEMES_DIR, { recursive: true });
|
mkdirSync(THEMES_DIR, { recursive: true });
|
||||||
|
@ -80,7 +80,6 @@ ipcMain.handle(IpcEvents.SET_QUICK_CSS, (_, css) =>
|
||||||
writeFileSync(QUICKCSS_PATH, css)
|
writeFileSync(QUICKCSS_PATH, css)
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.handle(IpcEvents.GET_THEMES_DIR, () => THEMES_DIR);
|
|
||||||
ipcMain.handle(IpcEvents.GET_THEMES_LIST, () => listThemes());
|
ipcMain.handle(IpcEvents.GET_THEMES_LIST, () => listThemes());
|
||||||
ipcMain.handle(IpcEvents.GET_THEME_DATA, (_, fileName) => getThemeData(fileName));
|
ipcMain.handle(IpcEvents.GET_THEME_DATA, (_, fileName) => getThemeData(fileName));
|
||||||
ipcMain.handle(IpcEvents.GET_THEME_SYSTEM_VALUES, () => ({
|
ipcMain.handle(IpcEvents.GET_THEME_SYSTEM_VALUES, () => ({
|
||||||
|
@ -88,6 +87,8 @@ ipcMain.handle(IpcEvents.GET_THEME_SYSTEM_VALUES, () => ({
|
||||||
"os-accent-color": `#${systemPreferences.getAccentColor?.() || ""}`
|
"os-accent-color": `#${systemPreferences.getAccentColor?.() || ""}`
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.OPEN_THEMES_FOLDER, () => shell.openPath(THEMES_DIR));
|
||||||
|
ipcMain.handle(IpcEvents.OPEN_SETTINGS_FOLDER, () => shell.openPath(SETTINGS_DIR));
|
||||||
|
|
||||||
export function initIpc(mainWindow: BrowserWindow) {
|
export function initIpc(mainWindow: BrowserWindow) {
|
||||||
let quickCssWatcher: FSWatcher | undefined;
|
let quickCssWatcher: FSWatcher | undefined;
|
||||||
|
|
|
@ -36,7 +36,6 @@ RendererSettings.addGlobalChangeListener(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR);
|
|
||||||
ipcMain.on(IpcEvents.GET_SETTINGS, e => e.returnValue = RendererSettings.plain);
|
ipcMain.on(IpcEvents.GET_SETTINGS, e => e.returnValue = RendererSettings.plain);
|
||||||
|
|
||||||
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, data: Settings, pathToNotify?: string) => {
|
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, data: Settings, pathToNotify?: string) => {
|
||||||
|
|
|
@ -17,25 +17,30 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const enum IpcEvents {
|
export const enum IpcEvents {
|
||||||
QUICK_CSS_UPDATE = "VencordQuickCssUpdate",
|
OPEN_QUICKCSS = "VencordOpenQuickCss",
|
||||||
THEME_UPDATE = "VencordThemeUpdate",
|
|
||||||
GET_QUICK_CSS = "VencordGetQuickCss",
|
GET_QUICK_CSS = "VencordGetQuickCss",
|
||||||
SET_QUICK_CSS = "VencordSetQuickCss",
|
SET_QUICK_CSS = "VencordSetQuickCss",
|
||||||
UPLOAD_THEME = "VencordUploadTheme",
|
QUICK_CSS_UPDATE = "VencordQuickCssUpdate",
|
||||||
DELETE_THEME = "VencordDeleteTheme",
|
|
||||||
GET_THEMES_DIR = "VencordGetThemesDir",
|
GET_SETTINGS = "VencordGetSettings",
|
||||||
|
SET_SETTINGS = "VencordSetSettings",
|
||||||
|
|
||||||
GET_THEMES_LIST = "VencordGetThemesList",
|
GET_THEMES_LIST = "VencordGetThemesList",
|
||||||
GET_THEME_DATA = "VencordGetThemeData",
|
GET_THEME_DATA = "VencordGetThemeData",
|
||||||
GET_THEME_SYSTEM_VALUES = "VencordGetThemeSystemValues",
|
GET_THEME_SYSTEM_VALUES = "VencordGetThemeSystemValues",
|
||||||
GET_SETTINGS_DIR = "VencordGetSettingsDir",
|
UPLOAD_THEME = "VencordUploadTheme",
|
||||||
GET_SETTINGS = "VencordGetSettings",
|
DELETE_THEME = "VencordDeleteTheme",
|
||||||
SET_SETTINGS = "VencordSetSettings",
|
THEME_UPDATE = "VencordThemeUpdate",
|
||||||
|
|
||||||
OPEN_EXTERNAL = "VencordOpenExternal",
|
OPEN_EXTERNAL = "VencordOpenExternal",
|
||||||
OPEN_QUICKCSS = "VencordOpenQuickCss",
|
OPEN_THEMES_FOLDER = "VencordOpenThemesFolder",
|
||||||
|
OPEN_SETTINGS_FOLDER = "VencordOpenSettingsFolder",
|
||||||
|
|
||||||
GET_UPDATES = "VencordGetUpdates",
|
GET_UPDATES = "VencordGetUpdates",
|
||||||
GET_REPO = "VencordGetRepo",
|
GET_REPO = "VencordGetRepo",
|
||||||
UPDATE = "VencordUpdate",
|
UPDATE = "VencordUpdate",
|
||||||
BUILD = "VencordBuild",
|
BUILD = "VencordBuild",
|
||||||
|
|
||||||
OPEN_MONACO_EDITOR = "VencordOpenMonacoEditor",
|
OPEN_MONACO_EDITOR = "VencordOpenMonacoEditor",
|
||||||
|
|
||||||
GET_PLUGIN_IPC_METHOD_MAP = "VencordGetPluginIpcMethodMap",
|
GET_PLUGIN_IPC_METHOD_MAP = "VencordGetPluginIpcMethodMap",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue