Don't send dummy users to new console clients (#434)

This commit is contained in:
et0h 2021-11-07 15:47:57 +00:00
parent 37b93846db
commit 07499aaef4
6 changed files with 36 additions and 9 deletions

View File

@ -707,6 +707,7 @@ class SyncplayClient(object):
# Can change during runtime:
features["sharedPlaylists"] = self.sharedPlaylistIsEnabled() # Can change during runtime
features["chat"] = self.chatIsEnabled() # Can change during runtime
features["uiMode"] = self.ui.getUIMode()
# Static for this version/release of Syncplay:
features["featureList"] = True
@ -1595,6 +1596,9 @@ class UiManager(object):
self.lastAlertOSDEndTime = None
self.lastError = ""
def getUIMode(self):
return self.__ui.uiMode
def addFileToPlaylist(self, newPlaylistItem):
self.__ui.addFileToPlaylist(newPlaylistItem)

View File

@ -349,3 +349,8 @@ DEFAULT_TRUSTED_DOMAINS = ["youtube.com", "youtu.be"]
TRUSTABLE_WEB_PROTOCOLS = ["http", "https"]
PRIVATE_FILE_FIELDS = ["path"]
CONSOLE_UI_MODE = "CLI"
GRAPHICAL_UI_MODE = "GUI"
UNKNOWN_UI_MODE = "Unknown"
FALLBACK_ASSUMED_UI_MODE = GRAPHICAL_UI_MODE

View File

@ -11,7 +11,7 @@ from twisted.python.versions import Version
from zope.interface.declarations import implementer
import syncplay
from syncplay.constants import PING_MOVING_AVERAGE_WEIGHT, CONTROLLED_ROOMS_MIN_VERSION, USER_READY_MIN_VERSION, SHARED_PLAYLIST_MIN_VERSION, CHAT_MIN_VERSION
from syncplay.constants import PING_MOVING_AVERAGE_WEIGHT, CONTROLLED_ROOMS_MIN_VERSION, USER_READY_MIN_VERSION, SHARED_PLAYLIST_MIN_VERSION, CHAT_MIN_VERSION, UNKNOWN_UI_MODE
from syncplay.messages import getMessage
from syncplay.utils import meetsMinVersion
@ -143,7 +143,7 @@ class SyncClientProtocol(JSONCommandProtocol):
self._client.setServerVersion(version, featureList)
def persistentRoomWarning(self, serverFeatures):
return serverFeatures["persistentRooms"] if "persistentRooms" in serverFeatures else False
return serverFeatures["persistentRooms"] if "persistentRooms" in serverFeatures else False
def sendHello(self):
hello = {}
@ -449,6 +449,7 @@ class SyncServerProtocol(JSONCommandProtocol):
self._features["readiness"] = meetsMinVersion(self._version, USER_READY_MIN_VERSION)
self._features["managedRooms"] = meetsMinVersion(self._version, CONTROLLED_ROOMS_MIN_VERSION)
self._features["persistentRooms"] = False
self._features["uiMode"] = UNKNOWN_UI_MODE
return self._features
def isLogged(self):
@ -652,9 +653,10 @@ class SyncServerProtocol(JSONCommandProtocol):
dummyCount = 0
for watcher in watchers:
self._addUserOnList(userlist, watcher)
for emptyRoom in self._factory.getEmptyPersistentRooms():
dummyCount += 1
self._addDummyUserOnList(userlist, emptyRoom, dummyCount)
if self._watcher.isGUIUser(self.getFeatures()):
for emptyRoom in self._factory.getEmptyPersistentRooms():
dummyCount += 1
self._addDummyUserOnList(userlist, emptyRoom, dummyCount)
self.sendMessage({"List": userlist})
@requireLogged

View File

@ -150,7 +150,7 @@ class SyncFactory(Factory):
self._roomManager.broadcast(watcher, l)
self._roomManager.broadcastRoom(watcher, lambda w: w.sendSetReady(watcher.getName(), watcher.isReady(), False))
if self.roomsDbFile:
l = lambda w: w.sendList()
l = lambda w: w.sendList(toGUIOnly=True)
self._roomManager.broadcast(watcher, l)
def removeWatcher(self, watcher):
@ -158,7 +158,7 @@ class SyncFactory(Factory):
self.sendLeftMessage(watcher)
self._roomManager.removeWatcher(watcher)
if self.roomsDbFile:
l = lambda w: w.sendList()
l = lambda w: w.sendList(toGUIOnly=True)
self._roomManager.broadcast(watcher, l)
def sendLeftMessage(self, watcher):
@ -170,7 +170,7 @@ class SyncFactory(Factory):
self._roomManager.broadcast(watcher, l)
self._roomManager.broadcastRoom(watcher, lambda w: w.sendSetReady(watcher.getName(), watcher.isReady(), False))
if self.roomsDbFile:
l = lambda w: w.sendList()
l = lambda w: w.sendList(toGUIOnly=True)
self._roomManager.broadcast(watcher, l)
def sendFileUpdate(self, watcher):
@ -781,9 +781,23 @@ class Watcher(object):
if self._connector.meetsMinVersion(constants.CHAT_MIN_VERSION):
self._connector.sendMessage({"Chat": message})
def sendList(self):
def sendList(self, toGUIOnly=False):
if toGUIOnly and self.isGUIUser(self._connector.getFeatures()):
clientFeatures = self._connector.getFeatures()
if "uiMode" in clientFeatures:
if clientFeatures["uiMode"] == constants.CONSOLE_UI_MODE:
return
else:
return
self._connector.sendList()
def isGUIUser(self, clientFeatures):
clientFeatures = self._connector.getFeatures()
uiMode = clientFeatures["uiMode"] if "uiMode" in clientFeatures else constants.UNKNOWN_UI_MODE
if uiMode == constants.UNKNOWN_UI_MODE:
uiMode = constants.FALLBACK_ASSUMED_UI_MODE
return uiMode == constants.GRAPHICAL_UI_MODE
def sendSetReady(self, username, isReady, manuallyInitiated=True):
self._connector.sendSetReady(username, isReady, manuallyInitiated)

View File

@ -18,6 +18,7 @@ class ConsoleUI(threading.Thread):
self.PromptResult = ""
self.promptMode.set()
self._syncplayClient = None
self.uiMode = constants.CONSOLE_UI_MODE
threading.Thread.__init__(self, name="ConsoleUI")
def addClient(self, client):

View File

@ -2081,3 +2081,4 @@ class MainWindow(QtWidgets.QMainWindow):
self.show()
self.setAcceptDrops(True)
self.clearedPlaylistNote = False
self.uiMode = constants.GRAPHICAL_UI_MODE