copy file to vesktop folder instead of storing full path
This commit is contained in:
parent
3822fb1ed3
commit
466488c7da
5 changed files with 26 additions and 19 deletions
|
@ -44,6 +44,7 @@ export const VENCORD_SETTINGS_DIR = join(DATA_DIR, "settings");
|
|||
export const VENCORD_QUICKCSS_FILE = join(VENCORD_SETTINGS_DIR, "quickCss.css");
|
||||
export const VENCORD_SETTINGS_FILE = join(VENCORD_SETTINGS_DIR, "settings.json");
|
||||
export const VENCORD_THEMES_DIR = join(DATA_DIR, "themes");
|
||||
export const VESKTOP_SPLASH_DIR = join(DATA_DIR, "splash");
|
||||
|
||||
// needs to be inline require because of circular dependency
|
||||
// as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
|
||||
import "./ipc";
|
||||
|
||||
import { join } from "path";
|
||||
import { app, BrowserWindow, nativeTheme, net, protocol, session } from "electron";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
|
||||
import { DATA_DIR } from "./constants";
|
||||
import { DATA_DIR, VESKTOP_SPLASH_DIR } from "./constants";
|
||||
import { createFirstLaunchTour } from "./firstLaunch";
|
||||
import { createWindows, mainWin } from "./mainWindow";
|
||||
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
||||
|
@ -84,7 +85,8 @@ function init() {
|
|||
//register file handler so we can load the custom splash animation from the user's filesystem
|
||||
protocol.handle("splash-animation", () => {
|
||||
const { splashAnimationPath } = Settings.store;
|
||||
return net.fetch("file:///"+splashAnimationPath);
|
||||
const fullPath = join(VESKTOP_SPLASH_DIR, splashAnimationPath as string);
|
||||
return net.fetch("file:///"+fullPath);
|
||||
});
|
||||
|
||||
//this patches the discord csp to allow the splash-animation:// protocol
|
||||
|
|
|
@ -9,15 +9,16 @@ 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 { open, readFile } from "fs/promises";
|
||||
import { open, readFile, copyFile, mkdir, rmdir } from "fs/promises";
|
||||
import { release } from "os";
|
||||
import { join } from "path";
|
||||
import { randomBytes } from "crypto";
|
||||
import { join, extname } from "path";
|
||||
import { debounce } from "shared/utils/debounce";
|
||||
|
||||
import { IpcEvents } from "../shared/IpcEvents";
|
||||
import { setBadgeCount } from "./appBadge";
|
||||
import { autoStart } from "./autoStart";
|
||||
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
|
||||
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR, VESKTOP_SPLASH_DIR } from "./constants";
|
||||
import { mainWin } from "./mainWindow";
|
||||
import { Settings, State } from "./settings";
|
||||
import { handle, handleSync } from "./utils/ipcWrappers";
|
||||
|
@ -134,7 +135,17 @@ handle(IpcEvents.SELECT_IMAGE_PATH, async () => {
|
|||
]
|
||||
});
|
||||
if (!res.filePaths.length) return "cancelled";
|
||||
return res.filePaths[0];
|
||||
|
||||
const originalPath = res.filePaths[0];
|
||||
const uuid = randomBytes(16).toString("hex");
|
||||
const imageName = "splash_" + uuid + extname(originalPath);
|
||||
const destPath = join(VESKTOP_SPLASH_DIR, imageName);
|
||||
|
||||
await rmdir(VESKTOP_SPLASH_DIR, {recursive: true})
|
||||
await mkdir(VESKTOP_SPLASH_DIR, {recursive: true});
|
||||
await copyFile(originalPath, destPath);
|
||||
|
||||
return imageName;
|
||||
});
|
||||
|
||||
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => setBadgeCount(count));
|
||||
|
|
|
@ -35,7 +35,7 @@ export const VesktopNative = {
|
|||
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
|
||||
getVencordDir: () => sendSync<string | undefined>(IpcEvents.GET_VENCORD_DIR),
|
||||
selectVencordDir: (value?: null) => invoke<"cancelled" | "invalid" | "ok">(IpcEvents.SELECT_VENCORD_DIR, value),
|
||||
selectImagePath: () => invoke<LiteralUnion<"cancelled", string>>(IpcEvents.SELECT_IMAGE_PATH)
|
||||
selectImagePath: () => invoke<"cancelled" | string>(IpcEvents.SELECT_IMAGE_PATH)
|
||||
},
|
||||
settings: {
|
||||
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
||||
|
|
|
@ -21,17 +21,7 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => {
|
|||
}}>
|
||||
{/* adding the Math.random() here ensures that a new image is fetched when the user changes the path */}
|
||||
<img src={"splash-animation:///" + Math.random()} width="64px" height="64px"></img>
|
||||
<p>The custom splash animation is enabled. It is loaded from
|
||||
<a
|
||||
href="about:blank"
|
||||
onClick={e => {
|
||||
e.preventDefault();
|
||||
VesktopNative.fileManager.showItemInFolder(settings.splashAnimationPath!);
|
||||
}}
|
||||
>
|
||||
{" " + settings.splashAnimationPath}
|
||||
</a>
|
||||
</p>
|
||||
<p>The custom splash animation is enabled.</p>
|
||||
</div>
|
||||
) : (
|
||||
"A custom splash animation is not set."
|
||||
|
@ -51,7 +41,10 @@ export const CustomSplashAnimation: SettingsComponent = ({ settings }) => {
|
|||
<Button
|
||||
size={Button.Sizes.SMALL}
|
||||
color={Button.Colors.RED}
|
||||
onClick={() => (settings.splashAnimationPath = void 0)}
|
||||
onClick={() => {
|
||||
//todo: delete the image after resetting the path?
|
||||
settings.splashAnimationPath = undefined
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
|
|
Loading…
Reference in a new issue