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:21:39 -08:00
parent e9df18c067
commit 6036000214
4 changed files with 61 additions and 48 deletions

View file

@ -28,6 +28,7 @@
#import "Shortcuts.h" #import "Shortcuts.h"
#import <MASShortcut/Shortcut.h> #import <MASShortcut/Shortcut.h>
#import <MASShortcut/MASDictionaryTransformer.h>
#import <Sparkle/Sparkle.h> #import <Sparkle/Sparkle.h>
@ -209,11 +210,11 @@ static BOOL consentLastEnabled = NO;
[randomizeButton setToolTip:NSLocalizedString(@"RandomizeButtonTooltip", @"")]; [randomizeButton setToolTip:NSLocalizedString(@"RandomizeButtonTooltip", @"")];
[fileButton setToolTip:NSLocalizedString(@"FileButtonTooltip", @"")]; [fileButton setToolTip:NSLocalizedString(@"FileButtonTooltip", @"")];
if(@available(macOS 15, *)) { [self registerDefaultHotKeys];
[self registerDefaultHotKeys];
[self migrateHotKeys];
[self registerHotKeys];
} [self registerHotKeys];
(void)[spotlightWindowController init]; (void)[spotlightWindowController init];
@ -760,23 +761,24 @@ static NSDictionary *shortcutDefaults = nil;
MASShortcut *seekFwdShortcut = [MASShortcut shortcutWithKeyCode:kVK_RightArrow MASShortcut *seekFwdShortcut = [MASShortcut shortcutWithKeyCode:kVK_RightArrow
modifierFlags:NSEventModifierFlagControl | NSEventModifierFlagCommand]; modifierFlags:NSEventModifierFlagControl | NSEventModifierFlagCommand];
NSData *playShortcutData = [NSKeyedArchiver archivedDataWithRootObject:playShortcut]; MASDictionaryTransformer *transformer = [MASDictionaryTransformer new];
NSData *nextShortcutData = [NSKeyedArchiver archivedDataWithRootObject:nextShortcut]; NSDictionary *playShortcutDict = [transformer reverseTransformedValue:playShortcut];
NSData *prevShortcutData = [NSKeyedArchiver archivedDataWithRootObject:prevShortcut]; NSDictionary *nextShortcutDict = [transformer reverseTransformedValue:nextShortcut];
NSData *spamShortcutData = [NSKeyedArchiver archivedDataWithRootObject:spamShortcut]; NSDictionary *prevShortcutDict = [transformer reverseTransformedValue:prevShortcut];
NSData *fadeShortcutData = [NSKeyedArchiver archivedDataWithRootObject:fadeShortcut]; NSDictionary *spamShortcutDict = [transformer reverseTransformedValue:spamShortcut];
NSData *seekBkwdShortcutData = [NSKeyedArchiver archivedDataWithRootObject:seekBkwdShortcut]; NSDictionary *fadeShortcutDict = [transformer reverseTransformedValue:fadeShortcut];
NSData *seekFwdShortcutData = [NSKeyedArchiver archivedDataWithRootObject:seekFwdShortcut]; NSDictionary *seekBkwdShortcutDict = [transformer reverseTransformedValue:seekBkwdShortcut];
NSDictionary *seekFwdShortcutDict = [transformer reverseTransformedValue:seekFwdShortcut];
// Register default values to be used for the first app start // Register default values to be used for the first app start
NSDictionary<NSString *, NSData *> *defaultShortcuts = @{ NSDictionary<NSString *, NSDictionary *> *defaultShortcuts = @{
CogPlayShortcutKey: playShortcutData, CogPlayShortcutKey: playShortcutDict,
CogNextShortcutKey: nextShortcutData, CogNextShortcutKey: nextShortcutDict,
CogPrevShortcutKey: prevShortcutData, CogPrevShortcutKey: prevShortcutDict,
CogSpamShortcutKey: spamShortcutData, CogSpamShortcutKey: spamShortcutDict,
CogFadeShortcutKey: fadeShortcutData, CogFadeShortcutKey: fadeShortcutDict,
CogSeekBackwardShortcutKey: seekBkwdShortcutData, CogSeekBackwardShortcutKey: seekBkwdShortcutDict,
CogSeekForwardShortcutKey: seekFwdShortcutData CogSeekForwardShortcutKey: seekFwdShortcutDict
}; };
shortcutDefaults = defaultShortcuts; shortcutDefaults = defaultShortcuts;
@ -790,6 +792,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 { - (void)registerHotKeys {
MASShortcutBinder *binder = [MASShortcutBinder sharedBinder]; MASShortcutBinder *binder = [MASShortcutBinder sharedBinder];
[binder bindShortcutWithDefaultsKey:CogPlayShortcutKey [binder bindShortcutWithDefaultsKey:CogPlayShortcutKey

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

View file

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

View file

@ -5,10 +5,18 @@
// Created by Dzmitry Neviadomski on 25.01.21. // Created by Dzmitry Neviadomski on 25.01.21.
// //
static NSString *const CogPlayShortcutKey = @"cogPlayShortcut"; static NSString *const CogPlayShortcutKey = @"cogPlayShortcutV2";
static NSString *const CogNextShortcutKey = @"cogNextShortcut"; static NSString *const CogNextShortcutKey = @"cogNextShortcutV2";
static NSString *const CogPrevShortcutKey = @"cogPrevShortcut"; static NSString *const CogPrevShortcutKey = @"cogPrevShortcutV2";
static NSString *const CogSpamShortcutKey = @"cogSpamShortcut"; static NSString *const CogSpamShortcutKey = @"cogSpamShortcutV2";
static NSString *const CogFadeShortcutKey = @"cogFadeShortcut"; static NSString *const CogFadeShortcutKey = @"cogFadeShortcutV2";
static NSString *const CogSeekBackwardShortcutKey = @"cogSeekBackwardShortcut"; static NSString *const CogSeekBackwardShortcutKey = @"cogSeekBackwardShortcutV2";
static NSString *const CogSeekForwardShortcutKey = @"cogSeekForwardShortcut"; 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";