-
Notifications
You must be signed in to change notification settings - Fork 9
/
service.py
86 lines (70 loc) · 2.42 KB
/
service.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
from lib.api.trakt.base_cache import setup_databases
import xbmc
from threading import Thread
from lib.utils.kodi_utils import (
get_kodi_version,
get_property,
set_property,
clear_property,
dialog_ok,
)
from time import time
from lib.api.jacktook.kodi import kodilog
from lib.utils.settings import update_action, update_delay
from lib.updater import updates_check_addon
first_run_update_prop = "jacktook.first_run_update"
pause_services_prop = "jacktook.pause_services"
class OnNotificationActions:
def run(self, sender, method, data):
if sender == "xbmc":
if method in ("GUI.OnScreensaverActivated", "System.OnSleep"):
set_property(pause_services_prop, "true")
elif method in ("GUI.OnScreensaverDeactivated", "System.OnWake"):
clear_property(pause_services_prop)
class CheckKodiVersion:
def run(self):
kodilog("Checking Kodi version")
if get_kodi_version() < 20:
dialog_ok(
"Jacktook",
"Kodi 20 or above required[CR]Please update Kodi to use addon",
)
class DatabaseSetup:
def run(self):
setup_databases()
class UpdateCheck:
def run(self):
kodilog("Update Check Service Started")
if get_property(first_run_update_prop) == "true":
return
end_pause = time() + update_delay()
monitor, player = xbmc.Monitor(), xbmc.Player()
wait_for_abort, is_playing = monitor.waitForAbort, player.isPlayingVideo
while not monitor.abortRequested():
while time() < end_pause:
wait_for_abort(1)
while get_property(pause_services_prop) == "true" or is_playing():
wait_for_abort(1)
updates_check_addon(update_action())
break
set_property(first_run_update_prop, "true")
try:
del monitor
except:
pass
try:
del player
except:
pass
kodilog("Update Check Service Finished")
class JacktookMOnitor(xbmc.Monitor):
def __init__(self):
xbmc.Monitor.__init__(self)
self.start()
def start(self):
CheckKodiVersion().run()
DatabaseSetup().run()
Thread(target=UpdateCheck().run).start()
def onNotification(self, sender, method, data):
OnNotificationActions().run(sender, method, data)
JacktookMOnitor().waitForAbort()