From e9a621dbaaf82cbf5e82f98888812d634999f735 Mon Sep 17 00:00:00 2001
From: Nydragon <contact@ccnlc.eu>
Date: Fri, 22 Nov 2024 17:11:54 +0100
Subject: [PATCH] chore: improve mpris music progress logic

---
 src/Dashboard.qml                |  4 ++--
 src/Nysh.qml                     |  5 ++---
 src/widgets/mpris/MprisSmall.qml | 14 +++-----------
 3 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/src/Dashboard.qml b/src/Dashboard.qml
index 132c834..1b08015 100644
--- a/src/Dashboard.qml
+++ b/src/Dashboard.qml
@@ -15,7 +15,7 @@ PanelWindow {
     id: homeWindow
 
     property bool animRunning: false
-    required property bool focused
+    property bool focused: false
     property bool focusLocked: false
 
     color: "transparent"
@@ -114,6 +114,7 @@ PanelWindow {
                             height: 100
                         }
 
+                        MprisSmall {}
                         GridLayout {
 
                             rows: 2
@@ -147,7 +148,6 @@ PanelWindow {
                                 height: 30
                             }
                         }
-                        MprisSmall {}
                     }
                 }
 
diff --git a/src/Nysh.qml b/src/Nysh.qml
index 02a1b2c..eca64a9 100644
--- a/src/Nysh.qml
+++ b/src/Nysh.qml
@@ -1,7 +1,6 @@
 import QtQuick
 import Quickshell
 import Quickshell.I3
-import "provider"
 
 Item {
     id: root
@@ -14,12 +13,12 @@ Item {
 
     Component.onCompleted: {
         I3.focusedMonitorChanged.connect(e => {
-            dash.focused = I3.monitorFor(root.screen).focused;
+            dash.focused = I3.monitorFor(root.screen)?.focused;
         });
     }
 
     property Dashboard dash: Dashboard {
         screen: root.screen
-        focused: I3.monitorFor(root.screen).focused
+        focused: I3.monitorFor(root.screen)?.focused ?? true
     }
 }
diff --git a/src/widgets/mpris/MprisSmall.qml b/src/widgets/mpris/MprisSmall.qml
index 8d4fa38..54f9434 100644
--- a/src/widgets/mpris/MprisSmall.qml
+++ b/src/widgets/mpris/MprisSmall.qml
@@ -129,18 +129,10 @@ BRectangle {
                         enabled: (card.player?.canSeek && card.player?.positionSupported) ?? false
 
                         onMoved: {
-                            if (card.player)
+                            if (card.player) {
                                 card.player.position = value;
-                        }
-
-                        Component.onCompleted: {
-                            const con = () => card.player?.positionChanged.connect(() => {
-                                    slider.value = card.player?.position;
-                                });
-                            con();
-                            Player.currentChanged.connect(() => {
-                                con();
-                            });
+                                value = card.player.position;
+                            }
                         }
 
                         FrameAnimation {