mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 05:44:16 +00:00
emit media_change event on startup to popuplate items
This commit is contained in:
parent
e39c1c0e13
commit
32f05a93a9
3 changed files with 18 additions and 6 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "volume.h"
|
||||
#include "power.h"
|
||||
#include "mouse.h"
|
||||
#include "media.h"
|
||||
|
||||
extern void forced_front_app_event();
|
||||
|
||||
|
@ -522,6 +523,7 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
|
|||
forced_brightness_event();
|
||||
forced_power_event();
|
||||
forced_front_app_event();
|
||||
forced_media_change_event();
|
||||
}
|
||||
|
||||
bool needs_refresh = false;
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
void initialize_media_events();
|
||||
void begin_receiving_media_events();
|
||||
void forced_media_change_event();
|
||||
|
|
21
src/media.m
21
src/media.m
|
@ -4,6 +4,7 @@
|
|||
extern void MRMediaRemoteRegisterForNowPlayingNotifications(dispatch_queue_t queue);
|
||||
extern void MRMediaRemoteGetNowPlayingInfo(dispatch_queue_t queue, void (^block)(NSDictionary* dict));
|
||||
extern void MRMediaRemoteGetNowPlayingApplicationIsPlaying(dispatch_queue_t queue, void (^block)(BOOL playing));
|
||||
extern void MRMediaRemoteGetNowPlayingApplicationDisplayName(int null, dispatch_queue_t queue, void (^block)(CFStringRef name));
|
||||
|
||||
extern NSString* kMRMediaRemoteNowPlayingApplicationIsPlayingDidChangeNotification;
|
||||
extern NSString* kMRMediaRemoteNowPlayingInfoDidChangeNotification;
|
||||
|
@ -95,14 +96,18 @@ bool g_media_events = false;
|
|||
|
||||
- (void)media_change:(NSNotification *)notification {
|
||||
if (!g_media_events) return;
|
||||
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(NSDictionary* dict) {
|
||||
MRMediaRemoteGetNowPlayingApplicationDisplayName(0, dispatch_get_main_queue(), ^(CFStringRef name) {
|
||||
@autoreleasepool {
|
||||
self.app = [notification.userInfo valueForKey:kMRMediaRemoteNowPlayingApplicationDisplayNameUserInfoKey];
|
||||
self.artist = [dict valueForKey:kMRMediaRemoteNowPlayingInfoArtist];
|
||||
self.title = [dict valueForKey:kMRMediaRemoteNowPlayingInfoTitle];
|
||||
self.album = [dict valueForKey:kMRMediaRemoteNowPlayingInfoAlbum];
|
||||
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(NSDictionary* dict) {
|
||||
@autoreleasepool {
|
||||
self.app = (NSString*)name;
|
||||
self.artist = [dict valueForKey:kMRMediaRemoteNowPlayingInfoArtist];
|
||||
self.title = [dict valueForKey:kMRMediaRemoteNowPlayingInfoTitle];
|
||||
self.album = [dict valueForKey:kMRMediaRemoteNowPlayingInfoAlbum];
|
||||
|
||||
[self update];
|
||||
[self update];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -119,3 +124,7 @@ void initialize_media_events() {
|
|||
void begin_receiving_media_events() {
|
||||
g_media_events = true;
|
||||
}
|
||||
|
||||
void forced_media_change_event() {
|
||||
[g_media_context playing_change:NULL];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue