mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 07:25:10 +00:00
CustomVoiceFilter: Add open model folder functionality
This commit is contained in:
parent
91e6f2dbed
commit
cff7492f37
2 changed files with 100 additions and 89 deletions
|
@ -20,6 +20,11 @@ import { openWikiHomeModal } from "./WikiHomeModal";
|
||||||
|
|
||||||
const Native = VencordNative.pluginHelpers.CustomVoiceFilters as PluginNative<typeof import("./native")>;
|
const Native = VencordNative.pluginHelpers.CustomVoiceFilters as PluginNative<typeof import("./native")>;
|
||||||
|
|
||||||
|
function openModelFolder() {
|
||||||
|
const { modulePath } = useVoiceFiltersStore.getState();
|
||||||
|
const modelFolder = Native.openFolder(modulePath);
|
||||||
|
}
|
||||||
|
|
||||||
export function openVoiceFiltersModal(): string {
|
export function openVoiceFiltersModal(): string {
|
||||||
const key = openModal(modalProps => (
|
const key = openModal(modalProps => (
|
||||||
<VoiceFiltersModal
|
<VoiceFiltersModal
|
||||||
|
@ -72,6 +77,7 @@ function VoiceFiltersModal({ modalProps, close, accept }: VoiceFiltersModalProps
|
||||||
<Button onClick={exportVoiceFilters} color={Button.Colors.TRANSPARENT}>Export</Button>
|
<Button onClick={exportVoiceFilters} color={Button.Colors.TRANSPARENT}>Export</Button>
|
||||||
<Button onClick={importVoiceFilters} color={Button.Colors.TRANSPARENT}>Import</Button>
|
<Button onClick={importVoiceFilters} color={Button.Colors.TRANSPARENT}>Import</Button>
|
||||||
<Button onClick={() => downloadVoicepack("https://fox3000foxy.com/voicepacks/agents.json")} color={Button.Colors.TRANSPARENT}>Download Default</Button>
|
<Button onClick={() => downloadVoicepack("https://fox3000foxy.com/voicepacks/agents.json")} color={Button.Colors.TRANSPARENT}>Download Default</Button>
|
||||||
|
<Button onClick={openModelFolder} color={Button.Colors.TRANSPARENT}>Open Model Folder</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Text>Voice filters list:</Text>
|
<Text>Voice filters list:</Text>
|
||||||
|
|
|
@ -1,89 +1,94 @@
|
||||||
/*
|
/*
|
||||||
* Vencord, a Discord client mod
|
* Vencord, a Discord client mod
|
||||||
* Copyright (c) 2025 Vendicated and contributors
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IpcMainInvokeEvent } from "electron";
|
import { IpcMainInvokeEvent } from "electron";
|
||||||
|
|
||||||
interface IVoiceFilter {
|
interface IVoiceFilter {
|
||||||
name: string;
|
name: string;
|
||||||
author: string;
|
author: string;
|
||||||
onnxFileUrl: string;
|
onnxFileUrl: string;
|
||||||
iconURL: string;
|
iconURL: string;
|
||||||
id: string;
|
id: string;
|
||||||
styleKey: string;
|
styleKey: string;
|
||||||
available: boolean;
|
available: boolean;
|
||||||
temporarilyAvailable: boolean;
|
temporarilyAvailable: boolean;
|
||||||
|
|
||||||
custom?: boolean;
|
custom?: boolean;
|
||||||
splashGradient?: string;
|
splashGradient?: string;
|
||||||
baseColor?: string;
|
baseColor?: string;
|
||||||
previewSoundURLs?: string[];
|
previewSoundURLs?: string[];
|
||||||
downloadUrl?: string;
|
downloadUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
export async function downloadCustomVoiceFilter(_: IpcMainInvokeEvent, modulePath: string, voiceFilter: IVoiceFilter): Promise<{ success: boolean, voiceFilter: IVoiceFilter, path: string | null, response: Response | null; }> {
|
export async function downloadCustomVoiceFilter(_: IpcMainInvokeEvent, modulePath: string, voiceFilter: IVoiceFilter): Promise<{ success: boolean, voiceFilter: IVoiceFilter, path: string | null, response: Response | null; }> {
|
||||||
if (!fs.existsSync(modulePath + "/discord_voice_filters")) {
|
if (!fs.existsSync(modulePath + "/discord_voice_filters")) {
|
||||||
fs.mkdirSync(modulePath + "/discord_voice_filters");
|
fs.mkdirSync(modulePath + "/discord_voice_filters");
|
||||||
}
|
}
|
||||||
if (!voiceFilter.onnxFileUrl ||
|
if (!voiceFilter.onnxFileUrl ||
|
||||||
fs.existsSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx") ||
|
fs.existsSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx") ||
|
||||||
!voiceFilter.onnxFileUrl.endsWith(".onnx")
|
!voiceFilter.onnxFileUrl.endsWith(".onnx")
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
response: null,
|
response: null,
|
||||||
voiceFilter: voiceFilter,
|
voiceFilter: voiceFilter,
|
||||||
path: null
|
path: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const response = await fetch(voiceFilter.onnxFileUrl);
|
const response = await fetch(voiceFilter.onnxFileUrl);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
response: response,
|
response: response,
|
||||||
voiceFilter: voiceFilter,
|
voiceFilter: voiceFilter,
|
||||||
path: null
|
path: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
const arrayBuffer = await response.arrayBuffer();
|
||||||
fs.writeFileSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx", Buffer.from(arrayBuffer));
|
fs.writeFileSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx", Buffer.from(arrayBuffer));
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
response: response,
|
response: response,
|
||||||
voiceFilter: voiceFilter,
|
voiceFilter: voiceFilter,
|
||||||
path: modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx"
|
path: modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadCustomVoiceFilterFromBuffer(_: IpcMainInvokeEvent, modulePath: string, voiceFilter: IVoiceFilter, buffer: ArrayBuffer) {
|
export async function downloadCustomVoiceFilterFromBuffer(_: IpcMainInvokeEvent, modulePath: string, voiceFilter: IVoiceFilter, buffer: ArrayBuffer) {
|
||||||
if (!fs.existsSync(modulePath + "/discord_voice_filters")) {
|
if (!fs.existsSync(modulePath + "/discord_voice_filters")) {
|
||||||
fs.mkdirSync(modulePath + "/discord_voice_filters");
|
fs.mkdirSync(modulePath + "/discord_voice_filters");
|
||||||
}
|
}
|
||||||
fs.writeFileSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx", Buffer.from(buffer));
|
fs.writeFileSync(modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx", Buffer.from(buffer));
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
voiceFilter: voiceFilter,
|
voiceFilter: voiceFilter,
|
||||||
path: modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx"
|
path: modulePath + "/discord_voice_filters/" + voiceFilter.id + ".onnx"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export async function getModelState(_: IpcMainInvokeEvent, id: string, modulePath: string) {
|
export async function getModelState(_: IpcMainInvokeEvent, id: string, modulePath: string) {
|
||||||
const modelPath = modulePath + "/discord_voice_filters/";
|
const modelPath = modulePath + "/discord_voice_filters/";
|
||||||
return {
|
return {
|
||||||
status: fs.existsSync(modelPath + id + ".onnx") ? "downloaded" : "not_downloaded",
|
status: fs.existsSync(modelPath + id + ".onnx") ? "downloaded" : "not_downloaded",
|
||||||
downloadedBytes: fs.existsSync(modelPath + id + ".onnx") ? fs.statSync(modelPath + id + ".onnx").size : 0
|
downloadedBytes: fs.existsSync(modelPath + id + ".onnx") ? fs.statSync(modelPath + id + ".onnx").size : 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteModel(_: IpcMainInvokeEvent, modulePath: string, id: string) {
|
export async function deleteModel(_: IpcMainInvokeEvent, modulePath: string, id: string) {
|
||||||
const modelPath = modulePath + "/discord_voice_filters/";
|
const modelPath = modulePath + "/discord_voice_filters/";
|
||||||
fs.unlinkSync(modelPath + id + ".onnx");
|
fs.unlinkSync(modelPath + id + ".onnx");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteAllModels(_: IpcMainInvokeEvent, modulePath: string) {
|
export async function deleteAllModels(_: IpcMainInvokeEvent, modulePath: string) {
|
||||||
const modelPath = modulePath + "/discord_voice_filters/";
|
const modelPath = modulePath + "/discord_voice_filters/";
|
||||||
fs.rmSync(modelPath, { recursive: true, force: true });
|
fs.rmSync(modelPath, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function openFolder(_: IpcMainInvokeEvent, modulePath: string) {
|
||||||
|
const process = require("child_process");
|
||||||
|
process.exec(`start "" "${modulePath}/discord_voice_filters/"`);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue