Skip to content

Commit

Permalink
Merge pull request #2 from cpinkl/master
Browse files Browse the repository at this point in the history
Load settings immediately after changing in GUI
  • Loading branch information
bluecube committed Mar 5, 2014
2 parents bde0f3d + dff8c4b commit a494d1b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions inhibit_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
import subprocess
import re

class MyMonitor( xbmc.Monitor ):
def __init__( self, *args, **kwargs ):
xbmc.Monitor.__init__( self )

def onSettingsChanged( self ):
load_settings()

def port_set(string):
ret = set()
for port in re.findall("[0-9]+", string):
Expand Down Expand Up @@ -48,20 +55,23 @@ def check_services():
log("No connection found.")
return False

def load_settings():
global watched_local,watched_remote,sleep_time
s = addon.getSetting
try:
sleep_time = int(float(s('sleep')) * 1000)
except ValueError:
sleep_time = 60 * 1000
watched_local = port_set(s('localports'))
watched_remote = port_set(s('remoteports'))
log("Watching for remote connections to ports {} and for local connections to ports {}, sleep time is {:0.2f} s.".format(
', '.join(str(x) for x in watched_remote),
', '.join(str(x) for x in watched_local),
sleep_time / 1000.0))

addon = xbmcaddon.Addon()
s = addon.getSetting
try:
sleep_time = int(float(s('sleep')) * 1000)
except ValueError:
sleep_time = 60 * 1000
watched_local = port_set(s('localports'))
watched_remote = port_set(s('remoteports'))

log("Watching for remote connections to ports {} and for local connections to ports {}, sleep time is {:0.2f} s.".format(
', '.join(str(x) for x in watched_remote),
', '.join(str(x) for x in watched_local),
sleep_time / 1000.0))
monitor = MyMonitor()
load_settings()

while not xbmc.abortRequested:
if check_services():
Expand Down

0 comments on commit a494d1b

Please sign in to comment.