From 50d2b712d600eb25c371240b0b5381787263c2d5 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 22 Jan 2024 18:10:14 +0000 Subject: [PATCH 01/13] add option to disable the splash animation --- src/main/splash.ts | 6 +++++- src/renderer/components/Settings.tsx | 1 + src/shared/settings.d.ts | 1 + static/views/splash.html | 10 +++------- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/splash.ts b/src/main/splash.ts index 7c05de9..8b60895 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -20,7 +20,7 @@ export function createSplashWindow(startMinimized = false) { splash.loadFile(join(VIEW_DIR, "splash.html")); - const { splashBackground, splashColor, splashTheming } = Settings.store; + const { splashBackground, splashColor, splashTheming, disableSplashAnimation } = Settings.store; if (splashTheming) { if (splashColor) { @@ -35,5 +35,9 @@ export function createSplashWindow(startMinimized = false) { } } + if (!disableSplashAnimation) { + splash.webContents.insertCSS(`img {display: block !important}`); + } + return splash; } diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index eb0387f..236558e 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -49,6 +49,7 @@ export default function SettingsUi() { ["disableSmoothScroll", "Disable smooth scrolling", "Disables smooth scrolling in Vesktop", false], ["hardwareAcceleration", "Hardware Acceleration", "Enable hardware acceleration", true], ["splashTheming", "Splash theming", "Adapt the splash window colors to your custom theme", false], + ["disableSplashAnimation", "Disable splash animation", "Disable the animation on the splash window", false], [ "openLinksWithElectron", "Open Links in app (experimental)", diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index d796e4b..688e1a8 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -28,6 +28,7 @@ export interface Settings { checkUpdates?: boolean; splashTheming?: boolean; + disableSplashAnimation?: boolean; splashColor?: string; splashBackground?: string; } diff --git a/static/views/splash.html b/static/views/splash.html index bac2ad2..a125871 100644 --- a/static/views/splash.html +++ b/static/views/splash.html @@ -26,18 +26,14 @@ width: 128px; height: 128px; image-rendering: pixelated; + display: none; }
- shiggy + shiggy

Loading Vesktop...

- + \ No newline at end of file From c18e0c2c7cff41272f049efcb525e33b2ec6217e Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 22 Jan 2024 18:53:49 +0000 Subject: [PATCH 02/13] reduce size of splash screen when animation is disabled --- src/main/splash.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/splash.ts b/src/main/splash.ts index 8b60895..7283455 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -12,6 +12,11 @@ import { ICON_PATH, VIEW_DIR } from "shared/paths"; import { Settings } from "./settings"; export function createSplashWindow(startMinimized = false) { + const { splashBackground, splashColor, splashTheming, disableSplashAnimation } = Settings.store; + + if (disableSplashAnimation) { + SplashProps.height = 150; + } const splash = new BrowserWindow({ ...SplashProps, icon: ICON_PATH, @@ -20,8 +25,6 @@ export function createSplashWindow(startMinimized = false) { splash.loadFile(join(VIEW_DIR, "splash.html")); - const { splashBackground, splashColor, splashTheming, disableSplashAnimation } = Settings.store; - if (splashTheming) { if (splashColor) { const semiTransparentSplashColor = splashColor.replace("rgb(", "rgba(").replace(")", ", 0.2)"); From 454efff26d5ff2f3211e91f70348c59b866ebd8d Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 22 Jan 2024 23:39:13 +0000 Subject: [PATCH 03/13] add setting for custom splash animations --- src/main/index.ts | 8 +++++- src/main/ipc.ts | 11 ++++++++ src/main/splash.ts | 23 +++++++++------- src/preload/VesktopNative.ts | 3 ++- src/renderer/components/Settings.tsx | 40 +++++++++++++++++++++++++++- src/shared/IpcEvents.ts | 1 + src/shared/settings.d.ts | 2 +- static/views/splash.html | 4 +-- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 9d6a52c..780d52a 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -6,7 +6,7 @@ import "./ipc"; -import { app, BrowserWindow, nativeTheme } from "electron"; +import { app, BrowserWindow, nativeTheme, protocol } from "electron"; import { checkUpdates } from "updater/main"; import { DATA_DIR } from "./constants"; @@ -63,6 +63,12 @@ function init() { registerScreenShareHandler(); registerMediaPermissionsHandler(); + //register file handler so we can load the custom splash animation from the user's filesystem + protocol.registerFileProtocol("image", (request, callback) => { + const url = request.url.substring(8); + callback({path: url}); + }); + bootstrap(); app.on("activate", () => { diff --git a/src/main/ipc.ts b/src/main/ipc.ts index e0bf131..3bfca76 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -121,6 +121,17 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => { return dir; }); +handle(IpcEvents.SELECT_IMAGE_PATH, async () => { + const res = await dialog.showOpenDialog(mainWin!, { + properties: ["openFile"], + filters: [ + {name: "Images", extensions: ["apng", "avif", "gif", "jpeg", "png", "svg", "webp"]} + ] + }); + if (!res.filePaths.length) return "cancelled"; + return res.filePaths[0]; +}); + handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => setBadgeCount(count)); handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) => { diff --git a/src/main/splash.ts b/src/main/splash.ts index 7283455..1d1df1b 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { BrowserWindow } from "electron"; +import { BrowserWindow, webContents } from "electron"; import { join } from "path"; import { SplashProps } from "shared/browserWinProperties"; import { ICON_PATH, VIEW_DIR } from "shared/paths"; @@ -12,17 +12,14 @@ import { ICON_PATH, VIEW_DIR } from "shared/paths"; import { Settings } from "./settings"; export function createSplashWindow(startMinimized = false) { - const { splashBackground, splashColor, splashTheming, disableSplashAnimation } = Settings.store; + const { splashBackground, splashColor, splashTheming, splashAnimationPath } = Settings.store; - if (disableSplashAnimation) { - SplashProps.height = 150; - } const splash = new BrowserWindow({ ...SplashProps, icon: ICON_PATH, show: !startMinimized }); - + splash.loadFile(join(VIEW_DIR, "splash.html")); if (splashTheming) { @@ -37,9 +34,17 @@ export function createSplashWindow(startMinimized = false) { splash.webContents.insertCSS(`body { --bg: ${splashBackground} !important }`); } } - - if (!disableSplashAnimation) { - splash.webContents.insertCSS(`img {display: block !important}`); + + if (splashAnimationPath) { + splash.webContents.executeJavaScript(` + document.getElementById("animation").src = "image://${splashAnimationPath}"; + `); + } + else { + splash.webContents.insertCSS(`img {image-rendering: pixelated}`) + splash.webContents.executeJavaScript(` + document.getElementById("animation").src = "../shiggy.gif"; + `); } return splash; diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index a2ca74c..172d2c2 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -33,7 +33,8 @@ export const VesktopNative = { }, fileManager: { showItemInFolder: (path: string) => invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path), - selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR) + selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR), + selectImagePath: () => invoke>(IpcEvents.SELECT_IMAGE_PATH) }, settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index 236558e..5e3ed1c 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -49,7 +49,6 @@ export default function SettingsUi() { ["disableSmoothScroll", "Disable smooth scrolling", "Disables smooth scrolling in Vesktop", false], ["hardwareAcceleration", "Hardware Acceleration", "Enable hardware acceleration", true], ["splashTheming", "Splash theming", "Adapt the splash window colors to your custom theme", false], - ["disableSplashAnimation", "Disable splash animation", "Disable the animation on the splash window", false], [ "openLinksWithElectron", "Open Links in app (experimental)", @@ -154,6 +153,45 @@ export default function SettingsUi() { )} + Custom Spash Animation + + The animation on the splash window is loaded from{" "} + {Settings.splashAnimationPath ? ( + { + e.preventDefault(); + VesktopNative.fileManager.showItemInFolder(Settings.splashAnimationPath!); + }} + > + {Settings.splashAnimationPath} + + ) : ( + "the default location" + )} + +
+ + +
+ Vencord Location Vencord files are loaded from{" "} diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index df64403..b5d40c4 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -24,6 +24,7 @@ export const enum IpcEvents { SET_SETTINGS = "VCD_SET_SETTINGS", SELECT_VENCORD_DIR = "VCD_SELECT_VENCORD_DIR", + SELECT_IMAGE_PATH= "VCD_SELECT_IMAGE_PATH", UPDATER_GET_DATA = "VCD_UPDATER_GET_DATA", UPDATER_DOWNLOAD = "VCD_UPDATER_DOWNLOAD", diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index 688e1a8..d6e9dc2 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -28,7 +28,7 @@ export interface Settings { checkUpdates?: boolean; splashTheming?: boolean; - disableSplashAnimation?: boolean; + splashAnimationPath?: string; splashColor?: string; splashBackground?: string; } diff --git a/static/views/splash.html b/static/views/splash.html index a125871..4b91560 100644 --- a/static/views/splash.html +++ b/static/views/splash.html @@ -25,15 +25,13 @@ img { width: 128px; height: 128px; - image-rendering: pixelated; - display: none; }
- shiggy + animation

Loading Vesktop...

\ No newline at end of file From 1a828bfbdda9d9c12b2249e3c3df47be72908fe9 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 22 Jan 2024 23:54:10 +0000 Subject: [PATCH 04/13] avoid showing unloaded splash image --- static/views/splash.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/views/splash.html b/static/views/splash.html index 4b91560..85e0e45 100644 --- a/static/views/splash.html +++ b/static/views/splash.html @@ -24,14 +24,16 @@ img { width: 128px; - height: 128px; + height: 128px }
- animation + + animation

Loading Vesktop...

\ No newline at end of file From e962e34ec44f974e2b9cec539d91b216fec737c9 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 23 Jan 2024 00:43:22 +0000 Subject: [PATCH 05/13] remove debug console.log --- src/renderer/components/Settings.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index 5e3ed1c..72f19c5 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -174,9 +174,7 @@ export default function SettingsUi() { + + + + + ); +}; diff --git a/src/renderer/components/settings/DiscordBranchPicker.tsx b/src/renderer/components/settings/DiscordBranchPicker.tsx new file mode 100644 index 0000000..c0b840d --- /dev/null +++ b/src/renderer/components/settings/DiscordBranchPicker.tsx @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { Select } from "@vencord/types/webpack/common"; + +import { SettingsComponent } from "./Settings"; + +export const DiscordBranchPicker: SettingsComponent = ({ settings }) => { + return ( + (settings.transparencyOption = v)} + isSelected={v => v === settings.transparencyOption} + serialize={s => s} + /> + + + + ); +}; diff --git a/src/renderer/components/settings/settings.css b/src/renderer/components/settings/settings.css new file mode 100644 index 0000000..d55ff50 --- /dev/null +++ b/src/renderer/components/settings/settings.css @@ -0,0 +1,14 @@ +.vcd-location-btns { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 0.5em; + margin-top: 0.5em; +} + +.vcd-settings-section { + margin-top: 1.5rem; +} + +.vcd-settings-title { + margin-bottom: 0.5rem; +} \ No newline at end of file diff --git a/src/renderer/fixes.css b/src/renderer/fixes.css new file mode 100644 index 0000000..aeec1bf --- /dev/null +++ b/src/renderer/fixes.css @@ -0,0 +1,11 @@ +/* Download Desktop button in guilds list */ +[class^=listItem_]:has([data-list-item-id=guildsnav___app-download-button]), +[class^=listItem_]:has(+ [class^=listItem_] [data-list-item-id=guildsnav___app-download-button]) { + display: none; +} + +/* FIXME: remove this once Discord fixes their css to not explode scrollbars on chromium >=121 */ +* { + scrollbar-width: unset !important; + scrollbar-color: unset !important; +} \ No newline at end of file diff --git a/src/renderer/fixes.ts b/src/renderer/fixes.ts index 2524023..2758b5c 100644 --- a/src/renderer/fixes.ts +++ b/src/renderer/fixes.ts @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import "./hideGarbage.css"; +import "./fixes.css"; import { isWindows, localStorage } from "./utils"; diff --git a/src/renderer/index.ts b/src/renderer/index.ts index ebe6bc6..1ccc2e4 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -15,7 +15,7 @@ export * as Components from "./components"; import { findByPropsLazy } from "@vencord/types/webpack"; import { FluxDispatcher } from "@vencord/types/webpack/common"; -import SettingsUi from "./components/Settings"; +import SettingsUi from "./components/settings/Settings"; import { Settings } from "./settings"; export { Settings }; diff --git a/src/renderer/patches/hideSwitchDevice.tsx b/src/renderer/patches/hideSwitchDevice.tsx new file mode 100644 index 0000000..911aed7 --- /dev/null +++ b/src/renderer/patches/hideSwitchDevice.tsx @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + { + find: "lastOutputSystemDevice.justChanged", + replacement: { + // eslint-disable-next-line no-useless-escape + match: /(\i)\.default\.getState\(\).neverShowModal/, + replace: "$& || $self.shouldIgnore($1)" + } + } + ], + + shouldIgnore(state: any) { + return Object.keys(state?.default?.lastDeviceConnected ?? {})?.[0] === "vencord-screen-share"; + } +}); diff --git a/src/renderer/patches/hideVenmicInput.tsx b/src/renderer/patches/hideVenmicInput.tsx new file mode 100644 index 0000000..ca706ce --- /dev/null +++ b/src/renderer/patches/hideVenmicInput.tsx @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + { + find: 'setSinkId"in', + replacement: { + // eslint-disable-next-line no-useless-escape + match: /return (\i)\?navigator\.mediaDevices\.enumerateDevices/, + replace: "return $1 ? $self.filteredDevices" + } + } + ], + + async filteredDevices() { + const original = await navigator.mediaDevices.enumerateDevices(); + return original.filter(x => x.label !== "vencord-screen-share"); + } +}); diff --git a/src/renderer/patches/index.ts b/src/renderer/patches/index.ts index 7d4c4b3..aabff3e 100644 --- a/src/renderer/patches/index.ts +++ b/src/renderer/patches/index.ts @@ -7,6 +7,8 @@ // TODO: Possibly auto generate glob if we have more patches in the future import "./enableNotificationsByDefault"; import "./platformClass"; -import "./screenShareAudio"; +import "./hideSwitchDevice"; +import "./hideVenmicInput"; +import "./screenShareFixes"; import "./spellCheck"; import "./windowsTitleBar"; diff --git a/src/renderer/patches/screenShareFixes.ts b/src/renderer/patches/screenShareFixes.ts new file mode 100644 index 0000000..66e4b14 --- /dev/null +++ b/src/renderer/patches/screenShareFixes.ts @@ -0,0 +1,69 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { Logger } from "@vencord/types/utils"; +import { currentSettings } from "renderer/components/ScreenSharePicker"; +import { isLinux } from "renderer/utils"; + +const logger = new Logger("VesktopStreamFixes"); + +if (isLinux) { + const original = navigator.mediaDevices.getDisplayMedia; + + async function getVirtmic() { + try { + const devices = await navigator.mediaDevices.enumerateDevices(); + const audioDevice = devices.find(({ label }) => label === "vencord-screen-share"); + return audioDevice?.deviceId; + } catch (error) { + return null; + } + } + + navigator.mediaDevices.getDisplayMedia = async function (opts) { + const stream = await original.call(this, opts); + const id = await getVirtmic(); + + const frameRate = Number(currentSettings?.fps); + const height = Number(currentSettings?.resolution); + const width = Math.round(height * (16 / 9)); + const track = stream.getVideoTracks()[0]; + + track.contentHint = String(currentSettings?.contentHint); + + const constraints = { + ...track.getConstraints(), + frameRate, + width: { min: 640, ideal: width, max: width }, + height: { min: 480, ideal: height, max: height }, + advanced: [{ width: width, height: height }], + resizeMode: "none" + }; + + track + .applyConstraints(constraints) + .then(() => { + logger.info("Applied constraints successfully. New constraints: ", track.getConstraints()); + }) + .catch(e => logger.error("Failed to apply constraints.", e)); + + if (id) { + const audio = await navigator.mediaDevices.getUserMedia({ + audio: { + deviceId: { + exact: id + }, + autoGainControl: false, + echoCancellation: false, + noiseSuppression: false + } + }); + audio.getAudioTracks().forEach(t => stream.addTrack(t)); + } + + return stream; + }; +} diff --git a/src/renderer/patches/spellCheck.tsx b/src/renderer/patches/spellCheck.tsx index 038f06a..9f0dbbd 100644 --- a/src/renderer/patches/spellCheck.tsx +++ b/src/renderer/patches/spellCheck.tsx @@ -6,7 +6,7 @@ import { addContextMenuPatch } from "@vencord/types/api/ContextMenu"; import { findStoreLazy } from "@vencord/types/webpack"; -import { ContextMenu, FluxDispatcher, Menu } from "@vencord/types/webpack/common"; +import { FluxDispatcher, Menu, useStateFromStores } from "@vencord/types/webpack/common"; import { addPatch } from "./shared"; @@ -46,7 +46,8 @@ addPatch({ } }); -addContextMenuPatch("textarea-context", children => () => { +addContextMenuPatch("textarea-context", children => { + const spellCheckEnabled = useStateFromStores([SpellCheckStore], () => SpellCheckStore.isEnabled()); const hasCorrections = Boolean(word && corrections?.length); children.push( @@ -71,11 +72,9 @@ addContextMenuPatch("textarea-context", children => () => { { FluxDispatcher.dispatch({ type: "SPELLCHECK_TOGGLE" }); - // Haven't found a good way to update state, so just close for now 🤷‍♀️ - ContextMenu.close(); }} /> diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index d6e9dc2..fa46bac 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -20,7 +20,7 @@ export interface Settings { arRPC?: boolean; appBadge?: boolean; disableMinSize?: boolean; - + clickTrayToShowHide?: boolean; /** @deprecated use customTitleBar */ discordWindowsTitleBar?: boolean; customTitleBar?: boolean; @@ -28,8 +28,8 @@ export interface Settings { checkUpdates?: boolean; splashTheming?: boolean; - splashAnimationPath?: string; splashColor?: string; + splashAnimationPath?: string; splashBackground?: string; } diff --git a/src/updater/main.ts b/src/updater/main.ts index 059afb9..207687e 100644 --- a/src/updater/main.ts +++ b/src/updater/main.ts @@ -81,7 +81,7 @@ export async function checkUpdates() { try { const raw = await githubGet("/repos/Vencord/Vesktop/releases/latest"); - const data = JSON.parse(raw.toString("utf-8")) as ReleaseData; + const data: ReleaseData = await raw.json(); const oldVersion = app.getVersion(); const newVersion = data.tag_name.replace(/^v/, ""); diff --git a/static/views/splash.html b/static/views/splash.html index 85e0e45..a44b273 100644 --- a/static/views/splash.html +++ b/static/views/splash.html @@ -24,7 +24,7 @@ img { width: 128px; - height: 128px + height: 128px; } From e6467ea211f8e3f885b9143505a185c319bb598e Mon Sep 17 00:00:00 2001 From: ading2210 Date: Wed, 8 May 2024 17:06:07 -0700 Subject: [PATCH 09/13] remove unrelated edit --- src/renderer/components/ScreenSharePicker.tsx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/renderer/components/ScreenSharePicker.tsx b/src/renderer/components/ScreenSharePicker.tsx index e9fd78e..72bfa6f 100644 --- a/src/renderer/components/ScreenSharePicker.tsx +++ b/src/renderer/components/ScreenSharePicker.tsx @@ -63,20 +63,6 @@ addPatch({ match: /this.localWant=/, replace: "$self.patchStreamQuality(this);$&" } - }, - { - find: "x-google-max-bitrate", - replacement: [ - { - // eslint-disable-next-line no-useless-escape - match: /"x-google-max-bitrate=".concat\(\i\)/, - replace: '"x-google-max-bitrate=".concat("80_000")' - }, - { - match: /;level-asymmetry-allowed=1/, - replace: ";b=AS:800000;level-asymmetry-allowed=1" - } - ] } ], patchStreamQuality(opts: any) { @@ -534,4 +520,4 @@ function ModalComponent({ ); -} +} \ No newline at end of file From 209d4cde8193d45892e45426afee66724d6807ea Mon Sep 17 00:00:00 2001 From: ading2210 Date: Fri, 19 Jul 2024 04:03:55 -0700 Subject: [PATCH 10/13] add splash animation preview in the vesktop settings --- src/main/index.ts | 26 +++++++++++++- src/main/splash.ts | 2 +- .../settings/CustomSplashAnimation.tsx | 34 ++++++++++++------- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 663980a..97213fa 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -6,7 +6,7 @@ import "./ipc"; -import { app, BrowserWindow, nativeTheme, net, protocol } from "electron"; +import { app, BrowserWindow, nativeTheme, net, protocol, session } from "electron"; import { autoUpdater } from "electron-updater"; import { DATA_DIR } from "./constants"; @@ -80,11 +80,35 @@ function init() { registerScreenShareHandler(); registerMediaPermissionsHandler(); + //register file handler so we can load the custom splash animation from the user's filesystem protocol.handle("splash-animation", () => { return net.fetch("file:///"+splashAnimationPath); }); + //this patches the discord csp to allow the splash-animation:// protocol + //the vencord:// protocol is already whitelisted, but the code for doing that is in the + //vencord repo, not the vesktop one. hopefully in the future, the splash image functionality + //can be added to the vencord:// protocol handler, or the vencord:// protocol handler can be moved here + let otherHandler: any = null; + session.defaultSession.webRequest.onHeadersReceived(({responseHeaders, resourceType}, callback) => { + if (responseHeaders && resourceType === "mainFrame" && responseHeaders["content-security-policy"]) { + let csp = responseHeaders["content-security-policy"][0]; + csp = csp.replace("img-src", "img-src splash-animation:"); + responseHeaders["content-security-policy"] = [csp]; + } + if (otherHandler) { + otherHandler({responseHeaders, resourceType}, callback); + } + else { + callback({ cancel: false, responseHeaders }); + } + }); + //we need to overwrite onHeadersReceived because normally electron only allows one handler to be active at a time + session.defaultSession.webRequest.onHeadersReceived = (handler) => { + otherHandler = handler; + } + bootstrap(); app.on("activate", () => { diff --git a/src/main/splash.ts b/src/main/splash.ts index ee4a4f3..bde47ae 100644 --- a/src/main/splash.ts +++ b/src/main/splash.ts @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { BrowserWindow, webContents } from "electron"; +import { BrowserWindow } from "electron"; import { join } from "path"; import { SplashProps } from "shared/browserWinProperties"; import { ICON_PATH, VIEW_DIR } from "shared/paths"; diff --git a/src/renderer/components/settings/CustomSplashAnimation.tsx b/src/renderer/components/settings/CustomSplashAnimation.tsx index b7de314..1079a97 100644 --- a/src/renderer/components/settings/CustomSplashAnimation.tsx +++ b/src/renderer/components/settings/CustomSplashAnimation.tsx @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { Button, Forms, Toasts } from "@vencord/types/webpack/common"; +import { Button, Forms } from "@vencord/types/webpack/common"; import { SettingsComponent } from "./Settings"; @@ -13,19 +13,27 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => { <> - The animation on the splash window is loaded from{" "} {settings.splashAnimationPath ? ( - { - e.preventDefault(); - VesktopNative.fileManager.showItemInFolder(settings.splashAnimationPath!); - }} - > - {settings.splashAnimationPath} - + ) : ( - "the default location" + "A custom splash animation is not set." )}
@@ -36,7 +44,7 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => { if (choice === "cancelled") return; settings.splashAnimationPath = choice; }} - > + > Change
) : ( "A custom splash animation is not set." @@ -51,7 +41,10 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => { From 415aa19d91d55608cbf8b7e3b7371913956abbdd Mon Sep 17 00:00:00 2001 From: Allen Ding Date: Thu, 25 Jul 2024 19:05:33 -0700 Subject: [PATCH 13/13] fix rmdir error if splash dir was previously unset --- src/main/ipc.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index fc0f23a..b135fce 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -8,7 +8,7 @@ if (process.platform === "linux") import("./venmic"); import { execFile } from "child_process"; import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron"; -import { mkdirSync, readFileSync, watch } from "fs"; +import { mkdirSync, readFileSync, watch, existsSync } from "fs"; import { open, readFile, copyFile, mkdir, rmdir } from "fs/promises"; import { release } from "os"; import { randomBytes } from "crypto"; @@ -141,7 +141,9 @@ handle(IpcEvents.SELECT_IMAGE_PATH, async () => { const imageName = "splash_" + uuid + extname(originalPath); const destPath = join(VESKTOP_SPLASH_DIR, imageName); - await rmdir(VESKTOP_SPLASH_DIR, {recursive: true}) + if (existsSync(VESKTOP_SPLASH_DIR)) { + await rmdir(VESKTOP_SPLASH_DIR, {recursive: true}); + } await mkdir(VESKTOP_SPLASH_DIR, {recursive: true}); await copyFile(originalPath, destPath);