diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts index 15c9850f..072d6d01 100644 --- a/browser/VencordNativeStub.ts +++ b/browser/VencordNativeStub.ts @@ -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, diff --git a/src/VencordNative.ts b/src/VencordNative.ts index 56984ef3..1e602490 100644 --- a/src/VencordNative.ts +++ b/src/VencordNative.ts @@ -33,10 +33,11 @@ export default { themes: { uploadTheme: (fileName: string, fileData: string) => invoke(IpcEvents.UPLOAD_THEME, fileName, fileData), deleteTheme: (fileName: string) => invoke(IpcEvents.DELETE_THEME, fileName), - getThemesDir: () => invoke(IpcEvents.GET_THEMES_DIR), getThemesList: () => invoke>(IpcEvents.GET_THEMES_LIST), getThemeData: (fileName: string) => invoke(IpcEvents.GET_THEME_DATA, fileName), getSystemValues: () => invoke>(IpcEvents.GET_THEME_SYSTEM_VALUES), + + openFolder: () => invoke(IpcEvents.OPEN_THEMES_FOLDER), }, updater: { @@ -49,7 +50,8 @@ export default { settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), set: (settings: Settings, pathToNotify?: string) => invoke(IpcEvents.SET_SETTINGS, settings, pathToNotify), - getSettingsDir: () => invoke(IpcEvents.GET_SETTINGS_DIR), + + openFolder: () => invoke(IpcEvents.OPEN_SETTINGS_FOLDER), }, quickCss: { diff --git a/src/components/ThemeSettings/ThemesTab.tsx b/src/components/ThemeSettings/ThemesTab.tsx index c65a3030..d1d2a719 100644 --- a/src/components/ThemeSettings/ThemesTab.tsx +++ b/src/components/ThemeSettings/ThemesTab.tsx @@ -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(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() { ) : ( 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); } }); diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 606986b7..c4441b4c 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -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 = { }[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() { showItemInFolder(settingsDir)} + action={() => VencordNative.settings.openFolder()} /> )} 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; diff --git a/src/main/settings.ts b/src/main/settings.ts index ed2f4850..962bbaa7 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -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) => { diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 914a0a9f..e7eb7594 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -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",