Skip to content

Commit

Permalink
Optimise wakeup to ensure http server is only started when required
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Dec 7, 2024
1 parent af02572 commit c2c6440
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 9 additions & 12 deletions resources/lib/youtube_plugin/kodion/monitors/service_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def onNotification(self, sender, method, data):
'GUI.OnDPMSDeactivated',
'System.OnWake',
}:
self.onWake()
self.system_idle = False
self.system_sleep = False
self.interrupt = True

elif method == 'Player.OnPlay':
player = xbmc.Player()
Expand All @@ -111,7 +113,10 @@ def onNotification(self, sender, method, data):
if playing_file.path in {PATHS.MPD,
PATHS.PLAY,
PATHS.REDIRECT}:
self.onWake()
if not self.httpd:
self.start_httpd()
if self.httpd_sleep_allowed:
self.httpd_sleep_allowed = None
except RuntimeError:
pass

Expand All @@ -131,6 +136,8 @@ def onNotification(self, sender, method, data):
target = data.get('target')

if target == PLUGIN_WAKEUP:
self.system_idle = False
self.system_sleep = False
self.interrupt = True
response = True

Expand Down Expand Up @@ -229,16 +236,6 @@ def onSettingsChanged(self, force=False):
elif httpd_started:
self.shutdown_httpd(terminate=True)

def onWake(self):
self.system_idle = False
self.system_sleep = False
self.interrupt = True

if not self.httpd and self.httpd_required():
self.start_httpd()
if self.httpd_sleep_allowed:
self.httpd_sleep_allowed = None

def httpd_address_sync(self):
self._old_httpd_address = self._httpd_address
self._old_httpd_port = self._httpd_port
Expand Down
4 changes: 3 additions & 1 deletion resources/lib/youtube_plugin/kodion/service_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def run():
and not monitor.system_sleep
and not (monitor.system_idle
or monitor.get_idle_time() >= loop_period)):
monitor.onWake()
monitor.system_idle = False
monitor.system_sleep = False
monitor.interrupt = True

if monitor.refresh and all(container.values()):
monitor.refresh_container(force=True)
Expand Down

0 comments on commit c2c6440

Please sign in to comment.