added adaptive quickshell

This commit is contained in:
wt committed 2026-11-17 18:15:16 +07:00
1 parent 6eb56d2065
commit 5b33a73fd8
189 files changed
+8678 -15

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""Strict JSON interface to powerprofilesctl, without shell execution."""
import json
import shutil
import subprocess
import sys
PROFILES = ('power-saver', 'balanced', 'performance')
def execute(argv, runner=subprocess.run, which=shutil.which):
if not which('powerprofilesctl'):
return {'ok': False, 'error': 'powerprofilesctl не установлен'}
if len(argv) == 1 and argv[0] == 'get':
args = ['powerprofilesctl', 'get']
elif len(argv) == 2 and argv[0] == 'set' and argv[1] in PROFILES:
args = ['powerprofilesctl', 'set', argv[1]]
else:
return {'ok': False, 'error': 'Недопустимая команда или профиль'}
try:
result = runner(args, capture_output=True, text=True, timeout=12, check=False)
except (OSError, subprocess.TimeoutExpired) as exc:
return {'ok': False, 'error': str(exc)[:300]}
if result.returncode:
return {'ok': False, 'error': (result.stderr or result.stdout or 'Команда завершилась с ошибкой').strip()[:300]}
if argv[0] == 'get':
profile = result.stdout.strip()
if profile not in PROFILES:
return {'ok': False, 'error': 'Неизвестный профиль: ' + profile[:100]}
return {'ok': True, 'profile': profile}
return {'ok': True, 'profile': argv[1]}
if __name__ == '__main__':
response = execute(sys.argv[1:])
print(json.dumps(response, ensure_ascii=False))
sys.exit(0 if response['ok'] else 1)