forked from lighttigerXIV/ulauncher-session-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (49 loc) · 2.55 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from asyncio import subprocess
from dataclasses import dataclass
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.ExtensionCustomAction import ExtensionCustomAction
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction
import subprocess
class Terminal_Runner(Extension):
def __init__(self):
super().__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
self.subscribe(ItemEnterEvent, ExecuteSession())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
options = []
for i in range(5):
data = { "option": i }
iconStyle = extension.preferences["icon"]
if iconStyle == "color": optionIcon = "images/icon.png"
if iconStyle == "black": optionIcon = "images/icon-black.png"
if iconStyle == "white": optionIcon = "images/icon-white.png"
if i == 0: optionName = "Suspender"
if i == 1: optionName = "Reiniciar"
if i == 2: optionName = "Hibernar"
if i == 3: optionName = "Apagar"
if i == 4: optionName = "Cerrar Sesión"
options.append(ExtensionResultItem(icon=optionIcon,
name=optionName,
on_enter=ExtensionCustomAction(data, keep_app_open=True)))
return RenderResultListAction(options)
class ExecuteSession(EventListener):
def on_event(self, event, extension):
data = event.get_data()
option = data["option"]
if option == 0: command = "systemctl suspend"
if option == 1: command = "systemctl reboot"
if option == 2: command = "systemctl hibernate"
if option == 3: command = "systemctl poweroff"
if option == 4:
desktopEnvironment = extension.preferences["desktop-environment"]
if(desktopEnvironment == "gnome"): command = "gnome-session-quit --no-prompt"
if(desktopEnvironment == "kde"): command = "qdbus org.kde.ksmserver /KSMServer logout 0 0 1"
subprocess.run( [command], shell=True )
return HideWindowAction()
if __name__ == '__main__':
Terminal_Runner().run()