#!/usr/bin/env python3 """Read-only live metrics integration with isolated preferences; no hardware writes.""" import json import os from pathlib import Path import subprocess import tempfile import time ROOT=Path(__file__).resolve().parents[1] SHELL=ROOT/'quickshell' def ipc(target,method,*args): p=subprocess.run(['quickshell','ipc','--path',str(SHELL),'call',target,method,*args],capture_output=True,text=True,timeout=5) if p.returncode:return None try:return json.loads(p.stdout) except ValueError:return p.stdout.strip() def wait(check,timeout=15): end=time.monotonic()+timeout while time.monotonic()=2) assert ipc('metricsTest','screenshot',str(ROOT/'.cache/metrics-preview.png')) is True wait(lambda:(ROOT/'.cache/metrics-preview.png').exists()) s=state();assert not s['error'] and not s['stale'],s assert 0<=s['snapshot']['cpu']['percent']<=100,s assert s['snapshot']['ram']['total']>0,s ipc('shell','close') wait(lambda:state().get('consumers')==0 and not state().get('running')) before=state()['samples'];time.sleep(2.2);assert state()['samples']==before monitors=json.loads(subprocess.check_output(['hyprctl','-j','monitors'])) pref('bar.modules',[{'id':k,'enabled':True,'position':'right'} for k in ['cpu','gpu','ram','storage','cpuTemperature','gpuTemperature','networkThroughput']]) wait(lambda:state().get('consumers')==7*len(monitors) and state().get('samples',0)>before) pref('bar.modules',[]) ipc('shell','openSettings','metrics') wait(lambda:state().get('consumers')==1) pref('metrics.interval',1) pref('metrics.storagePaths',['/','/missing-glassmxrph-test']) wait(lambda:len(state().get('snapshot',{}).get('storage',[]))==2) assert not state()['snapshot']['storage'][1]['available'] pref('metrics.networkInterface','missing-glassmxrph-test') wait(lambda:state().get('snapshot',{}).get('network',{}).get('selected')==['missing-glassmxrph-test']) assert state()['snapshot']['network']['download'] is None pref('controlCenter.modules',[{'id':'metrics','enabled':True}]) ipc('controlcenter','open') wait(lambda:state().get('consumers')==1) ipc('controlcenter','close') wait(lambda:state().get('consumers')==0 and not state().get('running')) # Desktop widgets sample only while their desktop is uncovered: no # tiled or fullscreen window on the monitor's active workspace. clients=json.loads(subprocess.check_output(['hyprctl','-j','clients'])) active={m['activeWorkspace']['id'] for m in monitors} covered={c['monitor'] for c in clients if c['workspace']['id'] in active and (not c['floating'] or c['fullscreen'])} widget=lambda m:{'version':1,'grid':False,'items':[{'id':'cpu-1','type':'cpu','variant':'','monitor':m['name'],'x':40,'y':40,'w':180,'h':130,'opacity':1}]} hidden=[m for m in monitors if m['id'] in covered] shown=[m for m in monitors if m['id'] not in covered] if hidden: pref('desktopWidgets',widget(hidden[0])) time.sleep(3) assert state().get('consumers')==0 and not state().get('running'),state() if shown: pref('desktopWidgets',widget(shown[0])) wait(lambda:state().get('consumers')>=1 and state().get('running')) config=Path(tmp)/'config/glassMxrph/config.json' wait(lambda:config.exists() and json.loads(config.read_text())['metrics']['interval']==1) finally: p.terminate();p.wait(timeout=8) (ROOT/'.cache/phase8-runtime.log').write_text(log.read_text()) text=log.read_text() assert 'WARN' not in text and 'ERROR' not in text,text print('PASS: live counters, shared bar/settings/Control Center consumers, idle shutdown/restart, source changes, unavailable sources, persistence and clean QML/DBus logs.')