- Клиентская часть Vue 3 + Vite - Серверная часть Node.js + WebSocket - Система авторизации и смен - Управление игровыми портами - Поддержка тем (светлая/темная) - Адаптивный дизайн 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
115 lines
4.4 KiB
JavaScript
115 lines
4.4 KiB
JavaScript
// Windows Audio Mixer - управление громкостью конкретных приложений
|
|
const { spawn } = require('child_process');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
class WindowsAudioMixer {
|
|
constructor() {
|
|
this.processVolumes = new Map();
|
|
this.checkNircmd();
|
|
}
|
|
|
|
checkNircmd() {
|
|
// Проверяем наличие nircmd
|
|
this.nircmdPath = path.join(__dirname, 'tools', 'nircmd.exe');
|
|
if (!fs.existsSync(this.nircmdPath)) {
|
|
// Пробуем системный nircmd
|
|
this.nircmdPath = 'nircmd';
|
|
console.log('[AUDIO-MIXER] nircmd.exe не найден в tools/, используем системный');
|
|
} else {
|
|
console.log('[AUDIO-MIXER] Используем nircmd из:', this.nircmdPath);
|
|
}
|
|
}
|
|
|
|
// Установка громкости для конкретного процесса
|
|
setProcessVolume(processId, volume) {
|
|
if (!processId) return;
|
|
|
|
const volumeLevel = volume / 100;
|
|
console.log(`[AUDIO-MIXER] Устанавливаем громкость процесса ${processId}: ${volume}%`);
|
|
|
|
try {
|
|
// Используем nircmd для установки громкости процесса
|
|
spawn(this.nircmdPath, ['setappvolume', `/pid:${processId}`, volumeLevel.toString()], {
|
|
stdio: 'ignore',
|
|
windowsHide: true
|
|
});
|
|
|
|
this.processVolumes.set(processId, volume);
|
|
return true;
|
|
} catch (err) {
|
|
console.error('[AUDIO-MIXER] Ошибка установки громкости:', err.message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Альтернативный метод через PowerShell и Audio API
|
|
setProcessVolumePS(processName, volume) {
|
|
const script = `
|
|
Add-Type @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Collections.Generic;
|
|
|
|
public class AudioManager {
|
|
[DllImport("ole32.dll")]
|
|
public static extern int CoCreateInstance(ref Guid clsid, IntPtr inner, uint context, ref Guid iid, out IntPtr instance);
|
|
|
|
public static void SetApplicationVolume(int pid, float level) {
|
|
// Это упрощенная версия, полная реализация требует COM интерфейсов
|
|
// Используем nircmd как более надежный метод
|
|
}
|
|
}
|
|
"@
|
|
|
|
# Получаем процессы PowerShell для музыки
|
|
$processes = Get-Process | Where-Object { $_.ProcessName -eq 'powershell' -and $_.Id -ne $PID }
|
|
foreach ($proc in $processes) {
|
|
Write-Host "Found audio process: $($proc.Id)"
|
|
}`;
|
|
|
|
spawn('powershell', ['-Command', script], {
|
|
stdio: 'pipe',
|
|
windowsHide: true
|
|
});
|
|
}
|
|
|
|
// Приглушение всех аудио процессов
|
|
duckAudioProcesses(targetVolume = 20) {
|
|
console.log('[AUDIO-MIXER] Приглушаем все аудио процессы до', targetVolume + '%');
|
|
|
|
// Ищем все PowerShell процессы (наши аудио плееры)
|
|
const findScript = `Get-Process | Where-Object { $_.ProcessName -eq 'powershell' } | Select-Object -ExpandProperty Id`;
|
|
|
|
const proc = spawn('powershell', ['-Command', findScript], {
|
|
stdio: 'pipe',
|
|
windowsHide: true
|
|
});
|
|
|
|
let output = '';
|
|
proc.stdout.on('data', (data) => {
|
|
output += data.toString();
|
|
});
|
|
|
|
proc.on('close', () => {
|
|
const pids = output.trim().split('\n').filter(pid => pid && !isNaN(pid));
|
|
console.log('[AUDIO-MIXER] Найдено PowerShell процессов:', pids.length);
|
|
|
|
pids.forEach(pid => {
|
|
this.setProcessVolume(parseInt(pid), targetVolume);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Восстановление громкости
|
|
restoreAudioProcesses(targetVolume = 70) {
|
|
console.log('[AUDIO-MIXER] Восстанавливаем громкость до', targetVolume + '%');
|
|
|
|
// Восстанавливаем для всех сохраненных процессов
|
|
this.processVolumes.forEach((_, pid) => {
|
|
this.setProcessVolume(pid, targetVolume);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = WindowsAudioMixer; |