@@ -5,12 +5,14 @@ module AGS.Service.Mpris
5
5
, disconnectMpris
6
6
, players
7
7
, matchPlayer
8
- , BusName
9
8
, Player
10
9
, PlayerProps
11
10
, PlayerSignals
11
+ , PlayerSignalsOverrides
12
+ , PlayerPosition (..)
12
13
, PlayerRecord
13
14
, PlayerRecordR
15
+ , BusName (..)
14
16
, MprisMetadata
15
17
, MprisMetadataF
16
18
, fromPlayer
@@ -28,10 +30,12 @@ import Prelude
28
30
import AGS.Binding (class BindProp , Binding )
29
31
import AGS.Service (class BindServiceProp , class ServiceConnect , Service )
30
32
import Data.Maybe (Maybe )
33
+ import Data.Newtype (class Newtype )
31
34
import Data.Nullable (Nullable , toMaybe )
32
35
import Data.Symbol (class IsSymbol , reflectSymbol )
36
+ import Data.Variant as V
33
37
import Effect (Effect )
34
- import Effect.Uncurried (EffectFn1 , EffectFn2 )
38
+ import Effect.Uncurried (EffectFn1 , EffectFn2 , mkEffectFn1 , mkEffectFn2 )
35
39
import GObject (class GObjectSignal , HandlerID , unsafeCopyGObjectProps )
36
40
import Record as R
37
41
import Record.Studio.MapKind (mapRecordKind )
@@ -83,35 +87,52 @@ foreign import matchPlayerImpl ∷ String → Effect (Nullable Player)
83
87
84
88
-- *** Player
85
89
90
+ foreign import data Player ∷ Type
91
+
86
92
newtype BusName = BusName String
87
93
94
+ derive instance Newtype BusName _
95
+ instance Show BusName where
96
+ show (BusName bn) = " (BusName " <> bn <> " )"
97
+
98
+ derive newtype instance Eq BusName
99
+
100
+ newtype PlayerPosition = PlayerPosition Number
101
+
102
+ derive instance Newtype PlayerPosition _
103
+
104
+ instance Show PlayerPosition where
105
+ show (PlayerPosition pos) = " (PlayerPosition " <> show pos <> " )"
106
+
107
+ derive newtype instance Eq PlayerPosition
108
+ derive newtype instance Ord PlayerPosition
109
+ derive newtype instance Semiring PlayerPosition
110
+
88
111
type PlayerRecord = Record PlayerRecordR
89
112
90
113
type PlayerRecordR =
91
- ( " bus-name" ∷ String
114
+ ( " bus-name" ∷ BusName
92
115
, " can-go-next" ∷ Boolean
93
116
, " can-go-prev" ∷ Boolean
94
117
, " can-play" ∷ Boolean
95
118
, " cover-path" ∷ Maybe String
96
119
, entry ∷ String
97
120
, identity ∷ String
98
- , length ∷ Int
121
+ , length ∷ Number
99
122
, " loop-status" ∷ Maybe Boolean
100
123
, metadata ∷ MprisMetadata
101
124
, name ∷ String
102
125
, " play-back-status" ∷ String
103
- , position ∷ Int
126
+ , position ∷ PlayerPosition
104
127
, " shuffle-status" ∷ Maybe Boolean
105
128
, " track-artists" ∷ Array String
106
129
, " track-cover-url" ∷ String
107
130
, " track-title" ∷ String
108
131
, " track-album" ∷ String
109
132
, trackid ∷ String
110
- , volume ∷ Int
133
+ , volume ∷ Number
111
134
)
112
135
113
- foreign import data Player ∷ Type
114
-
115
136
type MprisMetadata = MprisMetadataF Maybe
116
137
117
138
type MprisMetadataF f =
@@ -156,7 +177,7 @@ fromPlayer = unsafeCopyGObjectProps @PlayerRecordR
156
177
157
178
type PlayerProps =
158
179
-- the dbus name that starts with org.mpris.MediaPlayer2
159
- ( " bus-name" ∷ String
180
+ ( " bus-name" ∷ BusName
160
181
-- stripped from busName like spotify or firefox
161
182
, name ∷ String
162
183
-- name of the player like Spotify or Mozilla Firefox
@@ -189,11 +210,17 @@ instance BindProp Player PlayerProps
189
210
-- * Signals
190
211
191
212
type PlayerSignals =
192
- ( position ∷ EffectFn2 Player Number Unit
213
+ ( position ∷ Player → PlayerPosition → Effect Unit
214
+ , closed ∷ Player → Effect Unit
215
+ )
216
+
217
+ type PlayerSignalsOverrides =
218
+ ( position ∷ EffectFn2 Player PlayerPosition Unit
193
219
, closed ∷ EffectFn1 Player Unit
194
220
)
195
221
196
- instance GObjectSignal Player PlayerSignals
222
+ instance GObjectSignal Player PlayerSignals PlayerSignalsOverrides where
223
+ overrides = V .over { position: mkEffectFn2, closed: mkEffectFn1 }
197
224
198
225
-- * Methods
199
226
0 commit comments