mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 11:27:02 -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: {
|
||||
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]) => ({ fileName: name as string, content: css }))
|
||||
),
|
||||
getThemeData: (fileName: string) => DataStore.get(fileName, themeStore),
|
||||
getSystemValues: async () => ({}),
|
||||
|
||||
openFolder: async () => Promise.reject("themes:openFolder is not supported on web"),
|
||||
},
|
||||
|
||||
native: {
|
||||
|
@ -110,7 +111,7 @@ window.VencordNative = {
|
|||
}
|
||||
},
|
||||
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,
|
||||
|
|
|
@ -33,10 +33,11 @@ export default {
|
|||
themes: {
|
||||
uploadTheme: (fileName: string, fileData: string) => invoke<void>(IpcEvents.UPLOAD_THEME, fileName, fileData),
|
||||
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),
|
||||
getThemeData: (fileName: string) => invoke<string | undefined>(IpcEvents.GET_THEME_DATA, fileName),
|
||||
getSystemValues: () => invoke<Record<string, string>>(IpcEvents.GET_THEME_SYSTEM_VALUES),
|
||||
|
||||
openFolder: () => invoke<void>(IpcEvents.OPEN_THEMES_FOLDER),
|
||||
},
|
||||
|
||||
updater: {
|
||||
|
@ -49,7 +50,8 @@ export default {
|
|||
settings: {
|
||||
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
||||
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: {
|
||||
|
|
|
@ -33,7 +33,7 @@ import { openInviteModal } from "@utils/discord";
|
|||
import { Margins } from "@utils/margins";
|
||||
import { classes } from "@utils/misc";
|
||||
import { openModal } from "@utils/modal";
|
||||
import { relaunch, showItemInFolder } from "@utils/native";
|
||||
import { relaunch } from "@utils/native";
|
||||
import { useAwaiter, useForceUpdater } from "@utils/react";
|
||||
import type { ThemeHeader } from "@utils/themes";
|
||||
import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd";
|
||||
|
@ -201,7 +201,6 @@ function ThemesTab() {
|
|||
const [themeLinkValid, setThemeLinkValid] = useState(false);
|
||||
const [userThemes, setUserThemes] = useState<ThemeHeader[] | null>(null);
|
||||
const [onlineThemes, setOnlineThemes] = useState<(UserThemeHeader & { link: string; })[] | null>(null);
|
||||
const [themeDir, , themeDirPending] = useAwaiter(VencordNative.themes.getThemesDir);
|
||||
|
||||
useEffect(() => {
|
||||
updateThemes();
|
||||
|
@ -345,8 +344,7 @@ function ThemesTab() {
|
|||
) : (
|
||||
<QuickAction
|
||||
text="Open Themes Folder"
|
||||
action={() => showItemInFolder(themeDir!)}
|
||||
disabled={themeDirPending}
|
||||
action={() => VencordNative.themes.openFolder()}
|
||||
Icon={FolderIcon}
|
||||
/>
|
||||
)}
|
||||
|
@ -519,13 +517,13 @@ export function CspErrorCard() {
|
|||
const isImgurHtmlDomain = (url: string) => url.startsWith("https://imgur.com/");
|
||||
|
||||
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");
|
||||
if (result !== "ok") return;
|
||||
|
||||
CspBlockedUrls.forEach(url => {
|
||||
if (new URL(url).hostname === hostname) {
|
||||
if (new URL(url).host === host) {
|
||||
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 { Margins } from "@utils/margins";
|
||||
import { identity, isEquicordPluginDev, isPluginDev } from "@utils/misc";
|
||||
import { relaunch, showItemInFolder } from "@utils/native";
|
||||
import { useAwaiter } from "@utils/react";
|
||||
import { relaunch } from "@utils/native";
|
||||
import { Button, Forms, GuildMemberStore, React, Select, Switch, UserStore } from "@webpack/common";
|
||||
|
||||
import BadgeAPI from "../../plugins/_api/badges";
|
||||
|
@ -43,9 +42,6 @@ type KeysOfType<Object, Type> = {
|
|||
}[keyof Object];
|
||||
|
||||
function EquicordSettings() {
|
||||
const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, {
|
||||
fallbackValue: "Loading..."
|
||||
});
|
||||
const settings = useSettings();
|
||||
|
||||
const donateImage = React.useMemo(
|
||||
|
@ -183,7 +179,7 @@ function EquicordSettings() {
|
|||
<QuickAction
|
||||
Icon={FolderIcon}
|
||||
text="Open Settings Folder"
|
||||
action={() => showItemInFolder(settingsDir)}
|
||||
action={() => VencordNative.settings.openFolder()}
|
||||
/>
|
||||
)}
|
||||
<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
|
||||
|
||||
export const CspPolicies: PolicyMap = {
|
||||
"localhost": ImageAndCssSrc,
|
||||
"127.0.0.1": ImageAndCssSrc,
|
||||
"http://localhost:*": ImageAndCssSrc,
|
||||
"http://127.0.0.1:*": ImageAndCssSrc,
|
||||
"localhost:*": ImageAndCssSrc,
|
||||
"127.0.0.1:*": ImageAndCssSrc,
|
||||
|
||||
"*.github.io": ImageAndCssSrc, // GitHub pages, 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[]) {
|
||||
try {
|
||||
const { hostname } = new URL(url);
|
||||
const { host } = new URL(url);
|
||||
|
||||
if (/[;'"\\]/.test(hostname)) return false;
|
||||
if (/[;'"\\]/.test(host)) return false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ function validate(url: string, directives: 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}`;
|
||||
|
||||
|
@ -73,7 +73,7 @@ async function addCspRule(_: IpcMainInvokeEvent, url: string, directives: string
|
|||
return "invalid";
|
||||
}
|
||||
|
||||
const domain = new URL(url).hostname;
|
||||
const domain = new URL(url).host;
|
||||
|
||||
if (domain in NativeSettings.store.customCspRules) {
|
||||
return "conflict";
|
||||
|
@ -113,7 +113,7 @@ function removeCspRule(_: IpcMainInvokeEvent, domain: string) {
|
|||
|
||||
function isDomainAllowed(_: IpcMainInvokeEvent, url: string, directives: string[]) {
|
||||
try {
|
||||
const domain = new URL(url).hostname;
|
||||
const domain = new URL(url).host;
|
||||
|
||||
const ruleForDomain = CspPolicies[domain] ?? NativeSettings.store.customCspRules[domain];
|
||||
if (!ruleForDomain) return false;
|
||||
|
|
|
@ -29,7 +29,7 @@ import { open, readdir, readFile } from "fs/promises";
|
|||
import { join, normalize } from "path";
|
||||
|
||||
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";
|
||||
|
||||
mkdirSync(THEMES_DIR, { recursive: true });
|
||||
|
@ -80,7 +80,6 @@ ipcMain.handle(IpcEvents.SET_QUICK_CSS, (_, css) =>
|
|||
writeFileSync(QUICKCSS_PATH, css)
|
||||
);
|
||||
|
||||
ipcMain.handle(IpcEvents.GET_THEMES_DIR, () => THEMES_DIR);
|
||||
ipcMain.handle(IpcEvents.GET_THEMES_LIST, () => listThemes());
|
||||
ipcMain.handle(IpcEvents.GET_THEME_DATA, (_, fileName) => getThemeData(fileName));
|
||||
ipcMain.handle(IpcEvents.GET_THEME_SYSTEM_VALUES, () => ({
|
||||
|
@ -88,6 +87,8 @@ ipcMain.handle(IpcEvents.GET_THEME_SYSTEM_VALUES, () => ({
|
|||
"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) {
|
||||
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.handle(IpcEvents.SET_SETTINGS, (_, data: Settings, pathToNotify?: string) => {
|
||||
|
|
|
@ -17,25 +17,30 @@
|
|||
*/
|
||||
|
||||
export const enum IpcEvents {
|
||||
QUICK_CSS_UPDATE = "VencordQuickCssUpdate",
|
||||
THEME_UPDATE = "VencordThemeUpdate",
|
||||
OPEN_QUICKCSS = "VencordOpenQuickCss",
|
||||
GET_QUICK_CSS = "VencordGetQuickCss",
|
||||
SET_QUICK_CSS = "VencordSetQuickCss",
|
||||
UPLOAD_THEME = "VencordUploadTheme",
|
||||
DELETE_THEME = "VencordDeleteTheme",
|
||||
GET_THEMES_DIR = "VencordGetThemesDir",
|
||||
QUICK_CSS_UPDATE = "VencordQuickCssUpdate",
|
||||
|
||||
GET_SETTINGS = "VencordGetSettings",
|
||||
SET_SETTINGS = "VencordSetSettings",
|
||||
|
||||
GET_THEMES_LIST = "VencordGetThemesList",
|
||||
GET_THEME_DATA = "VencordGetThemeData",
|
||||
GET_THEME_SYSTEM_VALUES = "VencordGetThemeSystemValues",
|
||||
GET_SETTINGS_DIR = "VencordGetSettingsDir",
|
||||
GET_SETTINGS = "VencordGetSettings",
|
||||
SET_SETTINGS = "VencordSetSettings",
|
||||
UPLOAD_THEME = "VencordUploadTheme",
|
||||
DELETE_THEME = "VencordDeleteTheme",
|
||||
THEME_UPDATE = "VencordThemeUpdate",
|
||||
|
||||
OPEN_EXTERNAL = "VencordOpenExternal",
|
||||
OPEN_QUICKCSS = "VencordOpenQuickCss",
|
||||
OPEN_THEMES_FOLDER = "VencordOpenThemesFolder",
|
||||
OPEN_SETTINGS_FOLDER = "VencordOpenSettingsFolder",
|
||||
|
||||
GET_UPDATES = "VencordGetUpdates",
|
||||
GET_REPO = "VencordGetRepo",
|
||||
UPDATE = "VencordUpdate",
|
||||
BUILD = "VencordBuild",
|
||||
|
||||
OPEN_MONACO_EDITOR = "VencordOpenMonacoEditor",
|
||||
|
||||
GET_PLUGIN_IPC_METHOD_MAP = "VencordGetPluginIpcMethodMap",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue