Use callback for FileSwitch (thanks Uriziel)

This commit is contained in:
Et0h 2015-09-27 22:43:25 +01:00
parent 7022865cd0
commit 2b555134d1
2 changed files with 3 additions and 8 deletions

View File

@ -53,7 +53,6 @@ SYNC_ON_PAUSE = True # Client seek to global position - subtitles may disappear
# Options for the File Switch feature: # Options for the File Switch feature:
FOLDER_SEARCH_TIMEOUT = 60.0 # Secs - How long to wait until searches in folder to update cache are aborted (may be longer than this if hard drive needs to spin up) FOLDER_SEARCH_TIMEOUT = 60.0 # Secs - How long to wait until searches in folder to update cache are aborted (may be longer than this if hard drive needs to spin up)
FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL = 120.0 # Secs - Frequency of updating cache when someone is playing a file not in current cache FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL = 120.0 # Secs - Frequency of updating cache when someone is playing a file not in current cache
MEDIA_CACHE_CHECK_INTERVAL = 0.2 # Secs - Frequency of checking for the cache being updated
#Usually there's no need to adjust these #Usually there's no need to adjust these
LAST_PAUSED_DIFF_THRESHOLD = 2 LAST_PAUSED_DIFF_THRESHOLD = 2

View File

@ -10,7 +10,7 @@ import re
import os import os
from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize, isURL from syncplay.utils import formatTime, sameFilename, sameFilesize, sameFileduration, RoomPasswordProvider, formatSize, isURL
from functools import wraps from functools import wraps
from twisted.internet import task from twisted.internet import task, threads
import threading import threading
lastCheckedForUpdates = None lastCheckedForUpdates = None
@ -89,8 +89,6 @@ class MainWindow(QtGui.QMainWindow):
def __init__(self): def __init__(self):
self.fileSwitchTimer = task.LoopingCall(self.updateInfo) self.fileSwitchTimer = task.LoopingCall(self.updateInfo)
self.fileSwitchTimer.start(constants.FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL, True) self.fileSwitchTimer.start(constants.FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL, True)
self.fileCheckTimer = task.LoopingCall(self.checkForUpdate)
self.fileCheckTimer.start(constants.MEDIA_CACHE_CHECK_INTERVAL, True)
mediaFilesCache = {} mediaFilesCache = {}
filenameWatchlist = [] filenameWatchlist = []
@ -123,7 +121,7 @@ class MainWindow(QtGui.QMainWindow):
MainWindow.FileSwitchManager.updateInfo() MainWindow.FileSwitchManager.updateInfo()
@staticmethod @staticmethod
def checkForUpdate(): def checkForUpdate(self=None):
if MainWindow.FileSwitchManager.newInfo: if MainWindow.FileSwitchManager.newInfo:
MainWindow.FileSwitchManager.newInfo = False MainWindow.FileSwitchManager.newInfo = False
MainWindow.FileSwitchManager.infoUpdated() MainWindow.FileSwitchManager.infoUpdated()
@ -131,9 +129,7 @@ class MainWindow(QtGui.QMainWindow):
@staticmethod @staticmethod
def updateInfo(): def updateInfo():
if len(MainWindow.FileSwitchManager.filenameWatchlist) > 0 or len(MainWindow.FileSwitchManager.mediaFilesCache) == 0 and MainWindow.FileSwitchManager.currentlyUpdating == False: if len(MainWindow.FileSwitchManager.filenameWatchlist) > 0 or len(MainWindow.FileSwitchManager.mediaFilesCache) == 0 and MainWindow.FileSwitchManager.currentlyUpdating == False:
newThread = threading.Thread(target=MainWindow.FileSwitchManager._updateInfoThread) threads.deferToThread(MainWindow.FileSwitchManager._updateInfoThread).addCallback(MainWindow.FileSwitchManager.checkForUpdate)
newThread.setDaemon(True)
newThread.start()
@staticmethod @staticmethod
def setFilenameWatchlist(unfoundFilenames): def setFilenameWatchlist(unfoundFilenames):