Skip to content

Commit fd46bae

Browse files
committed
Added Swinsian app adapter (#16)
1 parent eedfeef commit fd46bae

File tree

8 files changed

+489
-3
lines changed

8 files changed

+489
-3
lines changed

BeardedSpice/Beardie-Prefix.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323

2424
#pragma mark - Other
2525

26+
#define ERROR_TRACE DDLogError(@"Error trace - %s[%p]: %@", __FILE__, self, NSStringFromSelector(_cmd));

BeardedSpice/NativeApps/NativeAppTabsRegistry.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "BSTVTabAdapter.h"
2222
#import "AmazonMusicTabAdapter.h"
2323
#import "QuodLibetTabAdapter.h"
24+
#import "BSSwinsianTabAdapter.h"
2425

2526
NSString *BSNativeAppTabsRegistryChangedNotification = @"BSNativeAppTabsRegistryChangedNotification";
2627

@@ -102,7 +103,8 @@ + (NSArray *)defaultNativeAppClasses {
102103
[BSTVTabAdapter class],
103104
[AmazonMusicTabAdapter class],
104105
[QuodLibetTabAdapter class],
105-
[TidalTabAdapter class]
106+
[TidalTabAdapter class],
107+
[BSSwinsianTabAdapter class]
106108
];
107109
}
108110

BeardedSpice/NativeApps/Tabs/BSMusicTabAdapter.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#import "BSTrack.h"
1313
#import "NSString+Utils.h"
1414

15-
#define ERROR_TRACE DDLogError(@"Error trace - %s[%p]: %@", __FILE__, self, NSStringFromSelector(_cmd));
16-
1715
#define APPID @"com.apple.Music"
1816
#define APPNAME @"Music"
1917

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// BSSwinsianTabAdapter.h
3+
// Beardie
4+
//
5+
// Created by Roman Sokolov on 06.06.2021.
6+
// Copyright © 2021 GPL v3 http://www.gnu.org/licenses/gpl.html
7+
//
8+
9+
#import "BSNativeAppTabAdapter.h"
10+
#import "Swinsian.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface BSSwinsianTabAdapter : BSNativeAppTabAdapter
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
//
2+
// BSSwinsianTabAdapter.m
3+
// Beardie
4+
//
5+
// Created by Roman Sokolov on 06.06.2021.
6+
// Copyright © 2021 GPL v3 http://www.gnu.org/licenses/gpl.html
7+
//
8+
9+
#import "BSSwinsianTabAdapter.h"
10+
#import "runningSBApplication.h"
11+
#import "BSMediaStrategy.h"
12+
#import "BSTrack.h"
13+
#import "NSString+Utils.h"
14+
15+
#define APPID @"com.swinsian.Swinsian"
16+
#define APPNAME @"Swinsian"
17+
18+
@implementation BSSwinsianTabAdapter
19+
20+
+ (NSString *)displayName {
21+
static NSString *name;
22+
static dispatch_once_t onceToken;
23+
dispatch_once(&onceToken, ^{
24+
name = [super displayName];
25+
});
26+
return name ?: APPNAME;
27+
}
28+
29+
+ (NSString *)bundleId{
30+
return APPID;
31+
}
32+
33+
- (NSString *)title{
34+
35+
@autoreleasepool {
36+
37+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
38+
SwinsianTrack *currentTrack = [music currentTrack];
39+
40+
NSString *title;
41+
if (currentTrack) {
42+
43+
if (currentTrack.name.length){
44+
title = currentTrack.name;
45+
}
46+
47+
if (currentTrack.artist.length) {
48+
49+
if (title) title = [title stringByAppendingFormat:@" - %@", currentTrack.artist];
50+
else
51+
title = currentTrack.artist;
52+
}
53+
}
54+
55+
if ([NSString isNullOrEmpty:title]) {
56+
title = BSLocalizedString(@"no-track-title", @"No tack title for tabs menu and default notification ");
57+
}
58+
59+
return [NSString stringWithFormat:@"%@ (%@)", title, BSSwinsianTabAdapter.displayName];
60+
}
61+
}
62+
63+
- (NSString *)URL{
64+
65+
return APPID;
66+
}
67+
68+
// We have only one window.
69+
- (NSString *)key{
70+
71+
return @"A:" APPID;
72+
}
73+
74+
// We have only one window.
75+
-(BOOL) isEqual:(__autoreleasing id)otherTab{
76+
77+
if (otherTab == nil || ![otherTab isKindOfClass:[BSSwinsianTabAdapter class]]) return NO;
78+
79+
return YES;
80+
}
81+
82+
//////////////////////////////////////////////////////////////
83+
#pragma mark Player control methods
84+
//////////////////////////////////////////////////////////////
85+
86+
- (BOOL)toggle{
87+
88+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
89+
if (music) {
90+
[music playpause];
91+
}
92+
// _musicNeedDisplayNotification = YES;
93+
return YES;
94+
}
95+
- (BOOL)pause{
96+
97+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
98+
if (music) {
99+
[music pause];
100+
}
101+
// _musicNeedDisplayNotification = YES;
102+
return YES;
103+
}
104+
- (BOOL)next{
105+
106+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
107+
if (music) {
108+
[music nextTrack];
109+
}
110+
// _musicNeedDisplayNotification = NO;
111+
return YES;
112+
}
113+
- (BOOL)previous{
114+
115+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
116+
if (music) {
117+
[music previousTrack];
118+
}
119+
// _musicNeedDisplayNotification = NO;
120+
return YES;
121+
}
122+
123+
- (BOOL)favorite{
124+
125+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
126+
if (music) {
127+
SwinsianTrack *track = [music currentTrack];
128+
@try {
129+
if ([[track rating] integerValue])
130+
track.rating = @(0);
131+
else
132+
track.rating = @(5);
133+
}
134+
@catch (NSException *exception) {
135+
136+
DDLogError(@"Error when calling [Swinsian rating]: %@", exception);
137+
ERROR_TRACE;
138+
}
139+
}
140+
return YES;
141+
}
142+
143+
- (BSTrack *)trackInfo{
144+
145+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
146+
if (music) {
147+
148+
SwinsianTrack *track = [music currentTrack];
149+
if (track) {
150+
BSTrack *trackInfo = [BSTrack new];
151+
152+
trackInfo.track = track.name ?: BSLocalizedString(@"apple-music-track-info-not-supported", @"");
153+
trackInfo.album = track.album;
154+
trackInfo.artist = track.artist;
155+
id image = track.albumArt;
156+
if ([image isKindOfClass:[NSImage class]]) {
157+
trackInfo.image = image;
158+
}
159+
else if ([image isKindOfClass:[NSAppleEventDescriptor class]]) {
160+
image = nil;
161+
NSData *data = [(NSAppleEventDescriptor *)track.albumArt data];
162+
if (data.length) {
163+
trackInfo.image = [[NSImage alloc] initWithData:data];
164+
}
165+
}
166+
167+
168+
@try {
169+
trackInfo.favorited = @([track.rating boolValue]);
170+
}
171+
@catch (NSException *exception) {
172+
DDLogError(@"Error when calling [Swinsian rating]: %@", exception);
173+
ERROR_TRACE;
174+
}
175+
176+
return trackInfo;
177+
}
178+
}
179+
180+
return nil;
181+
}
182+
183+
- (BOOL)isPlaying{
184+
185+
SwinsianApplication *music = (SwinsianApplication *)[self.application sbApplication];
186+
if (music) {
187+
188+
switch (music.playerState) {
189+
190+
case SwinsianPlayerStateStopped:
191+
case SwinsianPlayerStatePaused:
192+
193+
return NO;
194+
195+
default:
196+
197+
return YES;
198+
}
199+
}
200+
201+
return NO;
202+
}
203+
204+
//- (BOOL)showNotifications{
205+
// return _musicNeedDisplayNotification;
206+
//}
207+
208+
@end

0 commit comments

Comments
 (0)