Add notifications

This commit is contained in:
PapaTutuWawa 2025-01-12 01:24:14 +01:00
parent 934c4183aa
commit b0d16ffd49
5 changed files with 61 additions and 2 deletions

View File

@ -145,6 +145,7 @@ class PlayerRpcObject(JsonRpcObject):
config: Config = I.get("Config")
scheme_configuration = config.players.get(url.scheme)
if scheme_configuration is None:
I.get("DataBridge").notification.emit(f"No player available for {url.scheme}")
self.logger.warn("Client requested unknown scheme: '%s'", url.scheme)
return {
"error": "invalid protocol"
@ -153,6 +154,7 @@ class PlayerRpcObject(JsonRpcObject):
if player_class_name is None:
player_class_name = scheme_configuration.get("*")
if player_class_name is None:
I.get("DataBridge").notification.emit(f"No player available for {url.netloc}")
self.logger.warn("No player was picked for url '%s'", url)
return {
"error": "invalid protocol"
@ -171,6 +173,7 @@ class PlayerRpcObject(JsonRpcObject):
program_cls = getattr(sys.modules[module_name], class_name, None)
if program_cls is None:
I.get("DataBridge").notification.emit("Could not start player")
self.logger.warn("Class %s not found in module %s", class_name, module_name)
return {
"error": "invalid protocol"

View File

@ -108,9 +108,12 @@ class MpvProgram(Program):
def _when_mpv_exit(self):
self.logger.info("MPV has exited")
self._process = None
I.get("DataBridge").set_loading(False)
if self._process.returncode != 0:
I.get("DataBridge").notification.emit("mpv exited with an error")
self._process = None
def pause(self):
self.__mpv_command(["set_property", "pause", True])

View File

@ -122,6 +122,7 @@ class VlcProgram(Program):
"--http-port=9090",
f"--http-password={self._vlc_password}",
"--quiet",
"--play-and-exit",
*extra_args,
final_url,
]
@ -130,10 +131,13 @@ class VlcProgram(Program):
def _when_vlc_exit(self):
self.logger.info("vlc has exited")
self._process = None
I.get("VlcConfig").run_event_listeners(EVENT_PLAYER_EXIT)
I.get("DataBridge").set_loading(False)
if self._process.returncode != 0:
I.get("DataBridge").notification.emit("VLC exited with an error")
self._process = None
def __vlc_command(self, command: str) -> str | None:
try:
req = requests.get(

View File

@ -20,6 +20,10 @@ Window {
function onIsLoading(loading) {
isLoading = loading
}
function onNotification(text) {
notificationModel.append({"message": text})
}
}
Image {
@ -67,4 +71,47 @@ Window {
anchors.rightMargin: 20
font.pixelSize: window.height * 0.1
}
ListModel {
id: notificationModel
}
Timer {
interval: 8 * 1000
running: notificationModel.count > 0
repeat: true
onTriggered: notificationModel.remove(0, 1)
}
Component {
id: notificationDelegate
Rectangle {
color: "#37474F"
width: 400
height: 100
radius: 10
Label {
text: message
color: "white"
font.pixelSize: 20
anchors.fill: parent
anchors.margins: 10
}
}
}
ListView {
anchors.right: wallpaperImage.right
anchors.top: wallpaperImage.top
anchors.topMargin: 20 * 2 + window.height * 0.1
anchors.rightMargin: 20
width: 400
height: window.height * 0.9 - 20 * 2
spacing: 50
model: notificationModel
delegate: notificationDelegate
}
}

View File

@ -8,6 +8,8 @@ class DataBridge(QObject):
# Indicates whether we're currently loading something or not
isLoading = Signal(bool, arguments=["loading"])
notification = Signal(str, arguments=["text"])
def __init__(self):
super().__init__()