diff --git a/Application/AppController.m b/Application/AppController.m index 9270b54c1..ae785f94d 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -28,6 +28,7 @@ #import "Shortcuts.h" #import +#import #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 *defaultShortcuts = @{ - CogPlayShortcutKey: playShortcutData, - CogNextShortcutKey: nextShortcutData, - CogPrevShortcutKey: prevShortcutData, - CogSpamShortcutKey: spamShortcutData, - CogFadeShortcutKey: fadeShortcutData, - CogSeekBackwardShortcutKey: seekBkwdShortcutData, - CogSeekForwardShortcutKey: seekFwdShortcutData + 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 diff --git a/Frameworks/shpakovski/MASShortcut b/Frameworks/shpakovski/MASShortcut index a7d420713..c4a91c10e 160000 --- a/Frameworks/shpakovski/MASShortcut +++ b/Frameworks/shpakovski/MASShortcut @@ -1 +1 @@ -Subproject commit a7d42071344fb63c3dcee1dc7d468a089600d4e5 +Subproject commit c4a91c10e47310dba71782c46577e31117d0b6ef diff --git a/Preferences/Preferences/GeneralPreferencesPlugin.m b/Preferences/Preferences/GeneralPreferencesPlugin.m index 105349f87..e43f6cfdd 100644 --- a/Preferences/Preferences/GeneralPreferencesPlugin.m +++ b/Preferences/Preferences/GeneralPreferencesPlugin.m @@ -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 { diff --git a/Preferences/Shortcuts.h b/Preferences/Shortcuts.h index 0b0b2f3c9..3f6fb7b9c 100644 --- a/Preferences/Shortcuts.h +++ b/Preferences/Shortcuts.h @@ -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";