some updates

This commit is contained in:
MoonDev
2025-05-23 01:55:25 +03:00
parent a775fe1c80
commit f1d8283224
18 changed files with 251 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ import comtypes
import ctypes
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from typing import Dict, Any
from winrt.windows.media.control import GlobalSystemMediaTransportControlsSessionManager as MediaManager
@@ -15,10 +16,25 @@ parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if parent_dir not in sys.path:
sys.path.append(parent_dir)
VOLUME = 0
async def get_volume(args: Dict[str, Any]) -> Dict[str, Any]:
global VOLUME
# Get default audio device
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
# Get current volume level (returns a float between 0.0 and 1.0)
current_volume = volume.GetMasterVolumeLevelScalar()
return {"value": round(current_volume*100)}
async def set_volume(args: Dict[str, Any]) -> Dict[str, Any]:
global VOLUME
"""
Sets the Windows system volume using the Core Audio API.
@@ -36,12 +52,13 @@ async def set_volume(args: Dict[str, Any]) -> Dict[str, Any]:
comtypes.CoInitialize()
# Get volume level from args
level = args.get('level', 0.5) # Default to 50% if not specified
level = args.get('level', 50) # Default to 50% if not specified
# Validate input level
if not isinstance(level, (int, float)) or not 0.0 <= level <= 1.0:
raise ValueError("Volume level must be a float between 0.0 and 1.0")
if not isinstance(level, (int, float)) or not 0 <= level <= 100:
raise ValueError("Volume level must be a float between 0 and 100")
VOLUME = level
level = level/100
# Get audio endpoint interface
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, comtypes.CLSCTX_ALL, None)
@@ -106,4 +123,16 @@ async def prev(args):
# назад
await current_session.try_skip_previous_async()
else:
print("No media session is active.")
print("No media session is active.")
async def play_pause(args):
# Получаем менеджер медиасессий
sessions = await MediaManager.request_async()
current_session = sessions.get_current_session()
if current_session:
await current_session.try_toggle_play_pause_async()
else:
print("No media session is active.")

View File

@@ -1,5 +1,7 @@
import monitorcontrol
BRIGHTNESS = 10
def get_monitors():
"""Retrieve a list of connected monitors."""
return monitorcontrol.get_monitors()
@@ -13,9 +15,16 @@ def set_brightness(monitor, brightness):
print(f"Set brightness to {brightness}%")
def chenge_brightness(args):
def get_brightness(args):
global BRIGHTNESS
return {"value":BRIGHTNESS}
def change_brightness(args):
global BRIGHTNESS
try:
level = args.get('level', 10)
BRIGHTNESS = level
monitors = get_monitors()
if not monitors:
raise OSError(f"No DDC/CI compatible monitors found.")

View File

@@ -62,7 +62,6 @@ class V2rayAController:
async with self.session.post(url, headers=headers, json=data) as response:
if response.status == 200:
print("Прокси успешно включен")
V2RAY_VPN_ENABLED = True
await show_notification({"title":"✅ V2Ray proxy","message":"Прокси успешно включен"})
return True
else:
@@ -75,7 +74,7 @@ class V2rayAController:
async def disable_proxy(self):
"""Выключение прокси"""
global V2RAY_VPN_ENABLED
if not self.token:
print("Не выполнен вход. Пожалуйста, сначала выполните аутентификацию")
return False
@@ -88,7 +87,6 @@ class V2rayAController:
async with self.session.delete(url, headers=headers, json=data) as response:
if response.status == 200:
print("Прокси успешно выключен")
V2RAY_VPN_ENABLED = False
await show_notification({"title":"🔴 V2Ray proxy","message":"Прокси успешно выключен"})
return True
else:
@@ -105,6 +103,7 @@ class V2rayAController:
await self.session.close()
async def enable_vpn(args):
global V2RAY_VPN_ENABLED
# Инициализация контроллера
config = await read_config("v2ray.yaml")
if config.get("username") and config.get("password"):
@@ -119,9 +118,11 @@ async def enable_vpn(args):
# Закрытие сессии
await controller.close()
V2RAY_VPN_ENABLED = True
else:
raise OSError("Config unset")
async def disable_vpn(args):
global V2RAY_VPN_ENABLED
# Инициализация контроллера
config = await read_config("v2ray.yaml")
if config.get("username") and config.get("password"):
@@ -136,6 +137,7 @@ async def disable_vpn(args):
# Закрытие сессии
await controller.close()
V2RAY_VPN_ENABLED = False
else:
raise OSError("Config unset")
@@ -143,5 +145,5 @@ async def disable_vpn(args):
async def is_vpn_enabled(args):
global V2RAY_VPN_ENABLED
return {
"vpn_enabled": V2RAY_VPN_ENABLED
"value": V2RAY_VPN_ENABLED
}