2005-06-02 18:16:43 +00:00
|
|
|
#import "AppController.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "Cog-Swift.h"
|
2022-06-30 23:57:51 +00:00
|
|
|
#import "FileTreeController.h"
|
|
|
|
#import "FileTreeOutlineView.h"
|
|
|
|
#import "FileTreeViewController.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "FontSizetoLineHeightTransformer.h"
|
|
|
|
#import "OpenURLPanel.h"
|
2022-06-30 23:57:51 +00:00
|
|
|
#import "PathNode.h"
|
2007-03-09 01:16:06 +00:00
|
|
|
#import "PlaybackController.h"
|
|
|
|
#import "PlaylistController.h"
|
2013-10-09 09:02:49 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2007-03-09 01:16:06 +00:00
|
|
|
#import "PlaylistLoader.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "PlaylistView.h"
|
2022-06-16 14:14:33 +00:00
|
|
|
#import "SQLiteStore.h"
|
2022-06-20 10:35:29 +00:00
|
|
|
#import "SandboxBroker.h"
|
2008-02-11 09:20:52 +00:00
|
|
|
#import "SpotlightWindowController.h"
|
2008-02-18 01:46:34 +00:00
|
|
|
#import "StringToURLTransformer.h"
|
2013-10-09 09:02:49 +00:00
|
|
|
#import <CogAudio/Status.h>
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "DualWindow.h"
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
2013-10-11 19:02:05 +00:00
|
|
|
#import "MiniModeMenuTitleTransformer.h"
|
2013-10-11 12:03:55 +00:00
|
|
|
|
2022-05-22 22:26:27 +00:00
|
|
|
#import "ColorToValueTransformer.h"
|
|
|
|
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
#import "TotalTimeTransformer.h"
|
|
|
|
|
2021-01-25 02:44:17 +00:00
|
|
|
#import "Shortcuts.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import <MASShortcut/Shortcut.h>
|
2021-01-25 02:44:17 +00:00
|
|
|
|
2022-06-24 07:29:50 +00:00
|
|
|
#import "PreferencesController.h"
|
|
|
|
|
2022-06-17 14:24:12 +00:00
|
|
|
@import Firebase;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
void *kAppControllerContext = &kAppControllerContext;
|
2021-02-18 22:02:10 +00:00
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
BOOL kAppControllerShuttingDown = NO;
|
|
|
|
|
2022-06-24 07:29:50 +00:00
|
|
|
static AppController *kAppController = nil;
|
|
|
|
|
2021-02-06 22:12:19 +00:00
|
|
|
@implementation AppController {
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL _isFullToolbarStyle;
|
2021-02-06 22:12:19 +00:00
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2022-01-16 15:32:47 +00:00
|
|
|
@synthesize mainWindow;
|
|
|
|
@synthesize miniWindow;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (void)initialize {
|
|
|
|
// Register transformers
|
2016-05-05 20:05:39 +00:00
|
|
|
NSValueTransformer *stringToURLTransformer = [[StringToURLTransformer alloc] init];
|
2022-02-07 05:49:27 +00:00
|
|
|
[NSValueTransformer setValueTransformer:stringToURLTransformer
|
|
|
|
forName:@"StringToURLTransformer"];
|
2013-10-11 19:02:05 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *fontSizetoLineHeightTransformer =
|
|
|
|
[[FontSizetoLineHeightTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:fontSizetoLineHeightTransformer
|
|
|
|
forName:@"FontSizetoLineHeightTransformer"];
|
2008-02-18 01:46:34 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *miniModeMenuTitleTransformer = [[MiniModeMenuTitleTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:miniModeMenuTitleTransformer
|
|
|
|
forName:@"MiniModeMenuTitleTransformer"];
|
2022-05-22 22:26:27 +00:00
|
|
|
|
|
|
|
NSValueTransformer *colorToValueTransformer = [[ColorToValueTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:colorToValueTransformer
|
|
|
|
forName:@"ColorToValueTransformer"];
|
2008-02-18 01:46:34 +00:00
|
|
|
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
NSValueTransformer *totalTimeTransformer = [[TotalTimeTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:totalTimeTransformer
|
|
|
|
forName:@"TotalTimeTransformer"];
|
2022-06-30 07:28:03 +00:00
|
|
|
|
|
|
|
NSValueTransformer *numberHertzToStringTransformer = [[NumberHertzToStringTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:numberHertzToStringTransformer
|
|
|
|
forName:@"NumberHertzToStringTransformer"];
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)init {
|
2006-09-30 13:25:45 +00:00
|
|
|
self = [super init];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(self) {
|
2006-09-30 13:25:45 +00:00
|
|
|
[self initDefaults];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
queue = [[NSOperationQueue alloc] init];
|
2022-06-24 07:29:50 +00:00
|
|
|
|
|
|
|
kAppController = self;
|
2006-09-30 13:25:45 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
return self;
|
2006-09-30 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)openFiles:(id)sender {
|
2005-06-02 18:16:43 +00:00
|
|
|
NSOpenPanel *p;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
p = [NSOpenPanel openPanel];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[p setAllowedFileTypes:[playlistLoader acceptableFileTypes]];
|
2005-06-02 18:16:43 +00:00
|
|
|
[p setCanChooseDirectories:YES];
|
|
|
|
[p setAllowsMultipleSelection:YES];
|
2022-02-07 05:49:27 +00:00
|
|
|
[p setResolvesAliases:YES];
|
|
|
|
|
|
|
|
[p beginSheetModalForWindow:mainWindow
|
|
|
|
completionHandler:^(NSInteger result) {
|
|
|
|
if(result == NSModalResponseOK) {
|
2022-07-06 21:28:14 +00:00
|
|
|
NSDictionary *loadEntryData = @{@"entries": [p URLs],
|
|
|
|
@"sort": @(YES),
|
|
|
|
@"origin": @(URLOriginExternal)};
|
|
|
|
[self->playlistController performSelectorInBackground:@selector(addURLsInBackground:) withObject:loadEntryData];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
[p close];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)savePlaylist:(id)sender {
|
2007-05-26 14:43:31 +00:00
|
|
|
NSSavePanel *p;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-05-26 14:43:31 +00:00
|
|
|
p = [NSSavePanel savePanel];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
/* Yes, this is deprecated. Yes, this is required to give the dialog
|
|
|
|
* a default set of filename extensions to save, including adding an
|
|
|
|
* extension if the user does not supply one. */
|
|
|
|
[p setAllowedFileTypes:@[@"m3u", @"pls"]];
|
|
|
|
|
|
|
|
[p beginSheetModalForWindow:mainWindow
|
|
|
|
completionHandler:^(NSInteger result) {
|
|
|
|
if(result == NSModalResponseOK) {
|
|
|
|
[self->playlistLoader save:[[p URL] path]];
|
|
|
|
} else {
|
|
|
|
[p close];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)openURL:(id)sender {
|
2007-05-26 14:43:31 +00:00
|
|
|
OpenURLPanel *p;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-05-26 14:43:31 +00:00
|
|
|
p = [OpenURLPanel openURLPanel];
|
|
|
|
|
|
|
|
[p beginSheetWithWindow:mainWindow delegate:self didEndSelector:@selector(openURLPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)openURLPanelDidEnd:(OpenURLPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo {
|
|
|
|
if(returnCode == NSModalResponseOK) {
|
2022-07-06 21:28:14 +00:00
|
|
|
NSDictionary *loadEntriesData = @{ @"entries": @[[panel url]],
|
|
|
|
@"sort": @(NO),
|
|
|
|
@"origin": @(URLOriginExternal) };
|
|
|
|
[playlistController performSelectorInBackground:@selector(addURLsInBackground:) withObject:loadEntriesData];
|
2007-05-26 14:43:31 +00:00
|
|
|
}
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)delEntries:(id)sender {
|
2005-06-02 18:16:43 +00:00
|
|
|
[playlistController remove:self];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (PlaylistEntry *)currentEntry {
|
2005-06-02 18:16:43 +00:00
|
|
|
return [playlistController currentEntry];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key {
|
2022-02-22 05:52:09 +00:00
|
|
|
return [key isEqualToString:@"currentEntry"];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)awakeFromNib {
|
2022-06-29 03:22:51 +00:00
|
|
|
#if DEBUG
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions": @(NO) }];
|
|
|
|
#else
|
2022-06-17 14:24:12 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions": @(YES) }];
|
2022-06-29 03:22:51 +00:00
|
|
|
#endif
|
2022-06-20 04:46:30 +00:00
|
|
|
|
2022-06-17 14:24:12 +00:00
|
|
|
[FIRApp configure];
|
2022-06-22 02:01:06 +00:00
|
|
|
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.crashlyticsConsented" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kAppControllerContext];
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
[[totalTimeField cell] setBackgroundStyle:NSBackgroundStyleRaised];
|
2021-02-20 22:38:52 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self.infoButton setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")];
|
|
|
|
[self.infoButtonMini setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")];
|
2005-07-11 20:27:47 +00:00
|
|
|
[shuffleButton setToolTip:NSLocalizedString(@"ShuffleButtonTooltip", @"")];
|
|
|
|
[repeatButton setToolTip:NSLocalizedString(@"RepeatButtonTooltip", @"")];
|
2022-02-07 05:49:27 +00:00
|
|
|
[randomizeButton setToolTip:NSLocalizedString(@"RandomizeButtonTooltip", @"")];
|
2007-05-28 14:13:57 +00:00
|
|
|
[fileButton setToolTip:NSLocalizedString(@"FileButtonTooltip", @"")];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[self registerHotKeys];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
(void)[spotlightWindowController init];
|
|
|
|
|
2008-02-10 18:34:23 +00:00
|
|
|
[[playlistController undoManager] disableUndoRegistration];
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *basePath = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
|
|
|
|
|
|
|
NSString *dbFilename = @"Default.sqlite";
|
|
|
|
|
|
|
|
NSString *oldFilename = @"Default.m3u";
|
|
|
|
NSString *newFilename = @"Default.xml";
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
BOOL dataStorePresent = [playlistLoader addDataStore];
|
|
|
|
|
|
|
|
if(!dataStorePresent) {
|
|
|
|
if([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:dbFilename]]) {
|
|
|
|
[playlistLoader addDatabase];
|
|
|
|
} else if([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:newFilename]]) {
|
|
|
|
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:newFilename]]];
|
|
|
|
} else {
|
|
|
|
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:oldFilename]]];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:35:29 +00:00
|
|
|
SandboxBroker *sandboxBroker = [SandboxBroker sharedSandboxBroker];
|
|
|
|
if(!sandboxBroker) {
|
|
|
|
ALog(@"Sandbox broker init failed.");
|
|
|
|
}
|
2022-07-25 06:14:52 +00:00
|
|
|
[SandboxBroker cleanupFolderAccess];
|
2022-06-20 10:35:29 +00:00
|
|
|
|
2008-02-10 18:34:23 +00:00
|
|
|
[[playlistController undoManager] enableUndoRegistration];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
int lastStatus = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"lastPlaybackStatus"];
|
|
|
|
|
|
|
|
if(lastStatus != CogStatusStopped) {
|
2022-06-21 06:18:37 +00:00
|
|
|
NSPredicate *hasUrlPredicate = [NSPredicate predicateWithFormat:@"urlString != nil && urlString != %@", @""];
|
|
|
|
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"];
|
2022-06-19 08:42:27 +00:00
|
|
|
NSPredicate *currentPredicate = [NSPredicate predicateWithFormat:@"current == YES"];
|
|
|
|
|
2022-06-21 06:18:37 +00:00
|
|
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, hasUrlPredicate, currentPredicate]];
|
2022-06-19 08:42:27 +00:00
|
|
|
|
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
|
|
|
request.predicate = predicate;
|
|
|
|
|
|
|
|
NSError *error = nil;
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock lock];
|
2022-06-19 08:42:27 +00:00
|
|
|
NSArray *results = [playlistController.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
2022-10-12 05:58:36 +00:00
|
|
|
if(results) {
|
|
|
|
results = [results copy];
|
|
|
|
}
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock unlock];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
if(results && [results count] == 1) {
|
|
|
|
PlaylistEntry *pe = results[0];
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"resumePlaybackOnStartup"]) {
|
|
|
|
[playbackController playEntryAtIndex:pe.index startPaused:(lastStatus == CogStatusPaused) andSeekTo:@(pe.currentPosition)];
|
|
|
|
} else {
|
|
|
|
pe.current = NO;
|
2022-06-21 02:13:33 +00:00
|
|
|
pe.stopAfter = NO;
|
2022-06-19 08:42:27 +00:00
|
|
|
pe.currentPosition = 0.0;
|
2022-06-21 02:13:33 +00:00
|
|
|
pe.countAdded = NO;
|
2022-06-19 08:42:27 +00:00
|
|
|
[playlistController commitPersistentStore];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore mini mode
|
|
|
|
[self setMiniMode:[[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"]];
|
|
|
|
|
|
|
|
[self setToolbarStyle:[[NSUserDefaults standardUserDefaults] boolForKey:@"toolbarStyleFull"]];
|
|
|
|
|
|
|
|
[self setFloatingMiniWindow:[[NSUserDefaults standardUserDefaults]
|
|
|
|
boolForKey:@"floatingMiniWindow"]];
|
|
|
|
|
2022-06-30 23:57:51 +00:00
|
|
|
// We need file tree view to restore its state here
|
|
|
|
// so attempt to access file tree view controller's root view
|
|
|
|
// to force it to read nib and create file tree view for us
|
|
|
|
//
|
|
|
|
// TODO: there probably is a more elegant way to do all this
|
|
|
|
// but i'm too stupid/tired to figure it out now
|
|
|
|
[fileTreeViewController view];
|
|
|
|
|
|
|
|
FileTreeOutlineView *outlineView = [fileTreeViewController outlineView];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeExpanded:) name:NSOutlineViewItemDidExpandNotification object:outlineView];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeCollapsed:) name:NSOutlineViewItemDidCollapseNotification object:outlineView];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDockMenu:) name:CogPlaybackDidBeginNotficiation object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDockMenu:) name:CogPlaybackDidStopNotficiation object:nil];
|
|
|
|
|
|
|
|
[self updateDockMenu:nil];
|
|
|
|
|
2022-06-30 23:57:51 +00:00
|
|
|
NSArray *expandedNodesArray = [[NSUserDefaults standardUserDefaults] valueForKey:@"fileTreeViewExpandedNodes"];
|
|
|
|
|
|
|
|
if(expandedNodesArray) {
|
|
|
|
expandedNodes = [[NSMutableSet alloc] initWithArray:expandedNodesArray];
|
|
|
|
} else {
|
|
|
|
expandedNodes = [[NSMutableSet alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
DLog(@"Nodes to expand: %@", [expandedNodes description]);
|
|
|
|
|
|
|
|
DLog(@"Num of rows: %ld", [outlineView numberOfRows]);
|
|
|
|
|
|
|
|
if(!outlineView) {
|
|
|
|
DLog(@"outlineView is NULL!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[outlineView reloadData];
|
|
|
|
|
|
|
|
for(NSInteger i = 0; i < [outlineView numberOfRows]; i++) {
|
|
|
|
PathNode *pn = [outlineView itemAtRow:i];
|
|
|
|
NSString *str = [[pn URL] absoluteString];
|
|
|
|
|
|
|
|
if([expandedNodes containsObject:str]) {
|
|
|
|
[outlineView expandItem:pn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self addObserver:self
|
|
|
|
forKeyPath:@"playlistController.currentEntry"
|
|
|
|
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
|
|
|
|
context:kAppControllerContext];
|
2021-02-18 22:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
2022-02-07 05:49:27 +00:00
|
|
|
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
2021-02-18 22:02:10 +00:00
|
|
|
context:(void *)context {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(context != kAppControllerContext) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-22 02:01:06 +00:00
|
|
|
|
|
|
|
if([keyPath isEqualToString:@"values.crashlyticsConsented"]) {
|
|
|
|
BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"crashlyticsConsented"];
|
|
|
|
[[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:enabled];
|
|
|
|
[FIRAnalytics setAnalyticsCollectionEnabled:enabled];
|
|
|
|
} else if([keyPath isEqualToString:@"playlistController.currentEntry"]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
PlaylistEntry *entry = playlistController.currentEntry;
|
2022-06-18 23:10:18 +00:00
|
|
|
NSString *appTitle = NSLocalizedString(@"CogTitle", @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!entry) {
|
2022-06-11 20:34:57 +00:00
|
|
|
miniWindow.title = appTitle;
|
|
|
|
mainWindow.title = appTitle;
|
2022-02-07 05:49:27 +00:00
|
|
|
if(@available(macOS 11.0, *)) {
|
|
|
|
miniWindow.subtitle = @"";
|
|
|
|
mainWindow.subtitle = @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
self.infoButton.imageScaling = NSImageScaleNone;
|
|
|
|
self.infoButton.image = [NSImage imageNamed:@"infoTemplate"];
|
|
|
|
self.infoButtonMini.imageScaling = NSImageScaleNone;
|
|
|
|
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(entry.albumArt) {
|
|
|
|
self.infoButton.imageScaling = NSImageScaleProportionallyUpOrDown;
|
|
|
|
self.infoButton.image = playlistController.currentEntry.albumArt;
|
|
|
|
self.infoButtonMini.imageScaling = NSImageScaleProportionallyUpOrDown;
|
|
|
|
self.infoButtonMini.image = playlistController.currentEntry.albumArt;
|
|
|
|
} else {
|
|
|
|
self.infoButton.imageScaling = NSImageScaleNone;
|
|
|
|
self.infoButton.image = [NSImage imageNamed:@"infoTemplate"];
|
|
|
|
self.infoButtonMini.imageScaling = NSImageScaleNone;
|
|
|
|
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(@available(macOS 11.0, *)) {
|
2022-06-11 20:34:57 +00:00
|
|
|
NSString *title = appTitle;
|
2022-02-07 05:49:27 +00:00
|
|
|
if(entry.title) {
|
|
|
|
title = entry.title;
|
|
|
|
}
|
|
|
|
miniWindow.title = title;
|
|
|
|
mainWindow.title = title;
|
|
|
|
|
|
|
|
NSString *subtitle = @"";
|
|
|
|
NSMutableArray<NSString *> *subtitleItems = [NSMutableArray array];
|
|
|
|
if(entry.album && ![entry.album isEqualToString:@""]) {
|
|
|
|
[subtitleItems addObject:entry.album];
|
|
|
|
}
|
|
|
|
if(entry.artist && ![entry.artist isEqualToString:@""]) {
|
|
|
|
[subtitleItems addObject:entry.artist];
|
|
|
|
}
|
|
|
|
|
|
|
|
if([subtitleItems count]) {
|
|
|
|
subtitle = [subtitleItems componentsJoinedByString:@" - "];
|
|
|
|
}
|
|
|
|
|
|
|
|
miniWindow.subtitle = subtitle;
|
|
|
|
mainWindow.subtitle = subtitle;
|
|
|
|
} else {
|
2022-06-11 20:34:57 +00:00
|
|
|
NSString *title = appTitle;
|
2022-02-07 05:49:27 +00:00
|
|
|
if(entry.display) {
|
|
|
|
title = entry.display;
|
|
|
|
}
|
|
|
|
miniWindow.title = title;
|
|
|
|
mainWindow.title = title;
|
|
|
|
}
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
} else if([keyPath isEqualToString:@"finished"]) {
|
|
|
|
NSProgress *progress = (NSProgress *)object;
|
|
|
|
if([progress isFinished]) {
|
|
|
|
playbackController.progressOverall = nil;
|
|
|
|
[NSApp terminate:nil];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 23:57:51 +00:00
|
|
|
- (void)nodeExpanded:(NSNotification *)notification {
|
|
|
|
PathNode *node = [[notification userInfo] objectForKey:@"NSObject"];
|
|
|
|
NSString *url = [[node URL] absoluteString];
|
|
|
|
|
|
|
|
[expandedNodes addObject:url];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)nodeCollapsed:(NSNotification *)notification {
|
|
|
|
PathNode *node = [[notification userInfo] objectForKey:@"NSObject"];
|
|
|
|
NSString *url = [[node URL] absoluteString];
|
|
|
|
|
|
|
|
[expandedNodes removeObject:url];
|
|
|
|
}
|
|
|
|
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
|
|
|
if(playbackController.progressOverall) {
|
|
|
|
[playbackController.progressOverall addObserver:self forKeyPath:@"finished" options:0 context:kAppControllerContext];
|
|
|
|
return NSTerminateLater;
|
|
|
|
} else {
|
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
2022-06-19 08:42:27 +00:00
|
|
|
kAppControllerShuttingDown = YES;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
CogStatus currentStatus = [playbackController playbackStatus];
|
|
|
|
|
|
|
|
if(currentStatus == CogStatusStopping)
|
|
|
|
currentStatus = CogStatusStopped;
|
|
|
|
|
2007-02-26 05:07:18 +00:00
|
|
|
[playbackController stop:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:currentStatus forKey:@"lastPlaybackStatus"];
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *folder = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
2021-12-24 09:01:21 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([fileManager fileExistsAtPath:folder] == NO) {
|
|
|
|
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:nil];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2021-12-24 09:01:21 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playlistController clearFilterPredicate:self];
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
NSMutableDictionary<NSString *, AlbumArtwork *> *artLeftovers = [playlistController.persistentArtStorage mutableCopy];
|
|
|
|
|
|
|
|
NSManagedObjectContext *moc = playlistController.persistentContainer.viewContext;
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in playlistController.arrangedObjects) {
|
|
|
|
if(pe.deLeted) {
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock lock];
|
2022-06-16 14:14:33 +00:00
|
|
|
[moc deleteObject:pe];
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock unlock];
|
2022-06-16 14:14:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if([artLeftovers objectForKey:pe.artHash]) {
|
|
|
|
[artLeftovers removeObjectForKey:pe.artHash];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock lock];
|
2022-06-16 14:14:33 +00:00
|
|
|
for(NSString *key in artLeftovers) {
|
|
|
|
[moc deleteObject:[artLeftovers objectForKey:key]];
|
|
|
|
}
|
2022-07-15 14:00:11 +00:00
|
|
|
[playlistController.persistentContainerLock unlock];
|
2022-06-16 14:14:33 +00:00
|
|
|
|
|
|
|
[playlistController commitPersistentStore];
|
|
|
|
|
|
|
|
if([SQLiteStore databaseStarted]) {
|
|
|
|
[[SQLiteStore sharedStore] shutdown];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSError *error;
|
2022-06-16 14:14:33 +00:00
|
|
|
NSString *fileName = @"Default.sqlite";
|
|
|
|
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error];
|
|
|
|
|
|
|
|
fileName = @"Default.xml";
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error];
|
|
|
|
|
|
|
|
fileName = @"Default.m3u";
|
2013-10-11 10:03:23 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error];
|
2013-10-11 10:03:23 +00:00
|
|
|
|
2022-06-20 10:35:29 +00:00
|
|
|
DLog(@"Shutting down sandbox broker");
|
|
|
|
[[SandboxBroker sharedSandboxBroker] shutdown];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
DLog(@"Saving expanded nodes: %@", [expandedNodes description]);
|
|
|
|
|
2022-06-30 23:57:51 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setValue:[expandedNodes allObjects] forKey:@"fileTreeViewExpandedNodes"];
|
2022-02-07 05:49:27 +00:00
|
|
|
// Workaround window not restoring it's size and position.
|
|
|
|
[miniWindow setContentSize:NSMakeSize(miniWindow.frame.size.width, 1)];
|
|
|
|
[miniWindow saveFrameUsingName:@"Mini Window"];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
|
|
|
|
if(flag == NO)
|
|
|
|
[mainWindow makeKeyAndOrderFront:self]; // TODO: do we really need this? We never close the main window.
|
2015-01-15 13:57:22 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
for(NSWindow *win in [NSApp windows]) // Maximizing all windows
|
2015-01-15 13:57:22 +00:00
|
|
|
if([win isMiniaturized])
|
|
|
|
[win deminiaturize:self];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
|
|
|
|
NSArray *urls = @[[NSURL fileURLWithPath:filename]];
|
2022-07-06 21:28:14 +00:00
|
|
|
NSDictionary *loadEntriesData = @{ @"entries": urls,
|
|
|
|
@"sort": @(NO),
|
2022-07-07 00:04:02 +00:00
|
|
|
@"origin": @(URLOriginExternal) };
|
2022-07-06 21:28:14 +00:00
|
|
|
[playlistController performSelectorInBackground:@selector(addURLsInBackground:) withObject:loadEntriesData];
|
2005-06-02 18:16:43 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames {
|
|
|
|
// Need to convert to urls
|
2007-03-09 01:16:06 +00:00
|
|
|
NSMutableArray *urls = [NSMutableArray array];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
for(NSString *filename in filenames) {
|
2007-03-09 01:16:06 +00:00
|
|
|
[urls addObject:[NSURL fileURLWithPath:filename]];
|
|
|
|
}
|
2022-07-06 21:28:14 +00:00
|
|
|
|
|
|
|
NSDictionary *loadEntriesData = @{ @"entries": urls,
|
|
|
|
@"sort": @(YES),
|
2022-07-07 00:04:02 +00:00
|
|
|
@"origin": @(URLOriginExternal) };
|
2022-07-06 21:28:14 +00:00
|
|
|
|
|
|
|
[playlistController performSelectorInBackground:@selector(addURLsInBackground:) withObject:loadEntriesData];
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
|
|
|
}
|
|
|
|
|
2022-06-22 02:30:30 +00:00
|
|
|
- (IBAction)privacyPolicy:(id)sender {
|
2022-07-09 22:40:22 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:NSLocalizedString(@"PrivacyPolicyURL", @"Privacy policy URL from Iubenda.")]];
|
2022-06-22 02:30:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)feedback:(id)sender {
|
|
|
|
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
2020-11-25 00:03:49 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray<NSURLQueryItem *> *query = @[
|
|
|
|
[NSURLQueryItem queryItemWithName:@"labels"
|
|
|
|
value:@"bug"],
|
|
|
|
[NSURLQueryItem queryItemWithName:@"template"
|
|
|
|
value:@"bug_report.md"],
|
|
|
|
[NSURLQueryItem queryItemWithName:@"title"
|
|
|
|
value:[NSString stringWithFormat:@"[Cog %@] ", version]]
|
|
|
|
];
|
|
|
|
NSURLComponents *components =
|
|
|
|
[NSURLComponents componentsWithString:@"https://github.com/losnoco/Cog/issues/new"];
|
2019-11-16 22:49:30 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
components.queryItems = query;
|
2021-02-09 00:11:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:components.URL];
|
2006-04-04 01:08:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)initDefaults {
|
2006-09-02 16:09:20 +00:00
|
|
|
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
|
2006-09-10 21:27:20 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Font defaults
|
2022-07-08 00:56:25 +00:00
|
|
|
float fFontSize = [NSFont systemFontSizeForControlSize:NSControlSizeRegular];
|
2022-06-17 13:39:02 +00:00
|
|
|
NSNumber *fontSize = @(fFontSize);
|
2022-02-07 05:49:27 +00:00
|
|
|
[userDefaultsValuesDict setObject:fontSize forKey:@"fontSize"];
|
|
|
|
|
|
|
|
NSString *feedURLdefault = @"https://cogcdn.cog.losno.co/mercury.xml";
|
|
|
|
[userDefaultsValuesDict setObject:feedURLdefault forKey:@"SUFeedURL"];
|
2008-05-09 21:24:49 +00:00
|
|
|
|
2008-05-18 09:38:53 +00:00
|
|
|
[userDefaultsValuesDict setObject:@"clearAndPlay" forKey:@"openingFilesBehavior"];
|
|
|
|
[userDefaultsValuesDict setObject:@"enqueue" forKey:@"openingFilesAlteredBehavior"];
|
2021-01-25 03:23:48 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[userDefaultsValuesDict setObject:@"albumGainWithPeak" forKey:@"volumeScaling"];
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[userDefaultsValuesDict setObject:@"cubic" forKey:@"resampling"];
|
|
|
|
|
2022-06-17 13:39:02 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(CogStatusStopped) forKey:@"lastPlaybackStatus"];
|
2013-10-04 11:16:09 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[userDefaultsValuesDict setObject:@"dls appl" forKey:@"midiPlugin"];
|
|
|
|
|
|
|
|
[userDefaultsValuesDict setObject:@"default" forKey:@"midi.flavor"];
|
|
|
|
|
2022-06-17 13:39:02 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(NO) forKey:@"resumePlaybackOnStartup"];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-17 13:39:02 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(NO) forKey:@"quitOnNaturalStop"];
|
2022-02-22 04:55:42 +00:00
|
|
|
|
2022-06-17 13:39:02 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(NO) forKey:@"spectrumFreqMode"];
|
|
|
|
[userDefaultsValuesDict setObject:@(YES) forKey:@"spectrumProjectionMode"];
|
2022-05-22 22:26:27 +00:00
|
|
|
|
|
|
|
NSValueTransformer *colorToValueTransformer = [NSValueTransformer valueTransformerForName:@"ColorToValueTransformer"];
|
|
|
|
|
|
|
|
NSData *barColor = [colorToValueTransformer reverseTransformedValue:[NSColor colorWithSRGBRed:1.0 green:0.5 blue:0 alpha:1.0]];
|
|
|
|
NSData *dotColor = [colorToValueTransformer reverseTransformedValue:[NSColor systemRedColor]];
|
|
|
|
|
2022-07-05 19:52:53 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(YES) forKey:@"spectrumSceneKit"];
|
2022-05-22 22:26:27 +00:00
|
|
|
[userDefaultsValuesDict setObject:barColor forKey:@"spectrumBarColor"];
|
|
|
|
[userDefaultsValuesDict setObject:dotColor forKey:@"spectrumDotColor"];
|
|
|
|
|
2022-07-02 05:06:08 +00:00
|
|
|
[userDefaultsValuesDict setObject:@(150.0) forKey:@"synthDefaultSeconds"];
|
|
|
|
[userDefaultsValuesDict setObject:@(8.0) forKey:@"synthDefaultFadeSeconds"];
|
|
|
|
[userDefaultsValuesDict setObject:@(2) forKey:@"synthDefaultLoopCount"];
|
|
|
|
[userDefaultsValuesDict setObject:@(44100) forKey:@"synthSampleRate"];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Register and sync defaults
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
// And if the existing feed URL is broken due to my ineptitude with the above defaults, fix it
|
|
|
|
NSSet<NSString *> *brokenFeedURLs = [NSSet setWithObjects:
|
|
|
|
@"https://kode54.net/cog/stable.xml",
|
|
|
|
@"https://kode54.net/cog/mercury.xml"
|
|
|
|
@"https://www.kode54.net/cog/mercury.xml",
|
|
|
|
@"https://f.losno.co/cog/mercury.xml",
|
|
|
|
nil];
|
|
|
|
NSString *feedURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"];
|
|
|
|
if([brokenFeedURLs containsObject:feedURL]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setValue:feedURLdefault forKey:@"SUFeedURL"];
|
|
|
|
}
|
2021-01-25 02:44:17 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *oldMidiPlugin = [[NSUserDefaults standardUserDefaults] stringForKey:@"midi.plugin"];
|
|
|
|
if(oldMidiPlugin) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setValue:oldMidiPlugin forKey:@"midiPlugin"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"midi.plugin"];
|
|
|
|
}
|
2022-02-09 02:29:03 +00:00
|
|
|
|
|
|
|
// if([[[NSUserDefaults standardUserDefaults] stringForKey:@"midiPlugin"] isEqualToString:@"BASSMIDI"]) {
|
|
|
|
// [[NSUserDefaults standardUserDefaults] setValue:@"FluidSynth" forKey:@"midiPlugin"];
|
|
|
|
// }
|
|
|
|
if([[[NSUserDefaults standardUserDefaults] stringForKey:@"midiPlugin"] isEqualToString:@"FluidSynth"]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setValue:@"BASSMIDI" forKey:@"midiPlugin"];
|
|
|
|
}
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
/* Unassign previous handler first, so dealloc can unregister it from the global map before the new instances are assigned */
|
|
|
|
- (void)registerHotKeys {
|
|
|
|
MASShortcutBinder *binder = [MASShortcutBinder sharedBinder];
|
|
|
|
[binder bindShortcutWithDefaultsKey:CogPlayShortcutKey
|
|
|
|
toAction:^{
|
|
|
|
[self clickPlay];
|
|
|
|
}];
|
|
|
|
|
|
|
|
[binder bindShortcutWithDefaultsKey:CogNextShortcutKey
|
|
|
|
toAction:^{
|
|
|
|
[self clickNext];
|
|
|
|
}];
|
|
|
|
|
|
|
|
[binder bindShortcutWithDefaultsKey:CogPrevShortcutKey
|
|
|
|
toAction:^{
|
|
|
|
[self clickPrev];
|
|
|
|
}];
|
|
|
|
|
|
|
|
[binder bindShortcutWithDefaultsKey:CogSpamShortcutKey
|
|
|
|
toAction:^{
|
|
|
|
[self clickSpam];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)clickPlay {
|
2008-01-23 03:03:46 +00:00
|
|
|
[playbackController playPauseResume:self];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickPause {
|
|
|
|
[playbackController pause:self];
|
2019-11-14 03:13:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickStop {
|
|
|
|
[playbackController stop:self];
|
2019-11-14 03:13:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickPrev {
|
2008-01-23 03:03:46 +00:00
|
|
|
[playbackController prev:nil];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickNext {
|
2008-01-23 03:03:46 +00:00
|
|
|
[playbackController next:nil];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickSpam {
|
|
|
|
[playbackController spam:nil];
|
2013-10-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)clickSeek:(NSTimeInterval)position {
|
|
|
|
[playbackController seek:self toTime:position];
|
2019-11-14 03:13:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)changeFontSize:(float)size {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
float fCurrentSize = [defaults floatForKey:@"fontSize"];
|
2022-06-17 13:39:02 +00:00
|
|
|
NSNumber *newSize = @(fCurrentSize + size);
|
2022-02-07 05:49:27 +00:00
|
|
|
[defaults setObject:newSize forKey:@"fontSize"];
|
2008-02-15 15:27:34 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)increaseFontSize:(id)sender {
|
2008-02-15 15:27:34 +00:00
|
|
|
[self changeFontSize:1];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)decreaseFontSize:(id)sender {
|
2008-02-15 15:27:34 +00:00
|
|
|
[self changeFontSize:-1];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2008-03-01 18:29:14 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)toggleMiniMode:(id)sender {
|
|
|
|
[self setMiniMode:(!miniMode)];
|
2013-10-11 19:02:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)miniMode {
|
|
|
|
return miniMode;
|
2013-10-11 19:02:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setMiniMode:(BOOL)newMiniMode {
|
|
|
|
miniMode = newMiniMode;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:miniMode forKey:@"miniMode"];
|
|
|
|
|
|
|
|
NSWindow *windowToShow = miniMode ? miniWindow : mainWindow;
|
|
|
|
NSWindow *windowToHide = miniMode ? mainWindow : miniWindow;
|
|
|
|
[windowToHide close];
|
|
|
|
[windowToShow makeKeyAndOrderFront:self];
|
2013-10-11 19:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 22:12:19 +00:00
|
|
|
- (IBAction)toggleToolbarStyle:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setToolbarStyle:!_isFullToolbarStyle];
|
2021-02-06 22:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setToolbarStyle:(BOOL)full {
|
2022-02-07 05:49:27 +00:00
|
|
|
_isFullToolbarStyle = full;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:full forKey:@"toolbarStyleFull"];
|
|
|
|
DLog("Changed toolbar style: %@", (full ? @"full" : @"compact"));
|
|
|
|
|
|
|
|
if(@available(macOS 11.0, *)) {
|
|
|
|
NSWindowToolbarStyle style =
|
|
|
|
full ? NSWindowToolbarStyleExpanded : NSWindowToolbarStyleUnified;
|
|
|
|
mainWindow.toolbarStyle = style;
|
|
|
|
miniWindow.toolbarStyle = style;
|
|
|
|
} else {
|
|
|
|
NSWindowTitleVisibility titleVisibility = full ? NSWindowTitleVisible : NSWindowTitleHidden;
|
|
|
|
mainWindow.titleVisibility = titleVisibility;
|
|
|
|
miniWindow.titleVisibility = titleVisibility;
|
|
|
|
}
|
2021-02-06 22:12:19 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Fix empty area after changing toolbar style in mini window as it has no content view
|
|
|
|
[miniWindow setContentSize:NSMakeSize(miniWindow.frame.size.width, 0)];
|
2021-02-06 22:12:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 21:04:59 +00:00
|
|
|
- (void)setFloatingMiniWindow:(BOOL)floatingMiniWindow {
|
2022-02-07 05:49:27 +00:00
|
|
|
_floatingMiniWindow = floatingMiniWindow;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:floatingMiniWindow forKey:@"floatingMiniWindow"];
|
|
|
|
NSWindowLevel level = floatingMiniWindow ? NSFloatingWindowLevel : NSNormalWindowLevel;
|
|
|
|
[miniWindow setLevel:level];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateDockMenu:(NSNotification *)notification {
|
|
|
|
PlaylistEntry *pe = [playlistController currentEntry];
|
|
|
|
|
|
|
|
BOOL hideItem = NO;
|
|
|
|
|
|
|
|
if([[notification name] isEqualToString:CogPlaybackDidStopNotficiation] || !pe || ![pe artist] || [[pe artist] isEqualToString:@""])
|
|
|
|
hideItem = YES;
|
|
|
|
|
|
|
|
if(hideItem && [dockMenu indexOfItem:currentArtistItem] == 0) {
|
|
|
|
[dockMenu removeItem:currentArtistItem];
|
|
|
|
} else if(!hideItem && [dockMenu indexOfItem:currentArtistItem] < 0) {
|
|
|
|
[dockMenu insertItem:currentArtistItem atIndex:0];
|
|
|
|
}
|
2022-01-16 07:41:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 05:58:13 +00:00
|
|
|
- (BOOL)pathSuggesterEmpty {
|
|
|
|
return [playlistController pathSuggesterEmpty];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (BOOL)globalPathSuggesterEmpty {
|
|
|
|
return [kAppController pathSuggesterEmpty];
|
|
|
|
}
|
|
|
|
|
2022-06-24 07:29:50 +00:00
|
|
|
- (void)showPathSuggester {
|
|
|
|
[preferencesController showPathSuggester:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)globalShowPathSuggester {
|
|
|
|
[kAppController showPathSuggester];
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|