4747RPC .activity = {
4848 details = ' No file' ,
4949 state = nil ,
50- timestamps = {},
50+ timestamps = nil ,
51+ buttons = nil ,
5152 assets = {
5253 large_image = ' mpv' ,
5354 large_text = MPV ,
@@ -56,6 +57,11 @@ RPC.activity = {
5657 }
5758}
5859
60+ function RPC .get_time ()
61+ local pos = mp .get_property_number (' time-pos' , 0 )
62+ return math.floor (os.time () - pos )
63+ end
64+
5965function RPC .pack (op , body )
6066 local bytes = {}
6167 assert (body , ' empty body' )
@@ -168,7 +174,7 @@ function RPC:set_activity()
168174 local body = utils .format_json {
169175 cmd = ' SET_ACTIVITY' , nonce = nonce ,
170176 args = {activity = self .activity , pid = self .pid }
171- }: gsub ( ' %[] ' , ' {} ' )
177+ }
172178 self :send (OP .FRAME , body )
173179 local res = self :recv (8 )
174180 if not res then
@@ -202,7 +208,8 @@ mp.register_event('idle-active', function()
202208 RPC .activity = {
203209 details = ' No file' ,
204210 state = nil ,
205- timestamps = {},
211+ buttons = nil ,
212+ timestamps = nil ,
206213 assets = {
207214 small_image = ' stop' ,
208215 small_text = ' Idle' ,
@@ -243,77 +250,69 @@ mp.register_event('file-loaded', function()
243250 else
244251 RPC .activity .assets .large_image = ' stream'
245252 end
246- RPC .activity .assets .large_text = path
253+ RPC .activity .buttons = {
254+ {label = ' Open URL' , url = path }
255+ }
247256 else
257+ RPC .activity .buttons = nil
248258 RPC .activity .assets .large_image = ' mpv'
249- RPC .activity .assets .large_text = MPV
250259 end
251260 RPC .activity .details = title
252261 RPC .activity .state = time .. plist
253262 RPC .activity .assets .small_image = ' pause'
254263 RPC .activity .assets .small_text = ' Paused'
255- RPC .activity .timestamps = {}
264+ RPC .activity .timestamps = nil
256265end )
257266
258267mp .register_event (' shutdown' , function ()
259268 RPC :disconnect ()
260269end )
261270
262271mp .register_event (' seek' , function ()
263- local pos = mp .get_property_number (' time-pos' )
264- RPC .activity .timestamps = {
265- start = math.floor (os.time () - (pos or 0 ))
266- }
272+ if not mp .get_property_bool (' pause' ) then
273+ RPC .activity .timestamps = {start = RPC .get_time ()}
274+ end
267275end )
268276
269277mp .observe_property (' paused-for-cache' , ' bool' , function (_ , value )
270278 if value then
271- RPC .activity .timestamps = {}
279+ RPC .activity .timestamps = nil
272280 RPC .activity .assets .small_image = ' play'
273281 RPC .activity .assets .small_text = ' Playing'
274282 else
275- local pos = mp .get_property_number (' time-pos' )
276- RPC .activity .timestamps = {
277- start = math.floor (os.time () - (pos or 0 ))
278- }
283+ RPC .activity .timestamps = {start = RPC .get_time ()}
279284 RPC .activity .assets .small_image = ' play'
280285 RPC .activity .assets .small_text = ' Playing'
281286 end
282287end )
283288
284289mp .observe_property (' core-idle' , ' bool' , function (_ , value )
285290 if value then
286- RPC .activity .timestamps = {}
291+ RPC .activity .timestamps = nil
287292 RPC .activity .assets .small_image = ' pause'
288293 RPC .activity .assets .small_text = ' Loading'
289294 else
290- local pos = mp .get_property_number (' time-pos' )
291- RPC .activity .timestamps = {
292- start = math.floor (os.time () - (pos or 0 ))
293- }
295+ RPC .activity .timestamps = {start = RPC .get_time ()}
294296 RPC .activity .assets .small_image = ' play'
295297 RPC .activity .assets .small_text = ' Playing'
296298 end
297299end )
298300
299301mp .observe_property (' pause' , ' bool' , function (_ , value )
300302 if value then
301- RPC .activity .timestamps = {}
303+ RPC .activity .timestamps = nil
302304 RPC .activity .assets .small_image = ' pause'
303305 RPC .activity .assets .small_text = ' Paused'
304306 else
305- local pos = mp .get_property_number (' time-pos' )
306- RPC .activity .timestamps = {
307- start = math.floor (os.time () - (pos or 0 ))
308- }
307+ RPC .activity .timestamps = {start = RPC .get_time ()}
309308 RPC .activity .assets .small_image = ' play'
310309 RPC .activity .assets .small_text = ' Playing'
311310 end
312311end )
313312
314313mp .observe_property (' eof-reached' , ' bool' , function (_ , value )
315314 if value then
316- RPC .activity .timestamps = {}
315+ RPC .activity .timestamps = nil
317316 RPC .activity .assets .small_image = ' stop'
318317 RPC .activity .assets .small_text = ' Idle'
319318 end
0 commit comments