Skip to content

Commit

Permalink
Universal Binary Support, Full support for Music App
Browse files Browse the repository at this point in the history
The elapsed time now works properly for the Music app under Catalina and Big Sur. The app now supports Apple Silicon.
  • Loading branch information
千代田桃 committed Feb 5, 2021
1 parent db4a91d commit c32f2c7
Show file tree
Hide file tree
Showing 73 changed files with 2,226 additions and 615 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

SwinsianDiscord is a simple menubar app for macOS that allows you to share what you are playing in Swinsian or iTunes/Music App in Discord via Rich Presence. [Swinsian](https://swinsian.com) is a Advanced Music Player for Mac.

This program works on macOS El Capitan or later and requires Swinsian version >= 1.8.8 or Apple iTunes to work. Music.app suppport requires macOS 10.15 Catalina, but it does not support elapsed time due to the app not providing that information.
This program works on macOS El Capitan or later and requires Swinsian version >= 1.8.8 or Apple iTunes to work. Music.app suppport requires macOS 10.15 Catalina or later. This is Universal Binary 2 compatible.

The logo and the program name, Swinsian is owned by the respective owners.

Expand Down
8 changes: 4 additions & 4 deletions SwinsianDiscord.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 9HDZTER525;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -349,7 +349,7 @@
);
INFOPLIST_FILE = "$(SRCROOT)/SwinsianDiscord/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = pro.moyit.iTunesDiscord;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -361,7 +361,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 9HDZTER525;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -371,7 +371,7 @@
);
INFOPLIST_FILE = "$(SRCROOT)/SwinsianDiscord/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.2.1;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = pro.moyit.iTunesDiscord;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SwinsianDiscord.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
40 changes: 39 additions & 1 deletion SwinsianDiscord/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ - (void)playerInfoChanged:(NSNotification *)theNotification
if ([(NSString *)info[@"Player State"] isEqualToString:@"Playing"]) {
if (_dm.getStarted) {
if (@available(macOS 10.5, *)) {
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",info[@"Artist"],info[@"Album"]] withDetails:info[@"Name"] withLargeImage:@"itunes" withCurrentPosition:0];
float pos = [self getMusicPlayerPosition];
float duration = [self getMusicPlayerDuration];
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",info[@"Artist"],info[@"Album"]] withDetails:info[@"Name"] withLargeImage:@"itunes" withCurrentPosition:duration-pos];
}
else {
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",info[@"Artist"],info[@"Album"]] withDetails:info[@"Name"] withLargeImage:@"itunes" withCurrentPosition:[self convertElaspedTimeToInterval:info[@"elapsedStr"]]];
Expand All @@ -185,6 +187,42 @@ - (void)playerInfoChanged:(NSNotification *)theNotification
}
}

- (float)getMusicPlayerPosition {
return [self executeAppleScriot:@"tell application \"Music\" to get player position"].floatValue;
}

- (float)getMusicPlayerDuration {
return [self executeAppleScriot:@"tell application \"Music\" to get duration of current track"].floatValue;
}

- (NSString *)executeAppleScriot:(NSString *)command {
@try {
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/osascript";
task.arguments = @[@"-e", command];
NSPipe *pipe;
pipe = [NSPipe pipe];
task.standardOutput = pipe;

NSFileHandle *file;
file = pipe.fileHandleForReading;
[task setEnvironment:@{@"LC_ALL" : @"en_US.UTF-8"}];
[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
if (string.length > 0) {
return string;
}
}
@catch (NSException *ex) {
return @"";
}
return @"";
}

- (float)convertElaspedTimeToInterval:(NSString *)elapsed {
NSString *tmpstr = [elapsed stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSArray *intervals = [tmpstr componentsSeparatedByString:@":"];
Expand Down
Binary file modified SwinsianDiscord/DiscordRPC.framework/Versions/A/DiscordRPC
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#pragma once

#if defined(DISCORD_DYNAMIC_LIB)
# if defined(_WIN32)
# if defined(DISCORD_BUILDING_SDK)
# define DISCORD_EXPORT __declspec(dllexport)
# else
# define DISCORD_EXPORT __declspec(dllimport)
# endif
# else
# define DISCORD_EXPORT __attribute__((visibility("default")))
# endif
#if defined(_WIN32)
#if defined(DISCORD_BUILDING_SDK)
#define DISCORD_EXPORT __declspec(dllexport)
#else
# define DISCORD_EXPORT
#define DISCORD_EXPORT __declspec(dllimport)
#endif
#else
#define DISCORD_EXPORT __attribute__((visibility("default")))
#endif
#else
#define DISCORD_EXPORT
#endif

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ typedef struct DiscordRichPresence {
int8_t instance;
} DiscordRichPresence;

typedef struct DiscordJoinRequest {
typedef struct DiscordUser {
const char* userId;
const char* username;
const char* discriminator;
const char* avatar;
} DiscordJoinRequest;
} DiscordUser;

typedef struct DiscordEventHandlers {
void (*ready)(void);
void (*ready)(const DiscordUser* request);
void (*disconnected)(int errorCode, const char* message);
void (*errored)(int errorCode, const char* message);
void (*joinGame)(const char* joinSecret);
void (*spectateGame)(const char* spectateSecret);
void (*joinRequest)(const DiscordJoinRequest* request);
void (*joinRequest)(const DiscordUser* request);
} DiscordEventHandlers;

#define DISCORD_REPLY_NO 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

template <typename ElementType, size_t QueueSize>
class MsgQueue {
ElementType queue_[QueueSize]{};
ElementType queue_[QueueSize];
std::atomic_uint nextAdd_{0};
std::atomic_uint nextSend_{0};
std::atomic_uint pendingSends_{0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct RpcConnection {

BaseConnection* connection{nullptr};
State state{State::Disconnected};
void (*onConnect)(){nullptr};
void (*onConnect)(JsonDocument& message){nullptr};
void (*onDisconnect)(int errorCode, const char* message){nullptr};
char appId[64]{};
int lastErrorCode{0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma warning(disable : 4464) // relative include path contains
#pragma warning(disable : 4668) // is not defined as a preprocessor macro
#pragma warning(disable : 6313) // Incorrect operator
#endif // __MINGW32__
#endif // __MINGW32__

#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17C205</string>
<string>20B29</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>3.4.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
Expand All @@ -27,17 +27,21 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>9C40b</string>
<string>12B45b</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<string>11.0</string>
<key>DTSDKBuild</key>
<string>17C76</string>
<string>20A2408</string>
<key>DTSDKName</key>
<string>macosx10.13</string>
<string>macosx11.0</string>
<key>DTXcode</key>
<string>0920</string>
<string>1220</string>
<key>DTXcodeBuild</key>
<string>9C40b</string>
<string>12B45b</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Moy IT Solutions. All rights reserved.</string>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions SwinsianDiscord/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<string>https://updates.malupdaterosx.moe/swinsiandiscord/profileInfo.php</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
<key>NSAppleEventsUsageDescription</key>
<string>SwinsianDiscord uses Automation to retreive information about the current media you are playing.</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions SwinsianDiscord/Sparkle.framework/Headers
1 change: 1 addition & 0 deletions SwinsianDiscord/Sparkle.framework/Modules
1 change: 1 addition & 0 deletions SwinsianDiscord/Sparkle.framework/PrivateHeaders
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// SPUDownloadData.h
// Sparkle
//
// Created by Mayur Pawashe on 8/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//

#if __has_feature(modules)
@import Foundation;
#else
#import <Foundation/Foundation.h>
#endif

#import "SUExport.h"

NS_ASSUME_NONNULL_BEGIN

/*!
* A class for containing downloaded data along with some information about it.
*/
SU_EXPORT @interface SPUDownloadData : NSObject <NSSecureCoding>

- (instancetype)initWithData:(NSData *)data textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType;

/*!
* The raw data that was downloaded.
*/
@property (nonatomic, readonly) NSData *data;

/*!
* The IANA charset encoding name if available. Eg: "utf-8"
*/
@property (nonatomic, readonly, nullable, copy) NSString *textEncodingName;

/*!
* The MIME type if available. Eg: "text/plain"
*/
@property (nonatomic, readonly, nullable, copy) NSString *MIMEType;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SPUDownloader.h
// Downloader
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//

#if __has_feature(modules)
@import Foundation;
#else
#import <Foundation/Foundation.h>
#endif
#import "SPUDownloaderProtocol.h"

@protocol SPUDownloaderDelegate;

// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
@interface SPUDownloader : NSObject <SPUDownloaderProtocol>

// Due to XPC remote object reasons, this delegate is strongly referenced
// Invoke cleanup when done with this instance
- (instancetype)initWithDelegate:(id <SPUDownloaderDelegate>)delegate;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SPUDownloaderDelegate.h
// Sparkle
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//

#if __has_feature(modules)
@import Foundation;
#else
#import <Foundation/Foundation.h>
#endif

NS_ASSUME_NONNULL_BEGIN

@class SPUDownloadData;

@protocol SPUDownloaderDelegate <NSObject>

// This is only invoked for persistent downloads
- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory;

// Under rare cases, this may be called more than once, in which case the current progress should be reset back to 0
// This is only invoked for persistent downloads
- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength;

// This is only invoked for persistent downloads
- (void)downloaderDidReceiveDataOfLength:(uint64_t)length;

// downloadData is nil if this is a persisent download, otherwise it's non-nil if it's a temporary download
- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData;

- (void)downloaderDidFailWithError:(NSError *)error;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SPUDownloaderDeprecated.h
// Sparkle
//
// Created by Deadpikle on 12/20/17.
// Copyright © 2017 Sparkle Project. All rights reserved.
//

#import "SPUDownloader.h"

@interface SPUDownloaderDeprecated : SPUDownloader <SPUDownloaderProtocol>

@end
Loading

0 comments on commit c32f2c7

Please sign in to comment.