add splash animation preview in the vesktop settings
This commit is contained in:
parent
80e0fb738e
commit
209d4cde81
3 changed files with 47 additions and 15 deletions
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import "./ipc";
|
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 { autoUpdater } from "electron-updater";
|
||||||
|
|
||||||
import { DATA_DIR } from "./constants";
|
import { DATA_DIR } from "./constants";
|
||||||
|
@ -80,11 +80,35 @@ function init() {
|
||||||
|
|
||||||
registerScreenShareHandler();
|
registerScreenShareHandler();
|
||||||
registerMediaPermissionsHandler();
|
registerMediaPermissionsHandler();
|
||||||
|
|
||||||
//register file handler so we can load the custom splash animation from the user's filesystem
|
//register file handler so we can load the custom splash animation from the user's filesystem
|
||||||
protocol.handle("splash-animation", () => {
|
protocol.handle("splash-animation", () => {
|
||||||
return net.fetch("file:///"+splashAnimationPath);
|
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();
|
bootstrap();
|
||||||
|
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BrowserWindow, webContents } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { SplashProps } from "shared/browserWinProperties";
|
import { SplashProps } from "shared/browserWinProperties";
|
||||||
import { ICON_PATH, VIEW_DIR } from "shared/paths";
|
import { ICON_PATH, VIEW_DIR } from "shared/paths";
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* 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";
|
import { SettingsComponent } from "./Settings";
|
||||||
|
|
||||||
|
@ -13,19 +13,27 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => {
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<Forms.FormText>
|
<Forms.FormText>
|
||||||
The animation on the splash window is loaded from{" "}
|
|
||||||
{settings.splashAnimationPath ? (
|
{settings.splashAnimationPath ? (
|
||||||
<a
|
<div style={{
|
||||||
href="about:blank"
|
display: "flex",
|
||||||
onClick={e => {
|
alignItems: "center",
|
||||||
e.preventDefault();
|
gap: "16px"
|
||||||
VesktopNative.fileManager.showItemInFolder(settings.splashAnimationPath!);
|
}}>
|
||||||
}}
|
<img src="splash-animation:///" width="64px" height="64px"></img>
|
||||||
>
|
<p>The custom splash animation is enabled. It is loaded from
|
||||||
{settings.splashAnimationPath}
|
<a
|
||||||
</a>
|
href="about:blank"
|
||||||
|
onClick={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
VesktopNative.fileManager.showItemInFolder(settings.splashAnimationPath!);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{" " + settings.splashAnimationPath}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
"the default location"
|
"A custom splash animation is not set."
|
||||||
)}
|
)}
|
||||||
</Forms.FormText>
|
</Forms.FormText>
|
||||||
<div className="vcd-location-btns" style={{marginBottom: 20}}>
|
<div className="vcd-location-btns" style={{marginBottom: 20}}>
|
||||||
|
@ -36,7 +44,7 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => {
|
||||||
if (choice === "cancelled") return;
|
if (choice === "cancelled") return;
|
||||||
settings.splashAnimationPath = choice;
|
settings.splashAnimationPath = choice;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Change
|
Change
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
Loading…
Reference in a new issue