11from __future__ import annotations
22
3- from flogin import Query , Result , SearchHandler , ExecuteResponse , PlainTextCondition , MultiCondition
4- from flogin .jsonrpc .results import ResultConstructorArgs
5- from typing import Unpack
6- from ..plugin import ScreenBrightnessPlugin
73import re
4+ from typing import Unpack
5+
6+ import screen_brightness_control as sbc
7+ from flogin import (
8+ ExecuteResponse ,
9+ PlainTextCondition ,
10+ Query ,
11+ Result ,
12+ SearchHandler ,
13+ )
14+ from flogin .jsonrpc .results import ResultConstructorArgs
15+
816from ..conds import MultiAnyCondition
17+ from ..plugin import ScreenBrightnessPlugin
18+
919
1020class SetBrightnessResult (Result [ScreenBrightnessPlugin ]):
11- def __init__ (self , value : int , kw : str , ** kwargs : Unpack [ResultConstructorArgs ]):
21+ def __init__ (
22+ self ,
23+ value : int ,
24+ monitor : str | None ,
25+ kw : str ,
26+ ** kwargs : Unpack [ResultConstructorArgs ],
27+ ):
1228 super ().__init__ (** kwargs )
1329
1430 self .value = value
1531 self .kw = kw
32+ self .monitor = monitor
1633
1734 async def callback (self ):
1835 assert self .plugin
1936
20- self .plugin .set_brightness (self .value )
21- await self .plugin .api .show_notification ("ScreenBrightness" , f"Successfully set screen brightness to { self .value } %." )
37+ self .plugin .set_brightness (self .value , monitor = self .monitor )
38+ await self .plugin .api .show_notification (
39+ "ScreenBrightness" ,
40+ (
41+ f"Successfully set the brightness of your { self .monitor } display to { self .value } %."
42+ if self .monitor
43+ else f"Successfully set the brightness of all of your displays to { self .value } %."
44+ ),
45+ )
2246 await self .plugin .api .change_query (f"{ self .kw } " )
23-
47+
2448 return ExecuteResponse (False )
2549
50+
2651class SetBrightnessHandler (SearchHandler [ScreenBrightnessPlugin ]):
2752 def __init__ (self ):
2853 cond = MultiAnyCondition (* [PlainTextCondition (str (i + 1 )) for i in range (100 )])
@@ -33,5 +58,21 @@ async def callback(self, query: Query[re.Match]):
3358 assert self .plugin
3459
3560 value = int (query .text .strip ())
36-
37- return SetBrightnessResult (value , title = f"Set brightness to { value } %?" , icon = "assets/app.png" , kw = query .keyword )
61+
62+ yield SetBrightnessResult (
63+ value ,
64+ None ,
65+ title = f"Set brightness to { value } % for all of your displays?" ,
66+ icon = "assets/app.png" ,
67+ kw = query .keyword ,
68+ score = 10 ,
69+ )
70+
71+ for monitor in sbc .list_monitors ():
72+ yield SetBrightnessResult (
73+ value ,
74+ monitor ,
75+ title = f"Set brightness to { value } % for { monitor } ?" ,
76+ icon = "assets/app.png" ,
77+ kw = query .keyword ,
78+ )
0 commit comments