Событийные звуки звонка (сбросить, мутинг, и прочее...)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user