This commit is contained in:
parent
3d1ea790a5
commit
593f6251a7
6 changed files with 76 additions and 3 deletions
|
|
@ -31,11 +31,13 @@ export { PlainSettings, Settings };
|
||||||
|
|
||||||
import { coreStyleRootNode, initStyles } from "@api/Styles";
|
import { coreStyleRootNode, initStyles } from "@api/Styles";
|
||||||
import { openSettingsTabModal, UpdaterTab } from "@components/settings";
|
import { openSettingsTabModal, UpdaterTab } from "@components/settings";
|
||||||
|
import { makeDummyUser } from "@equicordplugins/themeLibrary/components/ThemeCard";
|
||||||
|
import { openThemeInfoModal } from "@equicordplugins/themeLibrary/components/ThemeInfoModal";
|
||||||
import { debounce } from "@shared/debounce";
|
import { debounce } from "@shared/debounce";
|
||||||
import { IS_WINDOWS } from "@utils/constants";
|
import { IS_WINDOWS } from "@utils/constants";
|
||||||
import { createAndAppendStyle } from "@utils/css";
|
import { createAndAppendStyle } from "@utils/css";
|
||||||
import { StartAt } from "@utils/types";
|
import { StartAt } from "@utils/types";
|
||||||
import { SettingsRouter } from "@webpack/common";
|
import { SettingsRouter, UserUtils } from "@webpack/common";
|
||||||
|
|
||||||
import { get as dsGet } from "./api/DataStore";
|
import { get as dsGet } from "./api/DataStore";
|
||||||
import { popNotice, showNotice } from "./api/Notices";
|
import { popNotice, showNotice } from "./api/Notices";
|
||||||
|
|
@ -198,12 +200,35 @@ function initTrayIpc() {
|
||||||
VencordNative.tray.setUpdateState(getIsOutdated);
|
VencordNative.tray.setUpdateState(getIsOutdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initProtocol() {
|
||||||
|
if (IS_WEB || IS_UPDATER_DISABLED) return;
|
||||||
|
|
||||||
|
VencordNative.themes.onInstallTheme(async id => {
|
||||||
|
try {
|
||||||
|
const res = await fetch("https://themes.equicord.org/api/themes");
|
||||||
|
const themes = await res.json();
|
||||||
|
const theme = themes.find(t => String(t.id) === String(id));
|
||||||
|
if (!theme) throw new Error("Theme not found");
|
||||||
|
|
||||||
|
const getUser = (id, username) => UserUtils.getUser(id) ?? makeDummyUser({ username, id });
|
||||||
|
const authors = Array.isArray(theme.author)
|
||||||
|
? await Promise.all(theme.author.map(author => getUser(author.discord_snowflake, author.discord_name)))
|
||||||
|
: [await getUser(theme.author.discord_snowflake, theme.author.discord_name)];
|
||||||
|
|
||||||
|
openThemeInfoModal(theme, authors);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[Equicord] Failed to handle install-theme IPC", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
await onceReady;
|
await onceReady;
|
||||||
startAllPlugins(StartAt.WebpackReady);
|
startAllPlugins(StartAt.WebpackReady);
|
||||||
|
|
||||||
syncSettings();
|
syncSettings();
|
||||||
initTrayIpc();
|
initTrayIpc();
|
||||||
|
initProtocol();
|
||||||
|
|
||||||
if (!IS_DEV && !IS_WEB && !IS_UPDATER_DISABLED) {
|
if (!IS_DEV && !IS_WEB && !IS_UPDATER_DISABLED) {
|
||||||
runUpdateCheck();
|
runUpdateCheck();
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ export default {
|
||||||
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),
|
openFolder: () => invoke<void>(IpcEvents.OPEN_THEMES_FOLDER),
|
||||||
|
onInstallTheme: (cb: (id: string) => void) => {
|
||||||
|
ipcRenderer.on(IpcEvents.INSTALL_THEME, (_, id) => cb(id));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updater: {
|
updater: {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ interface ThemeCardProps {
|
||||||
|
|
||||||
const UserRecord: Constructor<Partial<User>> = proxyLazy(() => UserStore.getCurrentUser().constructor) as any;
|
const UserRecord: Constructor<Partial<User>> = proxyLazy(() => UserStore.getCurrentUser().constructor) as any;
|
||||||
|
|
||||||
function makeDummyUser(user: { username: string; id?: string; avatar?: string; }) {
|
export function makeDummyUser(user: { username: string; id?: string; avatar?: string; }) {
|
||||||
const newUser = new UserRecord({
|
const newUser = new UserRecord({
|
||||||
username: user.username,
|
username: user.username,
|
||||||
id: user.id ?? generateId(),
|
id: user.id ?? generateId(),
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ export const ThemeInfoModal: React.FC<ThemeInfoModalProps> = ({ author, theme, .
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Paragraph style={{ marginTop: "10px" }}>
|
<Paragraph style={{ marginTop: "10px" }}>
|
||||||
<Button onClick={() => VencordNative.native.openExternal(donate)}>
|
<Button onClick={() => VencordNative.native.openExternal(donate)}>
|
||||||
<Heart />
|
<Heart className={Margins.right4} />
|
||||||
Donate
|
Donate
|
||||||
</Button>
|
</Button>
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
|
|
@ -239,3 +239,7 @@ export const ThemeInfoModal: React.FC<ThemeInfoModalProps> = ({ author, theme, .
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function openThemeInfoModal(theme: Theme, authors: any[]) {
|
||||||
|
openModal(props => <ThemeInfoModal {...props} author={authors} theme={theme} />);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,46 @@ import { IS_VANILLA, THEMES_DIR } from "./utils/constants";
|
||||||
import { installExt } from "./utils/extensions";
|
import { installExt } from "./utils/extensions";
|
||||||
|
|
||||||
if (!IS_VANILLA && !IS_EXTENSION) {
|
if (!IS_VANILLA && !IS_EXTENSION) {
|
||||||
|
app.setAsDefaultProtocolClient("equicord");
|
||||||
|
|
||||||
|
const handleEquicordUrl = (urlStr: string) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(urlStr);
|
||||||
|
if (url.protocol === "equicord:") {
|
||||||
|
switch (url.hostname) {
|
||||||
|
case "install-theme":
|
||||||
|
const id = url.searchParams.get("id");
|
||||||
|
if (id) {
|
||||||
|
const { BrowserWindow } = require("electron");
|
||||||
|
BrowserWindow.getAllWindows().forEach(win => {
|
||||||
|
win.webContents.send("VencordInstallTheme", id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[Equicord] Failed to parse protocol URL", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
app.on("second-instance", (event, commandLine, workingDirectory) => {
|
||||||
|
const url = commandLine.find(arg => arg.startsWith("equicord://"));
|
||||||
|
if (url) {
|
||||||
|
console.log("[Equicord] Protocol URL opened:", url);
|
||||||
|
handleEquicordUrl(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on("open-url", (event, url) => {
|
||||||
|
if (url.startsWith("equicord://")) {
|
||||||
|
event.preventDefault();
|
||||||
|
console.log("[Equicord] Protocol URL opened:", url);
|
||||||
|
handleEquicordUrl(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
protocol.handle("vencord", ({ url: unsafeUrl }) => {
|
protocol.handle("vencord", ({ url: unsafeUrl }) => {
|
||||||
let url = decodeURI(unsafeUrl).slice("vencord://".length).replace(/\?v=\d+$/, "");
|
let url = decodeURI(unsafeUrl).slice("vencord://".length).replace(/\?v=\d+$/, "");
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ export const enum IpcEvents {
|
||||||
GET_MONACO_THEME = "VencordGetMonacoTheme",
|
GET_MONACO_THEME = "VencordGetMonacoTheme",
|
||||||
|
|
||||||
GET_PLUGIN_IPC_METHOD_MAP = "VencordGetPluginIpcMethodMap",
|
GET_PLUGIN_IPC_METHOD_MAP = "VencordGetPluginIpcMethodMap",
|
||||||
|
INSTALL_THEME = "VencordInstallTheme",
|
||||||
|
|
||||||
CSP_IS_DOMAIN_ALLOWED = "VencordCspIsDomainAllowed",
|
CSP_IS_DOMAIN_ALLOWED = "VencordCspIsDomainAllowed",
|
||||||
CSP_REMOVE_OVERRIDE = "VencordCspRemoveOverride",
|
CSP_REMOVE_OVERRIDE = "VencordCspRemoveOverride",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue