-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppProvider.py
90 lines (76 loc) · 2.45 KB
/
AppProvider.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
82
83
84
85
86
87
88
89
90
import glob
import psutil
from Config import *
from ProcessNotifier import ProcessNotifier
from gi.repository import GdkX11
import Logger
UPDATE_APP_ENTRIES = False
APP_BLACK_LIST = []
if OS_NAME == "Linux":
APP_BLACK_LIST = [ "nautilus", "compiz" ]
class AppProvider:
apps = []
@staticmethod
def update():
AppProvider.getAppList(UPDATE_APP_ENTRIES)
ProcessNotifier.update()
@staticmethod
def getProcess(process_name):
for pid in psutil.pids():
try:
p = psutil.Process(pid)
if p.name() == process_name:
return p
except:
pass
return None
@staticmethod
def focusApp(process_name):
now = GdkX11.x11_get_server_time(Gdk.get_default_root_window())
return ProcessNotifier.getOpenProcsCached()[process_name].activate(now)
@staticmethod
def killApp(process_name):
p = AppProvider.getProcess(process_name)
if p:
p.terminate()
@staticmethod
def isAppRunning(process_name):
return ProcessNotifier.isRunning(process_name)
@staticmethod
def getAppList(force_update = False):
""" returns app_detail = (exec_path, icon_path)"""
if force_update:
AppProvider.apps = AppProvider.appDetails()
return AppProvider.apps
@staticmethod
def appDetails():
""" return the appropriate app details in format: (exec_path, icon_path)"""
if not APP_PATH_REGEX:
return []
if OS_NAME == "Linux":
return AppProvider.linuxAppDetails()
return []
@staticmethod
def linuxGetIcon(icon_name):
if os.path.isfile(icon_name):
return icon_name
icon_theme = Gtk.IconTheme.get_default()
icon = icon_theme.lookup_icon(icon_name, 48, 0)
if icon:
return icon.get_filename()
else:
Logger.log(icon_name + " not found")
return None
@staticmethod
def linuxAppDetails():
""" get linux desktop file details """
files = []
# probe .desktop files
for filename in glob.glob(APP_PATH_REGEX):
de = DesktopEntry(filename)
exec_path = de.getExec().split(" ")[0]
if exec_path in APP_BLACK_LIST:
continue
icon_path = AppProvider.linuxGetIcon(de.getIcon())
files.append((exec_path, icon_path))
return files