Фикс звуков из ресурсов
This commit is contained in:
@@ -6,12 +6,9 @@ import path from 'node:path'
|
||||
import fs from "node:fs";
|
||||
|
||||
|
||||
function resolveSound(fileName: string) {
|
||||
const isDev = !process.env.APP_PACKAGED; // или свой флаг dev
|
||||
const fullPath = isDev
|
||||
? path.join(process.cwd(), "resources", "sounds", fileName)
|
||||
: path.join(process.resourcesPath, "resources", "sounds", fileName);
|
||||
|
||||
async function resolveSound(fileName: string) {
|
||||
const resourcesPath = await ipcRenderer.invoke('runtime:get-resources');
|
||||
const fullPath = path.join(resourcesPath, "sounds", fileName);
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
throw new Error(`Sound not found: ${fullPath}`);
|
||||
}
|
||||
@@ -32,7 +29,7 @@ const exposeContext = async () => {
|
||||
}
|
||||
});
|
||||
contextBridge.exposeInMainWorld("mediaApi", {
|
||||
getSoundUrl: (fileName: string) => {
|
||||
getSoundUrl: async (fileName: string) => {
|
||||
return resolveSound(fileName);
|
||||
}
|
||||
});
|
||||
@@ -44,7 +41,7 @@ const exposeContext = async () => {
|
||||
window.api = api;
|
||||
window.shell = shell;
|
||||
window.mediaApi = {
|
||||
getSoundUrl: (fileName: string) => {
|
||||
getSoundUrl: async (fileName: string) => {
|
||||
return resolveSound(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user