Re-enable hotkeys and change preferences storage

Change hotkey storage system, hopefully this will fix the stability
issues that have been plaguing it for a while now.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-08 20:24:25 -08:00
parent 442dfb726b
commit 0de555c2fd
4 changed files with 60 additions and 47 deletions

View file

@ -28,6 +28,7 @@
#import "Shortcuts.h"
#import <MASShortcut/Shortcut.h>
#import <MASShortcut/MASDictionaryTransformer.h>
#import "PreferencesController.h"
@ -185,11 +186,11 @@ static BOOL consentLastEnabled = NO;
[randomizeButton setToolTip:NSLocalizedString(@"RandomizeButtonTooltip", @"")];
[fileButton setToolTip:NSLocalizedString(@"FileButtonTooltip", @"")];
if(@available(macOS 15, *)) {
[self registerDefaultHotKeys];
[self registerHotKeys];
}
[self registerDefaultHotKeys];
[self migrateHotKeys];
[self registerHotKeys];
(void)[spotlightWindowController init];
@ -735,23 +736,24 @@ static NSDictionary *shortcutDefaults = nil;
MASShortcut *seekFwdShortcut = [MASShortcut shortcutWithKeyCode:kVK_RightArrow
modifierFlags:NSEventModifierFlagControl | NSEventModifierFlagCommand];
NSData *playShortcutData = [NSKeyedArchiver archivedDataWithRootObject:playShortcut];
NSData *nextShortcutData = [NSKeyedArchiver archivedDataWithRootObject:nextShortcut];
NSData *prevShortcutData = [NSKeyedArchiver archivedDataWithRootObject:prevShortcut];
NSData *spamShortcutData = [NSKeyedArchiver archivedDataWithRootObject:spamShortcut];
NSData *fadeShortcutData = [NSKeyedArchiver archivedDataWithRootObject:fadeShortcut];
NSData *seekBkwdShortcutData = [NSKeyedArchiver archivedDataWithRootObject:seekBkwdShortcut];
NSData *seekFwdShortcutData = [NSKeyedArchiver archivedDataWithRootObject:seekFwdShortcut];
MASDictionaryTransformer *transformer = [MASDictionaryTransformer new];
NSDictionary *playShortcutDict = [transformer reverseTransformedValue:playShortcut];
NSDictionary *nextShortcutDict = [transformer reverseTransformedValue:nextShortcut];
NSDictionary *prevShortcutDict = [transformer reverseTransformedValue:prevShortcut];
NSDictionary *spamShortcutDict = [transformer reverseTransformedValue:spamShortcut];
NSDictionary *fadeShortcutDict = [transformer reverseTransformedValue:fadeShortcut];
NSDictionary *seekBkwdShortcutDict = [transformer reverseTransformedValue:seekBkwdShortcut];
NSDictionary *seekFwdShortcutDict = [transformer reverseTransformedValue:seekFwdShortcut];
// Register default values to be used for the first app start
NSDictionary<NSString *, NSData *> *defaultShortcuts = @{
CogPlayShortcutKey: playShortcutData,
CogNextShortcutKey: nextShortcutData,
CogPrevShortcutKey: prevShortcutData,
CogSpamShortcutKey: spamShortcutData,
CogFadeShortcutKey: fadeShortcutData,
CogSeekBackwardShortcutKey: seekBkwdShortcutData,
CogSeekForwardShortcutKey: seekFwdShortcutData
NSDictionary<NSString *, NSDictionary *> *defaultShortcuts = @{
CogPlayShortcutKey: playShortcutDict,
CogNextShortcutKey: nextShortcutDict,
CogPrevShortcutKey: prevShortcutDict,
CogSpamShortcutKey: spamShortcutDict,
CogFadeShortcutKey: fadeShortcutDict,
CogSeekBackwardShortcutKey: seekBkwdShortcutDict,
CogSeekForwardShortcutKey: seekFwdShortcutDict
};
shortcutDefaults = defaultShortcuts;
@ -765,6 +767,20 @@ static NSDictionary *shortcutDefaults = nil;
}];
}
- (void)migrateHotKeys {
NSArray *inKeys = @[CogPlayShortcutKeyV1, CogNextShortcutKeyV1, CogPrevShortcutKeyV1, CogSpamShortcutKeyV1, CogFadeShortcutKeyV1, CogSeekBackwardShortcutKeyV1, CogSeekForwardShortcutKeyV1];
NSArray *outKeys = @[CogPlayShortcutKey, CogNextShortcutKey, CogPrevShortcutKey, CogSpamShortcutKey, CogFadeShortcutKey, CogSeekBackwardShortcutKey, CogSeekForwardShortcutKey];
for(size_t i = 0, j = [inKeys count]; i < j; ++i) {
NSString *inKey = inKeys[i];
NSString *outKey = outKeys[i];
id value = [[NSUserDefaults standardUserDefaults] objectForKey:inKey];
if(value && value != [NSNull null]) {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:outKey];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:inKey];
}
}
}
- (void)registerHotKeys {
MASShortcutBinder *binder = [MASShortcutBinder sharedBinder];
[binder bindShortcutWithDefaultsKey:CogPlayShortcutKey

@ -1 +1 @@
Subproject commit a7d42071344fb63c3dcee1dc7d468a089600d4e5
Subproject commit c4a91c10e47310dba71782c46577e31117d0b6ef

View file

@ -41,25 +41,14 @@
[[NSBundle bundleWithIdentifier:@"org.cogx.cog.preferences"] loadNibNamed:@"Preferences"
owner:plugin
topLevelObjects:nil];
if(@available(macOS 15, *)) {
return @[[plugin playlistPane],
[plugin hotKeyPane],
[plugin outputPane],
[plugin generalPane],
[plugin notificationsPane],
[plugin appearancePane],
[plugin midiPane],
[plugin rubberbandPane]];
} else {
return @[[plugin playlistPane],
[plugin outputPane],
[plugin generalPane],
[plugin notificationsPane],
[plugin appearancePane],
[plugin midiPane],
[plugin rubberbandPane]];
}
return @[[plugin playlistPane],
[plugin hotKeyPane],
[plugin outputPane],
[plugin generalPane],
[plugin notificationsPane],
[plugin appearancePane],
[plugin midiPane],
[plugin rubberbandPane]];
}
- (HotKeyPane *)hotKeyPane {

View file

@ -5,10 +5,18 @@
// Created by Dzmitry Neviadomski on 25.01.21.
//
static NSString *const CogPlayShortcutKey = @"cogPlayShortcut";
static NSString *const CogNextShortcutKey = @"cogNextShortcut";
static NSString *const CogPrevShortcutKey = @"cogPrevShortcut";
static NSString *const CogSpamShortcutKey = @"cogSpamShortcut";
static NSString *const CogFadeShortcutKey = @"cogFadeShortcut";
static NSString *const CogSeekBackwardShortcutKey = @"cogSeekBackwardShortcut";
static NSString *const CogSeekForwardShortcutKey = @"cogSeekForwardShortcut";
static NSString *const CogPlayShortcutKey = @"cogPlayShortcutV2";
static NSString *const CogNextShortcutKey = @"cogNextShortcutV2";
static NSString *const CogPrevShortcutKey = @"cogPrevShortcutV2";
static NSString *const CogSpamShortcutKey = @"cogSpamShortcutV2";
static NSString *const CogFadeShortcutKey = @"cogFadeShortcutV2";
static NSString *const CogSeekBackwardShortcutKey = @"cogSeekBackwardShortcutV2";
static NSString *const CogSeekForwardShortcutKey = @"cogSeekForwardShortcutV2";
static NSString *const CogPlayShortcutKeyV1 = @"cogPlayShortcut";
static NSString *const CogNextShortcutKeyV1 = @"cogNextShortcut";
static NSString *const CogPrevShortcutKeyV1 = @"cogPrevShortcut";
static NSString *const CogSpamShortcutKeyV1 = @"cogSpamShortcut";
static NSString *const CogFadeShortcutKeyV1 = @"cogFadeShortcut";
static NSString *const CogSeekBackwardShortcutKeyV1 = @"cogSeekBackwardShortcut";
static NSString *const CogSeekForwardShortcutKeyV1 = @"cogSeekForwardShortcut";