Фикс звуков из ресурсов
This commit is contained in:
@@ -14,7 +14,7 @@ export function useSound() {
|
|||||||
audioRef.current.load();
|
audioRef.current.load();
|
||||||
};
|
};
|
||||||
|
|
||||||
const playSound = (sound : string, loop: boolean = false) => {
|
const playSound = async (sound : string, loop: boolean = false) => {
|
||||||
try {
|
try {
|
||||||
if(loop){
|
if(loop){
|
||||||
if (!loopingAudioRef.current) {
|
if (!loopingAudioRef.current) {
|
||||||
@@ -24,7 +24,7 @@ export function useSound() {
|
|||||||
loopingAudioRef.current.loop = true;
|
loopingAudioRef.current.loop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = window.mediaApi.getSoundUrl(sound);
|
const url = await window.mediaApi.getSoundUrl(sound);
|
||||||
const player = loopingAudioRef.current;
|
const player = loopingAudioRef.current;
|
||||||
|
|
||||||
player.src = url;
|
player.src = url;
|
||||||
@@ -43,7 +43,7 @@ export function useSound() {
|
|||||||
audioRef.current.loop = loop;
|
audioRef.current.loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = window.mediaApi.getSoundUrl(sound);
|
const url = await window.mediaApi.getSoundUrl(sound);
|
||||||
const player = audioRef.current;
|
const player = audioRef.current;
|
||||||
|
|
||||||
stopSound();
|
stopSound();
|
||||||
|
|||||||
13
lib/main/ipcs/ipcRuntime.ts
Normal file
13
lib/main/ipcs/ipcRuntime.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { app, ipcMain } from "electron";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить директорию с ресурсами приложения
|
||||||
|
*/
|
||||||
|
ipcMain.handle('runtime:get-resources', () => {
|
||||||
|
const isDev = !app.isPackaged && process.env['ELECTRON_RENDERER_URL'];
|
||||||
|
if(isDev){
|
||||||
|
return path.join(process.cwd(), "resources")
|
||||||
|
}
|
||||||
|
return path.join(process.resourcesPath, "resources");
|
||||||
|
});
|
||||||
@@ -8,6 +8,7 @@ import './ipcs/ipcUpdate'
|
|||||||
import './ipcs/ipcNotification'
|
import './ipcs/ipcNotification'
|
||||||
import './ipcs/ipcDevice'
|
import './ipcs/ipcDevice'
|
||||||
import './ipcs/ipcCore'
|
import './ipcs/ipcCore'
|
||||||
|
import './ipcs/ipcRuntime'
|
||||||
import { Tray } from 'electron/main'
|
import { Tray } from 'electron/main'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { Logger } from './logger'
|
import { Logger } from './logger'
|
||||||
|
|||||||
2
lib/preload/index.d.ts
vendored
2
lib/preload/index.d.ts
vendored
@@ -14,7 +14,7 @@ declare global {
|
|||||||
deviceName: string;
|
deviceName: string;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
mediaApi: {
|
mediaApi: {
|
||||||
getSoundUrl: (fileName: string) => string;
|
getSoundUrl: (fileName: string) => Promise<string>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,9 @@ import path from 'node:path'
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
|
||||||
|
|
||||||
function resolveSound(fileName: string) {
|
async function resolveSound(fileName: string) {
|
||||||
const isDev = !process.env.APP_PACKAGED; // или свой флаг dev
|
const resourcesPath = await ipcRenderer.invoke('runtime:get-resources');
|
||||||
const fullPath = isDev
|
const fullPath = path.join(resourcesPath, "sounds", fileName);
|
||||||
? path.join(process.cwd(), "resources", "sounds", fileName)
|
|
||||||
: path.join(process.resourcesPath, "resources", "sounds", fileName);
|
|
||||||
|
|
||||||
if (!fs.existsSync(fullPath)) {
|
if (!fs.existsSync(fullPath)) {
|
||||||
throw new Error(`Sound not found: ${fullPath}`);
|
throw new Error(`Sound not found: ${fullPath}`);
|
||||||
}
|
}
|
||||||
@@ -32,7 +29,7 @@ const exposeContext = async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
contextBridge.exposeInMainWorld("mediaApi", {
|
contextBridge.exposeInMainWorld("mediaApi", {
|
||||||
getSoundUrl: (fileName: string) => {
|
getSoundUrl: async (fileName: string) => {
|
||||||
return resolveSound(fileName);
|
return resolveSound(fileName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -44,7 +41,7 @@ const exposeContext = async () => {
|
|||||||
window.api = api;
|
window.api = api;
|
||||||
window.shell = shell;
|
window.shell = shell;
|
||||||
window.mediaApi = {
|
window.mediaApi = {
|
||||||
getSoundUrl: (fileName: string) => {
|
getSoundUrl: async (fileName: string) => {
|
||||||
return resolveSound(fileName);
|
return resolveSound(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user