3434from tauon .t_modules .t_extra import filename_to_metadata , star_count2 # noqa: E402
3535
3636if TYPE_CHECKING :
37+ gi .require_version ("AyatanaAppIndicatorGlib" , "2.0" )
38+ from gi .repository import AyatanaAppIndicatorGlib
39+ gi .require_version ("AyatanaAppIndicator3" , "0.1" )
40+ from gi .repository import AyatanaAppIndicator3
41+ gi .require_version ("AppIndicator3" , "0.1" )
3742 from gi .repository import AppIndicator3
3843
3944 from tauon .t_modules .t_main import Tauon
@@ -48,6 +53,9 @@ def __init__(self, tauon: Tauon) -> None:
4853 self .update_tray_text = None
4954 self .tray_text = ""
5055 self .resume_playback = False
56+ self .indicator : AyatanaAppIndicatorGlib | AyatanaAppIndicator3 | AppIndicator3 = None
57+ self .loaded_indicator : str = ""
58+ self .menu : Gio .Menu | Gtk .Menu = None
5159
5260 tauon .set_tray_icons ()
5361
@@ -76,15 +84,24 @@ def hide_indicator(self) -> None:
7684
7785 def indicator_play (self ) -> None :
7886 if self .indicator_launched :
79- self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-play" ), "playing" )
87+ if self .loaded_indicator == "AyatanaAppIndicatorGlib" :
88+ self .indicator .set_icon (self .tauon .get_tray_icon ("tray-indicator-play" ), "playing" )
89+ else :
90+ self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-play" ), "playing" )
8091
8192 def indicator_pause (self ) -> None :
8293 if self .indicator_launched :
83- self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-pause" ), "paused" )
94+ if self .loaded_indicator == "AyatanaAppIndicatorGlib" :
95+ self .indicator .set_icon (self .tauon .get_tray_icon ("tray-indicator-pause" ), "paused" )
96+ else :
97+ self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-pause" ), "paused" )
8498
8599 def indicator_stop (self ) -> None :
86100 if self .indicator_launched :
87- self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-default" ), "default" )
101+ if self .loaded_indicator == "AyatanaAppIndicatorGlib" :
102+ self .indicator .set_icon (self .tauon .get_tray_icon ("tray-indicator-default" ), "default" )
103+ else :
104+ self .indicator .set_icon_full (self .tauon .get_tray_icon ("tray-indicator-default" ), "default" )
88105
89106 def start_indicator (self ) -> None :
90107 pctl = self .tauon .pctl
@@ -172,40 +189,57 @@ def update() -> None:
172189 self .indicator .set_title (tauon .t_title )
173190 self .tray_text = text
174191
175- item = Gtk .MenuItem (label = tauon .strings .menu_open_tauon )
176- item .connect ("activate" , restore )
177- item .show ()
178- self .menu .append (item )
192+ if self .loaded_indicator == "AyatanaAppIndicatorGlib" :
193+ pActions = Gio .SimpleActionGroup .new ()
194+ # self.menu.append(tauon.strings.menu_open_tauon, restore)
195+ pSimpleAction = Gio .SimpleAction .new ("showlabel" , None )
196+ pActions .add_action (pSimpleAction )
197+ pSimpleAction .connect ("activate" , restore , 6 )
198+ pItem = Gio .MenuItem .new (tauon .strings .menu_open_tauon , "indicator.showlabel" )
199+ self .menu .append_item (pItem )
200+
201+ # TODO(Martin): Separator
202+ # self.menu.append(tauon.strings.menu_play_pause, play_pause)
203+ # self.menu.append(tauon.strings.menu_next, next)
204+ # self.menu.append(tauon.strings.menu_previous, back)
205+ # TODO(Martin): Separator
206+ # self.menu.append(tauon.strings.menu_quit, menu_quit)
207+ self .indicator .set_actions (pActions )
208+ else :
209+ item = Gtk .MenuItem (label = tauon .strings .menu_open_tauon )
210+ item .connect ("activate" , restore )
211+ item .show ()
212+ self .menu .append (item )
179213
180- item = Gtk .SeparatorMenuItem ()
181- item .show ()
182- self .menu .append (item )
214+ item = Gtk .SeparatorMenuItem ()
215+ item .show ()
216+ self .menu .append (item )
183217
184- item = Gtk .MenuItem (label = tauon .strings .menu_play_pause )
185- item .connect ("activate" , play_pause )
186- item .show ()
187- self .menu .append (item )
218+ item = Gtk .MenuItem (label = tauon .strings .menu_play_pause )
219+ item .connect ("activate" , play_pause )
220+ item .show ()
221+ self .menu .append (item )
188222
189- item = Gtk .MenuItem (label = tauon .strings .menu_next )
190- item .connect ("activate" , next )
191- item .show ()
192- self .menu .append (item )
223+ item = Gtk .MenuItem (label = tauon .strings .menu_next )
224+ item .connect ("activate" , next )
225+ item .show ()
226+ self .menu .append (item )
193227
194- item = Gtk .MenuItem (label = tauon .strings .menu_previous )
195- item .connect ("activate" , back )
196- item .show ()
197- self .menu .append (item )
228+ item = Gtk .MenuItem (label = tauon .strings .menu_previous )
229+ item .connect ("activate" , back )
230+ item .show ()
231+ self .menu .append (item )
198232
199- item = Gtk .SeparatorMenuItem ()
200- item .show ()
201- self .menu .append (item )
233+ item = Gtk .SeparatorMenuItem ()
234+ item .show ()
235+ self .menu .append (item )
202236
203- item = Gtk .MenuItem (label = tauon .strings .menu_quit )
204- item .connect ("activate" , menu_quit )
205- item .show ()
206- self .menu .append (item )
237+ item = Gtk .MenuItem (label = tauon .strings .menu_quit )
238+ item .connect ("activate" , menu_quit )
239+ item .show ()
240+ self .menu .append (item )
207241
208- self .menu .show ()
242+ self .menu .show ()
209243
210244 self .indicator .set_menu (self .menu )
211245
@@ -220,7 +254,7 @@ def update() -> None:
220254 shoot .daemon = True
221255 shoot .start ()
222256
223- def scroll (self , indicator : AppIndicator3 .Indicator , steps : int , direction : int ) -> None :
257+ def scroll (self , indicator : AyatanaAppIndicatorGlib . Indicator | AppIndicator3 .Indicator , steps : int , direction : int ) -> None :
224258 if direction == Gdk .ScrollDirection .UP :
225259 self .tauon .pctl .player_volume += 4
226260 self .tauon .pctl .player_volume = min (self .tauon .pctl .player_volume , 100 )
@@ -619,7 +653,7 @@ def Seek(self, offset: int) -> None:
619653 pctl .seek_time (pctl .playing_time + (offset / 1000000 ))
620654
621655 @dbus .service .method (dbus_interface = "org.mpris.MediaPlayer2.Player" )
622- def SetPosition (self , id : int , position : str ) -> None :
656+ def SetPosition (self , id : int , position : int ) -> None :
623657 pctl .seek_time (position / 1000000 )
624658
625659 self .player_properties ["Position" ] = dbus .Int64 (int (position ))
0 commit comments