Fix crash when sleeping/waking up device

This commit is contained in:
angelblue05 2016-07-22 17:10:35 -05:00
parent e97a3a616d
commit 793bd66554
4 changed files with 25 additions and 4 deletions

View File

@ -289,6 +289,7 @@ class DownloadUtils():
log("Unable to convert the response for: %s" % url, 1) log("Unable to convert the response for: %s" % url, 1)
else: # Bad status code else: # Bad status code
log("=== Bad status response: %s ===" % r.status_code, -1)
r.raise_for_status() r.raise_for_status()
##### EXCEPTIONS ##### ##### EXCEPTIONS #####

View File

@ -195,10 +195,15 @@ class KodiMonitor(xbmc.Monitor):
finally: finally:
embycursor.close()''' embycursor.close()'''
elif method == "System.OnSleep":
# Connection is going to sleep
log("Marking the server as offline. System.OnSleep activating.", 1)
window('emby_online', value="sleep")
elif method == "System.OnWake": elif method == "System.OnWake":
# Allow network to wake up # Allow network to wake up
xbmc.sleep(10000) xbmc.sleep(10000)
window('emby_online', value="false")
window('emby_onWake', value="true") window('emby_onWake', value="true")

View File

@ -23,7 +23,7 @@ class UserClient(threading.Thread):
# Borg - multiple instances, shared state # Borg - multiple instances, shared state
_shared_state = {} _shared_state = {}
stopClient = False stop_thread = False
auth = True auth = True
retry = 0 retry = 0
@ -430,7 +430,7 @@ class UserClient(threading.Thread):
self.auth = True self.auth = True
if self.stopClient == True: if self.stop_thread == True:
# If stopping the client didn't work # If stopping the client didn't work
break break
@ -443,4 +443,4 @@ class UserClient(threading.Thread):
def stopClient(self): def stopClient(self):
# When emby for kodi terminates # When emby for kodi terminates
self.stopClient = True self.stop_thread = True

View File

@ -231,7 +231,21 @@ class Service():
sound=False) sound=False)
self.server_online = False self.server_online = False
elif window('emby_online') == "sleep":
# device going to sleep
if self.websocket_running:
log("Stop websocket thread")
ws.stopClient()
ws = wsc.WebSocket_Client()
self.websocket_running = False
if self.library_running:
log("Stop library thread")
library.stopThread()
library = librarysync.LibrarySync()
self.library_running = False
else: else:
# Server is online # Server is online
if not self.server_online: if not self.server_online:
@ -254,6 +268,7 @@ class Service():
# Start the userclient thread # Start the userclient thread
if not self.userclient_running: if not self.userclient_running:
log("Start user thread")
self.userclient_running = True self.userclient_running = True
user.start() user.start()