VoiceMessages: Read file from dynamic path (fixes mac & linux support)
This commit is contained in:
parent
d18681c197
commit
fe5e041db8
@ -64,7 +64,7 @@ export default {
|
|||||||
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
|
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
|
||||||
},
|
},
|
||||||
VoiceMessages: {
|
VoiceMessages: {
|
||||||
readRecording: () => invoke<Uint8Array | null>(IpcEvents.VOICE_MESSAGES_READ_RECORDING),
|
readRecording: (path: string) => invoke<Uint8Array | null>(IpcEvents.VOICE_MESSAGES_READ_RECORDING, path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,7 @@ import { IpcEvents } from "@utils/IpcEvents";
|
|||||||
import { app, ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import { readFile } from "fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
import { request } from "https";
|
import { request } from "https";
|
||||||
import { join } from "path";
|
import { basename, normalize } from "path";
|
||||||
|
|
||||||
// #region OpenInApp
|
// #region OpenInApp
|
||||||
// These links don't support CORS, so this has to be native
|
// These links don't support CORS, so this has to be native
|
||||||
@ -49,10 +49,15 @@ ipcMain.handle(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, async (_, url: string) =
|
|||||||
|
|
||||||
|
|
||||||
// #region VoiceMessages
|
// #region VoiceMessages
|
||||||
ipcMain.handle(IpcEvents.VOICE_MESSAGES_READ_RECORDING, async () => {
|
ipcMain.handle(IpcEvents.VOICE_MESSAGES_READ_RECORDING, async (_, filePath: string) => {
|
||||||
const path = join(app.getPath("userData"), "module_data/discord_voice/recording.ogg");
|
filePath = normalize(filePath);
|
||||||
|
const filename = basename(filePath);
|
||||||
|
const discordBaseDirWithTrailingSlash = normalize(app.getPath("userData") + "/");
|
||||||
|
console.log(filename, discordBaseDirWithTrailingSlash, filePath);
|
||||||
|
if (filename !== "recording.ogg" || !filePath.startsWith(discordBaseDirWithTrailingSlash)) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const buf = await readFile(path);
|
const buf = await readFile(filePath);
|
||||||
return new Uint8Array(buf.buffer);
|
return new Uint8Array(buf.buffer);
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
|
@ -49,7 +49,7 @@ export const VoiceRecorderDesktop: VoiceRecorder = ({ setAudioBlob, onRecordingC
|
|||||||
} else {
|
} else {
|
||||||
discordVoice.stopLocalAudioRecording(async (filePath: string) => {
|
discordVoice.stopLocalAudioRecording(async (filePath: string) => {
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
const buf = await VencordNative.pluginHelpers.VoiceMessages.readRecording();
|
const buf = await VencordNative.pluginHelpers.VoiceMessages.readRecording(filePath);
|
||||||
if (buf)
|
if (buf)
|
||||||
setAudioBlob(new Blob([buf], { type: "audio/ogg; codecs=opus" }));
|
setAudioBlob(new Blob([buf], { type: "audio/ogg; codecs=opus" }));
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user