Browse code
feat(notifications): add mini demo app
Edward Langley authored on 18/09/2022 11:12:15
Showing 1 changed files
Showing 1 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,68 @@ |
1 |
+(defpackage :objc.clog-dnc-player |
|
2 |
+ (:use :cl :clog) |
|
3 |
+ (:export )) |
|
4 |
+(in-package :objc.clog-dnc-player) |
|
5 |
+(named-readtables:in-readtable :objc-readtable) |
|
6 |
+ |
|
7 |
+(fw.lu:defclass+ store () |
|
8 |
+ ((%track-name |
|
9 |
+ :accessor track-name |
|
10 |
+ :initform nil) |
|
11 |
+ (%track-artist |
|
12 |
+ :accessor track-artist |
|
13 |
+ :initform nil) |
|
14 |
+ (%track-album |
|
15 |
+ :accessor track-album |
|
16 |
+ :initform nil) |
|
17 |
+ (%player-state |
|
18 |
+ :accessor player-state |
|
19 |
+ :initform nil))) |
|
20 |
+(defvar *store*) |
|
21 |
+ |
|
22 |
+(defun incorporate (store info) |
|
23 |
+ (prog1 store |
|
24 |
+ (trivia:match info |
|
25 |
+ ((trivia:hash-table-entries |
|
26 |
+ "Name" name |
|
27 |
+ "Album" album |
|
28 |
+ "Artist" artist |
|
29 |
+ "Player State" player-state) |
|
30 |
+ (setf |
|
31 |
+ (track-name store) name |
|
32 |
+ (track-album store) album |
|
33 |
+ (track-artist store) artist |
|
34 |
+ (player-state store) player-state))))) |
|
35 |
+ |
|
36 |
+(defun reducer-task (store) |
|
37 |
+ (lambda () |
|
38 |
+ (loop |
|
39 |
+ for message = (sb-concurrency:receive-message |
|
40 |
+ objc.notification:*mailbox*) |
|
41 |
+ do (incorporate *store* message)))) |
|
42 |
+ |
|
43 |
+(defun on-new-window (body) |
|
44 |
+ (let ((name (create-section body :h2 :content "track")) |
|
45 |
+ (artist (create-div body :content "artist")) |
|
46 |
+ (album (create-div body :content "album")) |
|
47 |
+ (player-state (create-div body :content "player-state")) |
|
48 |
+ (play-pause (create-button body :content "play/pause"))) |
|
49 |
+ (link-slot-to-element *store* track-name name) |
|
50 |
+ (link-slot-to-element *store* track-artist artist) |
|
51 |
+ (link-slot-to-element *store* track-album album) |
|
52 |
+ (link-slot-to-element *store* player-state player-state) |
|
53 |
+ (set-on-click play-pause |
|
54 |
+ (lambda (button) |
|
55 |
+ (declare (ignore button)) |
|
56 |
+ [(objc.scripting-bridge::itunes-app) @(playpause)]?)))) |
|
57 |
+ |
|
58 |
+(defvar *initialized* nil) |
|
59 |
+(defun doit () |
|
60 |
+ (unless *initialized* |
|
61 |
+ (setf *initialized* t) |
|
62 |
+ (setf *store* (make-instance 'store)) |
|
63 |
+ (bt:make-thread (reducer-task *store*) :name "Reducer") |
|
64 |
+ (objc.notification:setup-notifications) |
|
65 |
+ (objc.notification:observe-notifications (objc.notification:dnc) |
|
66 |
+ "com.apple.Music.playerInfo") |
|
67 |
+ (bt:make-thread 'objc.notification:main-loop-ticker) |
|
68 |
+ (set-on-new-window 'on-new-window :path "/player"))) |