Add native notifications with OSD-style banners and a Control Center module
glassMxrph now owns org.freedesktop.Notifications. Banners drop out of the bar like the OSD; Control Center stacks history per app like macOS Notification Center. Do Not Disturb lives in the shell and falls back to SwayNC while another daemon holds the bus name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7f0498ba0
commit
395de70b26
17 files changed
+1132
-13
No files matched your search
@@ -25,6 +25,8 @@ assert.deepEqual(loaded.desktopWidgets.items,[]);
|
||||
assert.equal(loaded.lock.backdrop,'wallpaper');assert.equal(loaded.lock.pamService,'');assert.equal(api.update(loaded,'lock.pamService','hyprlock').lock.pamService,'hyprlock');
|
||||
for(const [k,v] of [['lock.backdrop','video'],['lock.pamService','../etc/shadow'],['lock.glass','yes']])assert.throws(()=>api.update(loaded,k,v),/lock screen/);assert.equal(api.update(loaded,'desktopWidgets.items',[widget,Object.assign({},widget,{id:'w-2',type:'future'})]).desktopWidgets.items.length,2);
|
||||
for(const bad of [[widget,widget],[Object.assign({},widget,{w:10})],[Object.assign({},widget,{opacity:2})],[Object.assign({},widget,{id:'Bad id'})],[Object.assign({},widget,{options:[]})]])assert.throws(()=>api.update(loaded,'desktopWidgets.items',bad),/desktop widget/);assert.equal(api.update(loaded, 'bar.workspaces.style', 'pacman').bar.workspaces.style, 'pacman');assert.throws(() => api.update(loaded, 'bar.workspaces.style', 'emoji'), /bar module options/);assert.throws(() => api.update(loaded, 'osd.position', 'left'), /OSD/);assert.throws(() => api.update(loaded, 'osd.timeout', 50), /OSD/);assert.throws(() => api.update(loaded, 'appearance.glassTint', 'grey'), /Glass tint/);
|
||||
assert.equal(loaded.notifications.enabled, true);assert.equal(loaded.notifications.doNotDisturb, false);assert.equal(api.update(loaded, 'notifications.doNotDisturb', true).notifications.doNotDisturb, true);
|
||||
for(const [k,v] of [['notifications.position','bottom-center'],['notifications.timeout',200],['notifications.maxPopups',0],['notifications.doNotDisturb','yes']])assert.throws(()=>api.update(loaded,k,v),/notification/);
|
||||
assert.throws(() => api.update(loaded, '__proto__.polluted', true));
|
||||
console.log('Configuration preservation, validation and update tests passed.');
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Real Wayland notification test on a private session bus (the user's daemon is untouched).
|
||||
Run inside one: dbus-run-session -- python3 tests/notifications_runtime.py [screenshot-dir]"""
|
||||
import json,os,subprocess,sys,tempfile,time
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
BASE=['quickshell','ipc','--path',str(ROOT/'quickshell'),'call']
|
||||
SHOTS=Path(sys.argv[1]) if len(sys.argv)>1 else None
|
||||
def ipc(target,method,*args):
|
||||
r=subprocess.run(BASE+[target,method,*map(str,args)],capture_output=True,text=True)
|
||||
out=r.stdout.strip()
|
||||
if r.returncode or not out:return None
|
||||
try:return json.loads(out)
|
||||
except ValueError:return out
|
||||
def status():return ipc('notifications','status') or {}
|
||||
def wait(check,label,timeout=15):
|
||||
end=time.monotonic()+timeout
|
||||
while time.monotonic()<end:
|
||||
try:
|
||||
if check():return
|
||||
except (TypeError,KeyError,ValueError):pass
|
||||
time.sleep(.08)
|
||||
raise AssertionError(label+': '+json.dumps(status()))
|
||||
def notify(*args):subprocess.run(['notify-send',*args],check=True,timeout=5)
|
||||
def shot(name):
|
||||
if SHOTS:
|
||||
time.sleep(.6);SHOTS.mkdir(parents=True,exist_ok=True)
|
||||
focused=next(m['name'] for m in json.loads(subprocess.check_output(['hyprctl','monitors','-j'],text=True)) if m['focused'])
|
||||
subprocess.run(['grim','-o',focused,str(SHOTS/(name+'.png'))],check=False)
|
||||
if 'DBUS_SESSION_BUS_ADDRESS' not in os.environ or ipc('shell','status'):raise SystemExit('Run in a private dbus-run-session with no instance from this path.')
|
||||
log=ROOT/'.cache/notifications-runtime.log';log.parent.mkdir(exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='glassmxrph-notifications-') as tmp:
|
||||
cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True)
|
||||
cfg.write_text(json.dumps({'schemaVersion':3,'dock':{'enabled':False},'notifications':{'timeout':4000}}))
|
||||
env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',XDG_STATE_HOME=tmp+'/state',XDG_CACHE_HOME=tmp+'/cache',QT_NO_XDG_DESKTOP_PORTAL='1')
|
||||
with log.open('w') as output:
|
||||
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT)
|
||||
try:
|
||||
wait(lambda:ipc('shell','status')['ready'],'ready')
|
||||
wait(lambda:status()['active'] and status()['owner']=='shell','shell owns the notification bus')
|
||||
notify('-a','Mail','-i','mail-unread','New message','Lunch at <b>noon</b>? The usual place.')
|
||||
wait(lambda:status()['count']==1 and status()['popups']==1,'banner shown')
|
||||
shot('1-banner')
|
||||
notify('-a','Chat','Ada','Did you see the build?')
|
||||
notify('-a','Chat','Grace','Ship it 🚀')
|
||||
notify('-a','Chat','Linus','One more thing…')
|
||||
notify('-u','critical','-a','Battery','Battery low','5% remaining')
|
||||
wait(lambda:status()['count']==5,'history keeps everything')
|
||||
wait(lambda:status()['popups']==3,'banner stack capped at maxPopups')
|
||||
shot('2-stack')
|
||||
# Non-critical banners time out into history; the critical one stays.
|
||||
wait(lambda:status()['popups']==1,'banners expire',timeout=10)
|
||||
assert status()['count']==5
|
||||
groups={g['app']:g['count'] for g in status()['groups']}
|
||||
assert groups=={'Mail':1,'Chat':3,'Battery':1},groups
|
||||
ipc('controlcenter','open')
|
||||
wait(lambda:ipc('controlcenter','status')['opened'],'control center opens')
|
||||
wait(lambda:status()['popups']==0,'opening Control Center clears banners')
|
||||
shot('3-controlcenter')
|
||||
ipc('controlcenter','close')
|
||||
assert ipc('notifications','setDnd','true')
|
||||
wait(lambda:status()['dnd'],'dnd on')
|
||||
notify('-a','Mail','Quiet','Should not pop up')
|
||||
wait(lambda:status()['count']==6,'dnd still records')
|
||||
time.sleep(.5);assert status()['popups']==0,'dnd suppresses banners'
|
||||
notify('-u','critical','-a','Alarm','Wake up','Critical breaks through')
|
||||
wait(lambda:status()['popups']==1,'critical alerts break through dnd')
|
||||
ipc('notifications','setDnd','false');ipc('notifications','dismiss')
|
||||
wait(lambda:status()['popups']==0 and status()['count']==7,'dismiss hides banners but keeps history')
|
||||
ipc('notifications','clear')
|
||||
wait(lambda:status()['count']==0,'clear empties history')
|
||||
wait(lambda:json.loads(cfg.read_text())['notifications']['doNotDisturb'] is False,'dnd persisted')
|
||||
print('Notification server, banners, stacking, expiry, DND, Control Center grouping and clearing passed.')
|
||||
finally:
|
||||
shell.terminate()
|
||||
try:shell.wait(5)
|
||||
except subprocess.TimeoutExpired:shell.kill()
|
||||
@@ -40,13 +40,24 @@ class Providers(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):system.action({'options':OPTIONS,'action':'power','value':'suspend'})
|
||||
run.assert_not_called()
|
||||
def test_dnd_never_activates_notification_daemon(self):
|
||||
with patch.object(system,'run',return_value='{"type":"b","data":[true]}') as run:
|
||||
self.assertTrue(system.notifications()['enabled'])
|
||||
with patch.object(system,'run',side_effect=['{"type":"u","data":[1]}','{"type":"b","data":[true]}']) as run:
|
||||
state=system.notifications()
|
||||
self.assertTrue(state['enabled']);self.assertEqual(state['provider'],'swaync')
|
||||
args=run.call_args.args[0]
|
||||
self.assertIn('--auto-start=no',args);self.assertEqual(args[-1],'GetDnd')
|
||||
with patch.object(system,'notifications',return_value={'available':True}),patch.object(system,'snapshot',return_value={}),patch.object(system,'run') as run:
|
||||
with patch.object(system,'notifications',return_value={'available':True,'provider':'swaync'}),patch.object(system,'snapshot',return_value={}),patch.object(system,'run') as run:
|
||||
system.action({'options':OPTIONS,'action':'dnd','value':False})
|
||||
self.assertIn('--auto-start=no',run.call_args.args[0]);self.assertEqual(run.call_args.args[0][-3:],['SetDnd','b','false'])
|
||||
def test_shell_owned_notifications_keep_dnd_in_the_shell(self):
|
||||
with patch.object(system,'run',return_value='{"type":"u","data":[%d]}'%system.os.getppid()) as run:
|
||||
self.assertEqual(system.notifications(),{'available':True,'provider':'shell'})
|
||||
self.assertEqual(run.call_count,1)
|
||||
with patch.object(system,'notifications',return_value={'available':True,'provider':'shell'}),patch.object(system,'run') as run:
|
||||
with self.assertRaises(ValueError):system.action({'options':OPTIONS,'action':'dnd','value':True})
|
||||
run.assert_not_called()
|
||||
def test_missing_notification_server_is_reported(self):
|
||||
with patch.object(system,'run',side_effect=ValueError('NameHasNoOwner')):
|
||||
self.assertFalse(system.notifications()['available'])
|
||||
def test_cli_errors_are_json(self):
|
||||
p=subprocess.run([sys.executable,str(ROOT/'quickshell/helpers/system.py'),'{"op":"unknown"}'],capture_output=True,text=True)
|
||||
self.assertFalse(json.loads(p.stdout)['ok']);self.assertEqual(p.returncode,1);self.assertEqual(p.stderr,'')
|
||||
|
||||
Reference in new issue
Block a user