Skip to content

Commit

Permalink
1.1 - Add iTunes support, add PFMoveApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
moyitpro committed Jun 14, 2018
1 parent 7149197 commit 546d9f9
Show file tree
Hide file tree
Showing 8 changed files with 605 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# SwinsianDiscord
![screnshot](https://i.imgur.com/8CS4PSL.png)

SwinsianDiscord is a simple menubar app for macOS that allows you to share what you are playing in Swinsian in Discord via Rich Presence. [Swinsian](https://swinsian.com) is a Advanced Music Player for Mac.
SwinsianDiscord is a simple menubar app for macOS that allows you to share what you are playing in Swinsian or iTunes 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 to work.
This program works on macOS El Capitan or later and requires Swinsian version >= 1.8.8 or Apple iTunes to work.

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

Expand All @@ -13,4 +13,6 @@ The logo and the program name, Swinsian is owned by the respective owners.

Note: You can automatically set SwinsianDiscord to enable Rich Presence automatically by enabling the Start Rich Presence at Startup.

Depending on what music player you are using, it will show the large icon where music is playing. Do not use Swinsian and iTunes at the same time.

SwinsianDiscord is licensed under BSD License.
6 changes: 6 additions & 0 deletions SwinsianDiscord.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
F87417FE20D0750700614654 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F87417FD20D0750700614654 /* Assets.xcassets */; };
F874180120D0750700614654 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F87417FF20D0750700614654 /* MainMenu.xib */; };
F874180420D0750700614654 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F874180320D0750700614654 /* main.m */; };
F8EC907E20D30DA90086F719 /* PFMoveApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = F8EC907D20D30DA90086F719 /* PFMoveApplication.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -60,6 +61,8 @@
F874180220D0750700614654 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F874180320D0750700614654 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
F874180520D0750700614654 /* iTunesDiscord.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iTunesDiscord.entitlements; sourceTree = "<group>"; };
F8EC907C20D30DA80086F719 /* PFMoveApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFMoveApplication.h; sourceTree = "<group>"; };
F8EC907D20D30DA90086F719 /* PFMoveApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFMoveApplication.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -109,6 +112,8 @@
F85BC43920D08E2C00C58BD9 /* Sparkle.framework */,
F85D493E20D078D800343699 /* DiscordManager.h */,
F85D493D20D078D700343699 /* DiscordManager.m */,
F8EC907C20D30DA80086F719 /* PFMoveApplication.h */,
F8EC907D20D30DA90086F719 /* PFMoveApplication.m */,
F874180220D0750700614654 /* Info.plist */,
F874180320D0750700614654 /* main.m */,
F85D494B20D0851600343699 /* EULA.rtf */,
Expand Down Expand Up @@ -200,6 +205,7 @@
files = (
F874180420D0750700614654 /* main.m in Sources */,
F85D494620D0838300343699 /* PFAboutWindowController.m in Sources */,
F8EC907E20D30DA90086F719 /* PFMoveApplication.m in Sources */,
F87417FC20D0750700614654 /* AppDelegate.m in Sources */,
F85D493F20D078D800343699 /* DiscordManager.m in Sources */,
);
Expand Down
36 changes: 34 additions & 2 deletions SwinsianDiscord/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "AppDelegate.h"
#import "DiscordManager.h"
#import "PFAboutWindowController.h"
#import "PFMoveApplication.h"

@interface AppDelegate ()
@property (weak) IBOutlet NSMenuItem *togglerichpresence;
Expand Down Expand Up @@ -59,6 +60,7 @@ - (void) awakeFromNib {

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
PFMoveToApplicationsFolderIfNecessary();
self.dm = [DiscordManager new];
if ([NSUserDefaults.standardUserDefaults boolForKey:@"startrichpresence"]) {
[_dm startDiscordRPC];
Expand All @@ -80,11 +82,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
selector: @selector(trackStopped:)
name: @"com.swinsian.Swinsian-Track-Stopped"
object: nil];

[center addObserver:self
selector:@selector(playerInfoChanged:)
name:@"com.apple.iTunes.playerInfo"
object:nil];
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
[_dm shutdownDiscordRPC];
}

- (IBAction)showabout:(id)sender {
Expand Down Expand Up @@ -118,19 +126,43 @@ - (IBAction)togglerichpresence:(id)sender {
- (void)trackPlaying:(NSNotification *)myNotification {
if (_dm.getStarted) {
NSDictionary *userInfo = myNotification.userInfo;
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",userInfo[@"artist"],userInfo[@"album"]] withDetails:userInfo[@"title"]];
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",userInfo[@"artist"],userInfo[@"album"]] withDetails:userInfo[@"title"] withLargeImage:@"swinsian"];
}

}
- (void)trackPaused:(NSNotification *)myNotification {
if (_dm.getStarted) {
NSDictionary *userInfo = myNotification.userInfo;
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",userInfo[@"artist"],userInfo[@"album"]] withDetails:userInfo[@"title"]];
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",userInfo[@"artist"],userInfo[@"album"]] withDetails:userInfo[@"title"] withLargeImage:@"swinsian"];
}
}
- (void)trackStopped:(NSNotification *)myNotification {
if (_dm.getStarted) {
[_dm removePresence];
}
}

- (void)playerInfoChanged:(NSNotification *)theNotification
{
NSDictionary *info = [theNotification userInfo];

if ([(NSString *)info[@"Player State"] isEqualToString:@"Stopped"]) {
if (_dm.getStarted) {
[_dm removePresence];
}
return;
}

if ([(NSString *)info[@"Player State"] isEqualToString:@"Playing"]) {
if (_dm.getStarted) {
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",info[@"Artist"],info[@"Album"]] withDetails:info[@"Name"] withLargeImage:@"itunes"];
}
}

if ([(NSString *)info[@"Player State"] isEqualToString:@"Paused"]) {
if (_dm.getStarted) {
[self.dm UpdatePresence:[NSString stringWithFormat:@"by %@ \n- %@",info[@"Artist"],info[@"Album"]] withDetails:info[@"Name"] withLargeImage:@"itunes"];
}
}
}
@end
2 changes: 1 addition & 1 deletion SwinsianDiscord/DiscordManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@property (getter=getStarted) bool discordrpcrunning;
- (void)startDiscordRPC;
- (void)shutdownDiscordRPC;
- (void)UpdatePresence:(NSString *)state withDetails:(NSString *)details;
- (void)UpdatePresence:(NSString *)state withDetails:(NSString *)details withLargeImage:(NSString *)largeimage;
- (void)removePresence;
@end
4 changes: 2 additions & 2 deletions SwinsianDiscord/DiscordManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ - (void)shutdownDiscordRPC {
_discordrpcrunning = false;
}

- (void)UpdatePresence:(NSString *)state withDetails:(NSString *)details {
- (void)UpdatePresence:(NSString *)state withDetails:(NSString *)details withLargeImage:(NSString *)largeimage {
if ([self checkDiscordRunning]) {
Discord_ClearPresence();
DiscordRichPresence discordPresence;
discordPresence.state = state.UTF8String;
discordPresence.details = details.UTF8String;
discordPresence.startTimestamp = [NSDate date].timeIntervalSince1970;
discordPresence.endTimestamp = [NSDate dateWithTimeIntervalSinceNow:86400].timeIntervalSince1970;
discordPresence.largeImageKey = "default";
discordPresence.largeImageKey = largeimage.UTF8String;
discordPresence.smallImageKey = "default";
discordPresence.largeImageText = "";
discordPresence.smallImageText = "";
Expand Down
14 changes: 7 additions & 7 deletions SwinsianDiscord/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Moy IT Solutions. All rights reserved.</string>
<key>NSMainNibFile</key>
Expand All @@ -30,11 +35,6 @@
<string>NSApplication</string>
<key>NSUIElement</key>
<string>1</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>SUEnableSystemProfiling</key>
<true/>
<key>SUFeedURL</key>
Expand Down
17 changes: 17 additions & 0 deletions SwinsianDiscord/PFMoveApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// PFMoveApplication.h, version 1.22
// LetsMove
//
// Created by Andy Kim at Potion Factory LLC on 9/17/09
//
// The contents of this file are dedicated to the public domain.

#ifdef __cplusplus
extern "C" {
#endif

void PFMoveToApplicationsFolderIfNecessary(void);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 546d9f9

Please sign in to comment.