Skip to content

Commit 1d63069

Browse files
Fix enabling scrobbling on and off to refresh bug (#45)
1 parent 4d8054f commit 1d63069

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
## CHANGELOG
22

33
### Unrelaesed
4-
- Remove spaces from login
4+
5+
#### Added
56
- Send "Now playing" request to last.fm
67

8+
#### Fixed
9+
- Remove spaces from login
10+
- Fix bug where toggling "Enabled" on and off was needed to scrobble songs
11+
712
### 1.3.0 (2021/11/23)
813

914
- Scrobble with album name [issue #37](https://github.com/ShazamScrobbler/shazamscrobbler-macos/issues/37)

ShazamScrobbler/LastFmController.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ + (void)init {
3434
[LastFm sharedInstance].apiSecret = SECRET;
3535
[LastFm sharedInstance].session = [prefs valueForKey:@"session"];
3636
[LastFm sharedInstance].username = [prefs valueForKey:@"username"];
37-
37+
38+
// Initialize operation queue
3839
operationQueue = [[NSOperationQueue alloc] init];
3940
[operationQueue setMaxConcurrentOperationCount: 1];
41+
42+
// Ensure scrobbling state is properly initialized
43+
MenuController *menu = ((AppDelegate *)[NSApplication sharedApplication].delegate).menu;
44+
[menu.scrobblingItem setEnabled:([prefs stringForKey:@"session"] != nil)];
4045
}
4146

4247
+ (bool)login:(NSString*)username withPassword:(NSString*)password {

ShazamScrobbler/MenuController.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ - (IBAction)negateScrobbling:(id)sender
205205
NSInteger scrobbling = [[NSUserDefaults standardUserDefaults] integerForKey:@"scrobbling"];
206206
NSInteger state = scrobbling ? NSOffState : NSOnState;
207207
[[NSUserDefaults standardUserDefaults] setInteger:state forKey:@"scrobbling"];
208-
208+
[[NSUserDefaults standardUserDefaults] synchronize]; // Ensure settings are saved
209+
209210
[_scrobblingItem setState:state];
210-
[_scrobblingItem setEnabled:state];
211211
[_main itemChanged:_scrobblingItem];
212-
if (state == NSOnState) {
213-
[ShazamController findNewTags];
214-
}
212+
213+
// Always try to find new tags when toggling scrobbling
214+
[ShazamController findNewTags];
215215
}
216216

217217
- (void)updateScrobblingItemWith:(NSInteger)itemsToScrobble

ShazamScrobbler/ShazamController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ + (void)watch:(NSString*) path {
126126
+ (void)findNewTags {
127127
//Initialize previous session information
128128
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
129-
129+
130130
// Connection to the DB
131131
FMDatabase *database = [FMDatabase databaseWithPath:[ShazamConstants getSqlitePath]];
132132

0 commit comments

Comments
 (0)