Skip to content

Commit fe5e041

Browse files
committed
VoiceMessages: Read file from dynamic path (fixes mac & linux support)
1 parent d18681c commit fe5e041

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/VencordNative.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default {
6464
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
6565
},
6666
VoiceMessages: {
67-
readRecording: () => invoke<Uint8Array | null>(IpcEvents.VOICE_MESSAGES_READ_RECORDING),
67+
readRecording: (path: string) => invoke<Uint8Array | null>(IpcEvents.VOICE_MESSAGES_READ_RECORDING, path),
6868
}
6969
}
7070
};

src/main/ipcPlugins.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IpcEvents } from "@utils/IpcEvents";
2020
import { app, ipcMain } from "electron";
2121
import { readFile } from "fs/promises";
2222
import { request } from "https";
23-
import { join } from "path";
23+
import { basename, normalize } from "path";
2424

2525
// #region OpenInApp
2626
// 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) =
4949

5050

5151
// #region VoiceMessages
52-
ipcMain.handle(IpcEvents.VOICE_MESSAGES_READ_RECORDING, async () => {
53-
const path = join(app.getPath("userData"), "module_data/discord_voice/recording.ogg");
52+
ipcMain.handle(IpcEvents.VOICE_MESSAGES_READ_RECORDING, async (_, filePath: string) => {
53+
filePath = normalize(filePath);
54+
const filename = basename(filePath);
55+
const discordBaseDirWithTrailingSlash = normalize(app.getPath("userData") + "/");
56+
console.log(filename, discordBaseDirWithTrailingSlash, filePath);
57+
if (filename !== "recording.ogg" || !filePath.startsWith(discordBaseDirWithTrailingSlash)) return null;
58+
5459
try {
55-
const buf = await readFile(path);
60+
const buf = await readFile(filePath);
5661
return new Uint8Array(buf.buffer);
5762
} catch {
5863
return null;

src/plugins/voiceMessages/DesktopRecorder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const VoiceRecorderDesktop: VoiceRecorder = ({ setAudioBlob, onRecordingC
4949
} else {
5050
discordVoice.stopLocalAudioRecording(async (filePath: string) => {
5151
if (filePath) {
52-
const buf = await VencordNative.pluginHelpers.VoiceMessages.readRecording();
52+
const buf = await VencordNative.pluginHelpers.VoiceMessages.readRecording(filePath);
5353
if (buf)
5454
setAudioBlob(new Blob([buf], { type: "audio/ogg; codecs=opus" }));
5555
else

0 commit comments

Comments
 (0)