Событийные звуки звонка (сбросить, мутинг, и прочее...)

This commit is contained in:
RoyceDa
2026-03-18 18:27:39 +02:00
parent 7b9936dcc4
commit 88288317ab
10 changed files with 153 additions and 40 deletions

View File

@@ -1,8 +1,23 @@
import { contextBridge, ipcRenderer, shell } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import api from './api'
import { pathToFileURL } from 'node:url'
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);
if (!fs.existsSync(fullPath)) {
throw new Error(`Sound not found: ${fullPath}`);
}
return pathToFileURL(fullPath).toString();
}
const exposeContext = async () => {
if (process.contextIsolated) {
try {
@@ -16,6 +31,11 @@ const exposeContext = async () => {
ipcRenderer.invoke('ipcCore:showItemInFolder', fullPath);
}
});
contextBridge.exposeInMainWorld("mediaApi", {
getSoundUrl: (fileName: string) => {
return resolveSound(fileName);
}
});
} catch (error) {
console.error(error)
}
@@ -23,6 +43,11 @@ const exposeContext = async () => {
window.electron = electronAPI
window.api = api;
window.shell = shell;
window.mediaApi = {
getSoundUrl: (fileName: string) => {
return resolveSound(fileName);
}
}
}
}