Skip to content

Commit

Permalink
notification fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dtseto committed Nov 4, 2024
1 parent b838c40 commit 18a9d86
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Version 1.3.2 (dtseto fork)
*[edits by @dtseto] change localizations for mac os 11 xcode , depracated code
# Version 1.32b3
fixes to notifications to use macos instead of growler, notifications should work now

# Version 1.3.2b2 (dtseto fork)
*[edits by @dtseto] change localizations for mac os 11 xcode , depracated code, merge unreleased pull requests from 1.32 etc
removed growler and notifications
*[bug toolbar buttons no longer appear are in >>> as text only ]
universal app

# Version 1.3.2 (unreleased)
[Full changelog](https://github.com/HermesApp/Hermes/compare/v1.3.1...HEAD)
Expand Down
11 changes: 11 additions & 0 deletions Hermes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0F828EA42CD93B7200C35281 /* NotificationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F828EA32CD93A5900C35281 /* NotificationManager.m */; };
0FA6A7F22CD2F6A100961AD0 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD42F8713678F7500E935CA /* Sparkle.framework */; };
0FA6A7F32CD2F6A100961AD0 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FAD42F8713678F7500E935CA /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
Expand Down Expand Up @@ -113,6 +114,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0F828EA12CD9388F00C35281 /* NotificationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NotificationManager.h; path = ../../../NotificationManager.h; sourceTree = "<group>"; };
0F828EA32CD93A5900C35281 /* NotificationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NotificationManager.m; sourceTree = "<group>"; };
0FE7696E2C8EB09A00E3189E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
0FE769702C8EB09F00E3189E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -437,6 +440,8 @@
FA2A3F76132BF97E0089AECC /* StationsController.m */,
FACFACD415673690008A2140 /* StationController.h */,
FACFACD515673690008A2140 /* StationController.m */,
0F828EA32CD93A5900C35281 /* NotificationManager.m */,
0F828EA12CD9388F00C35281 /* NotificationManager.h */,
);
name = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -657,6 +662,7 @@
FA1063BE132C6A8A00D6DE42 /* Keychain.m in Sources */,
FAEFFAB1132CB173007DC6FB /* AuthController.m in Sources */,
FA3CFF44132FC4CF003554E2 /* PlaybackController.m in Sources */,
0F828EA42CD93B7200C35281 /* NotificationManager.m in Sources */,
FA560C511331701E00215F71 /* ImageLoader.m in Sources */,
FA85E72E13347A64005C96B8 /* HermesAppDelegate.m in Sources */,
B2A26AEF1AE39E9B00ADD460 /* MusicProgressSliderCell.m in Sources */,
Expand Down Expand Up @@ -760,6 +766,7 @@
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = GHTQCRGWTR;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)",
Expand All @@ -774,6 +781,7 @@
);
INFOPLIST_FILE = "Resources/Hermes-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.3.2b3;
PRODUCT_BUNDLE_IDENTIFIER = "com.alexcrichton.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hermes;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -798,6 +806,8 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = GHTQCRGWTR;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)",
Expand All @@ -812,6 +822,7 @@
);
INFOPLIST_FILE = "Resources/Hermes-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.3.2b3;
PRODUCT_BUNDLE_IDENTIFIER = "com.alexcrichton.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hermes;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 3 additions & 1 deletion Resources/Hermes-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.2d1</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand All @@ -45,6 +45,8 @@
<string>HermesApp</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
<key>OSAScriptingDefinition</key>
<string>Hermes.sdef</string>
<key>SUAllowsAutomaticUpdates</key>
Expand Down
9 changes: 9 additions & 0 deletions Sources/Controllers/PlaybackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#import <SPMediaKeyTap/SPMediaKeyTap.h>
#import <MediaPlayer/MediaPlayer.h>


//#import "Integration/Growler.h"
#import "NotificationManager.h"

#import "HistoryController.h"
#import "ImageLoader.h"
#import "PlaybackController.h"
Expand Down Expand Up @@ -338,6 +341,8 @@ - (void)songPlayed: (NSNotification *)aNotification {
[self setArtImage:nil];
if (![self->playing isPaused])
//[GROWLER growl:song withImage:nil isNew:YES];
[[NotificationManager sharedManager] notifySongPlaying:song withImageData:nil isNew:YES];

;
} else {
[artLoading startAnimation:nil];
Expand All @@ -357,6 +362,8 @@ - (void)songPlayed: (NSNotification *)aNotification {

if (![self->playing isPaused]) {
//[GROWLER growl:song withImage:data isNew:YES];
[[NotificationManager sharedManager] notifySongPlaying:song withImageData:data isNew:YES];

}
[self setArtImage:image];
}];
Expand Down Expand Up @@ -432,6 +439,8 @@ - (BOOL) play {
} else {
[playing play];
//[GROWLER growl:[playing playingSong] withImage:lastImg isNew:NO];
[[NotificationManager sharedManager] notifySongPlaying:[playing playingSong] withImageData:lastImg isNew:NO];

return YES;
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/Controllers/PreferencesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*/

/* If these are changed, then the xib also needs to be updated */

#define NOTIFICATION_ENABLED @"notification.enabled"



#define PLEASE_BIND_MEDIA @"pleaseBindMedia"
#define PLEASE_SCROBBLE @"pleaseScrobble"
#define PLEASE_SCROBBLE_LIKES @"pleaseScrobbleLikes"
Expand Down Expand Up @@ -72,6 +77,11 @@
IBOutlet NSView *network;

// General

//new
//IBOutlet NSButton *notificationEnabled;


IBOutlet NSButton *mediaKeysCheckbox;
IBOutlet NSTextField *mediaKeysLabel;

Expand Down
73 changes: 73 additions & 0 deletions Sources/NotificationManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#import "NotificationManager.h"
#import "Song.h" // Make sure to import your Song class header
#import "PreferencesController.h"


// Use existing preference keys
#define PLEASE_GROWL @"pleaseGrowl"
#define PLEASE_GROWL_NEW @"pleaseGrowlNew"
#define PLEASE_GROWL_PLAY @"pleaseGrowlPlay"
#define NOTIFICATION_TYPE @"notificationType"


@implementation NotificationManager

+ (instancetype)sharedManager {
static NotificationManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc] init];
});
return sharedManager;
}

- (instancetype)init {
self = [super init];
if (self) {
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
center.delegate = self;
}
return self;
}

- (void)notifySongPlaying:(Song *)song withImageData:(NSData *)imageData isNew:(BOOL)isNew {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

// Check if notifications are enabled
if (![defaults boolForKey:PLEASE_GROWL]) {
return;
}

// Check specific notification settings
if (isNew && ![defaults boolForKey:PLEASE_GROWL_NEW]) {
return;
}

if (!isNew && ![defaults boolForKey:PLEASE_GROWL_PLAY]) {
return;
}

NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = [song title];
notification.subtitle = [song artist];
notification.informativeText = [song album];

if (imageData) {
notification.contentImage = [[NSImage alloc] initWithData:imageData];
}

// Only play sound for new songs, not resumed playback
if (isNew) {
notification.soundName = NSUserNotificationDefaultSoundName;
}

[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
#pragma mark - NSUserNotificationCenterDelegate

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification {
// Always show notifications, even when app is active
return YES;
}
@end

0 comments on commit 18a9d86

Please sign in to comment.