diff --git a/Package.swift b/Package.swift index 3893a1d9..e9afe87e 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "ShortcutRecorder", defaultLocalization: "en", platforms: [ - .macOS(.v10_11) + .macOS(.v10_13) ], products: [ .library(name: "ShortcutRecorder", targets: ["ShortcutRecorder"]) diff --git a/ShortcutRecorder.xcodeproj/project.pbxproj b/ShortcutRecorder.xcodeproj/project.pbxproj index 6035c49e..737b9880 100644 --- a/ShortcutRecorder.xcodeproj/project.pbxproj +++ b/ShortcutRecorder.xcodeproj/project.pbxproj @@ -872,7 +872,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-fstack-protector"; RUN_CLANG_STATIC_ANALYZER = YES; @@ -925,7 +925,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = "-fstack-protector"; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; diff --git a/Sources/ShortcutRecorder/SRKeyBindingTransformer.m b/Sources/ShortcutRecorder/SRKeyBindingTransformer.m index 9ca91dc3..4e771e77 100644 --- a/Sources/ShortcutRecorder/SRKeyBindingTransformer.m +++ b/Sources/ShortcutRecorder/SRKeyBindingTransformer.m @@ -3,7 +3,7 @@ // CC BY 4.0 // -#import +#import #import "ShortcutRecorder/SRKeyCodeTransformer.h" @@ -56,7 +56,7 @@ - (SRShortcut *)transformedValue:(NSString *)aValue if (keyCodeString.length != 1) { - os_trace_error("#Error unexpected key symbol"); + os_log_error(OS_LOG_DEFAULT, "#Error unexpected key symbol"); return nil; } @@ -79,7 +79,7 @@ - (SRShortcut *)transformedValue:(NSString *)aValue if (!keyCode) { - os_trace_error("#Error unexpected key symbol"); + os_log_error(OS_LOG_DEFAULT, "#Error unexpected key symbol"); return nil; } @@ -148,14 +148,14 @@ - (NSString *)reverseTransformedValue:(SRShortcut *)aValue { if (![aValue isKindOfClass:NSDictionary.class] && ![aValue isKindOfClass:SRShortcut.class]) { - os_trace_error("#Error invalid class of the value"); + os_log_error(OS_LOG_DEFAULT, "#Error invalid class of the value"); return nil; } NSNumber *keyCode = aValue[SRShortcutKeyKeyCode]; if (![keyCode isKindOfClass:NSNumber.class]) { - os_trace_error("#Error invalid key code"); + os_log_error(OS_LOG_DEFAULT, "#Error invalid key code"); return nil; } @@ -163,7 +163,7 @@ - (NSString *)reverseTransformedValue:(SRShortcut *)aValue if (!keyCodeSymbol) { - os_trace_error("#Error unexpected key code"); + os_log_error(OS_LOG_DEFAULT, "#Error unexpected key code"); return nil; } diff --git a/Sources/ShortcutRecorder/SRKeyCodeTransformer.m b/Sources/ShortcutRecorder/SRKeyCodeTransformer.m index 925ffd96..c16ef8a9 100644 --- a/Sources/ShortcutRecorder/SRKeyCodeTransformer.m +++ b/Sources/ShortcutRecorder/SRKeyCodeTransformer.m @@ -3,8 +3,8 @@ // CC BY 4.0 // -#import #import +#import #import "ShortcutRecorder/SRCommon.h" #import "ShortcutRecorder/SRShortcut.h" @@ -173,7 +173,7 @@ - (nullable NSString *)translateKeyCode:(SRKeyCode)aKeyCode if (!inputSource) { - os_trace_error("#Critical Failed to create an input source"); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to create an input source"); return nil; } @@ -191,7 +191,7 @@ - (nullable NSString *)translateKeyCode:(SRKeyCode)aKeyCode keyCode:aKeyCode]; } else - os_trace_error("#Error Input source misses an ID"); + os_log_error(OS_LOG_DEFAULT, "#Error Input source misses an ID"); } @synchronized (self) @@ -204,11 +204,11 @@ - (nullable NSString *)translateKeyCode:(SRKeyCode)aKeyCode if (translation) { - os_trace_debug("Translation cache hit"); + os_log_debug(OS_LOG_DEFAULT, "Translation cache hit"); return translation; } else - os_trace_debug("Translation cache miss"); + os_log_debug(OS_LOG_DEFAULT, "Translation cache miss"); } CFDataRef layoutData = TISGetInputSourceProperty(inputSource, kTISPropertyUnicodeKeyLayoutData); @@ -228,7 +228,7 @@ - (nullable NSString *)translateKeyCode:(SRKeyCode)aKeyCode chars); if (error != noErr) { - os_trace_error("#Error Unable to translate keyCode %hu and modifierFlags %lu: %d", + os_log_error(OS_LOG_DEFAULT, "#Error Unable to translate keyCode %hu and modifierFlags %lu: %d", aKeyCode, anImplicitModifierFlags, error); @@ -236,7 +236,7 @@ - (nullable NSString *)translateKeyCode:(SRKeyCode)aKeyCode } else if (actualLength == 0) { - os_trace_debug("#Error No translation exists for keyCode %hu and modifierFlags %lu", + os_log_debug(OS_LOG_DEFAULT, "#Error No translation exists for keyCode %hu and modifierFlags %lu", aKeyCode, anImplicitModifierFlags); return nil; @@ -287,7 +287,7 @@ - (NSNumber *)keyCodeForTranslation:(NSString *)aTranslation if (!inputSource) { - os_trace_error("#Critical Failed to create an input source"); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to create an input source"); return nil; } @@ -297,7 +297,7 @@ - (NSNumber *)keyCodeForTranslation:(NSString *)aTranslation if (!sourceIdentifier) { - os_trace_error("#Error Input source misses an ID"); + os_log_error(OS_LOG_DEFAULT, "#Error Input source misses an ID"); return nil; } @@ -306,7 +306,7 @@ - (NSNumber *)keyCodeForTranslation:(NSString *)aTranslation if ([_inputSourceIdentifier isEqualToString:sourceIdentifier]) return _translationToKeyCode[aTranslation]; - os_trace_debug("Updating translation -> key code mapping"); + os_log_debug(OS_LOG_DEFAULT, "Updating translation -> key code mapping"); __auto_type knownKeyCodes = SRKeyCodeTransformer.knownKeyCodes; NSMutableDictionary *newTranslationToKeyCode = [NSMutableDictionary dictionaryWithCapacity:knownKeyCodes.count]; @@ -348,7 +348,7 @@ - (instancetype)init { if (self.class == SRKeyCodeTransformer.class) { - os_trace_error("#Developer #Error Use SRSymbolicKeyCodeTransformer instead"); + os_log_error(OS_LOG_DEFAULT, "#Developer #Error Use SRSymbolicKeyCodeTransformer instead"); return SRSymbolicKeyCodeTransformer.sharedTransformer; } else @@ -359,7 +359,7 @@ - (instancetype)initWithInputSource:(id)anInputSource { if (self.class == SRKeyCodeTransformer.class) { - os_trace_error("#Developer #Error Use SRSymbolicKeyCodeTransformer instead"); + os_log_error(OS_LOG_DEFAULT, "#Developer #Error Use SRSymbolicKeyCodeTransformer instead"); return [[SRSymbolicKeyCodeTransformer alloc] initWithInputSource:anInputSource]; } else @@ -774,7 +774,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue os_activity_initiate("Key Code -> Literal", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid key code"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid key code"); return; } @@ -824,7 +824,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue os_activity_initiate("Key Code -> Symbol", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid key code"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid key code"); return; } @@ -874,7 +874,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue os_activity_initiate("Key Code -> ASCII Literal", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid key code"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid key code"); return; } @@ -900,7 +900,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue os_activity_initiate("ASCII Literal -> Key Code", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSString.class] || !aValue.length) { - os_trace_error("#Error Invalid ASCII literal"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid ASCII literal"); return; } @@ -1111,7 +1111,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue if (!result) { - os_trace_error("#Error Invalid value for reverse transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for reverse transformation"); } return result; @@ -1154,7 +1154,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue os_activity_initiate("Key Code -> ASCII Symbol", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid key code"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid key code"); return; } @@ -1180,7 +1180,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue os_activity_initiate("ASCII Symbol -> Key Code", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (![aValue isKindOfClass:NSString.class] || aValue.length > 1) { - os_trace_error("#Error Invalid ASCII symbol"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid ASCII symbol"); return; } @@ -1336,7 +1336,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue }); if (!result) - os_trace_error("#Error Invalid value for reverse transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for reverse transformation"); return result; } diff --git a/Sources/ShortcutRecorder/SRModifierFlagsTransformer.m b/Sources/ShortcutRecorder/SRModifierFlagsTransformer.m index 867a787f..c0b48f4a 100644 --- a/Sources/ShortcutRecorder/SRModifierFlagsTransformer.m +++ b/Sources/ShortcutRecorder/SRModifierFlagsTransformer.m @@ -3,7 +3,7 @@ // CC BY 4.0 // -#import +#import #import "ShortcutRecorder/SRCommon.h" @@ -66,7 +66,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue layoutDirection:(NSUserInterfa { if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid value for transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for transformation"); return nil; } @@ -117,7 +117,7 @@ - (NSString *)transformedValue:(NSNumber *)aValue layoutDirection:(NSUserInterfa { if (![aValue isKindOfClass:NSNumber.class]) { - os_trace_error("#Error Invalid value for transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for transformation"); return nil; } @@ -146,7 +146,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue { if (![aValue isKindOfClass:NSString.class]) { - os_trace_error("#Error Invalid value for reverse transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for reverse transformation"); return nil; } @@ -174,7 +174,7 @@ - (NSNumber *)reverseTransformedValue:(NSString *)aValue if (foundInvalidSubstring) { - os_trace_error("#Error Invalid value for reverse transformation"); + os_log_error(OS_LOG_DEFAULT, "#Error Invalid value for reverse transformation"); return nil; } diff --git a/Sources/ShortcutRecorder/SRRecorderControl.m b/Sources/ShortcutRecorder/SRRecorderControl.m index 48fbb543..246e1303 100644 --- a/Sources/ShortcutRecorder/SRRecorderControl.m +++ b/Sources/ShortcutRecorder/SRRecorderControl.m @@ -5,8 +5,8 @@ #import #import -#import #import +#import #import "ShortcutRecorder/SRShortcutAction.h" #import "ShortcutRecorder/SRKeyCodeTransformer.h" @@ -755,12 +755,12 @@ - (void)drawBackground:(NSRect)aDirtyRect if (left && center && right) { - os_trace_debug("#Developer drawing background using images"); - NSDrawThreePartImage(backgroundFrame, left, center, right, NO, NSCompositeSourceOver, 1.0, self.isFlipped); + os_log_debug(OS_LOG_DEFAULT, "#Developer drawing background using images"); + NSDrawThreePartImage(backgroundFrame, left, center, right, NO, NSCompositingOperationSourceOver, 1.0, self.isFlipped); } else { - os_trace_debug("#Developer drawing background using color"); + os_log_debug(OS_LOG_DEFAULT, "#Developer drawing background using color"); if (self.isOpaque) [NSColor.windowBackgroundColor setFill]; @@ -848,7 +848,7 @@ - (void)drawCancelButton:(NSRect)aDirtyRect return; [NSGraphicsContext saveGraphicsState]; - [image drawInRect:cancelButtonFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; + [image drawInRect:cancelButtonFrame fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES hints:nil]; [NSGraphicsContext restoreGraphicsState]; } @@ -872,7 +872,7 @@ - (void)drawClearButton:(NSRect)aDirtyRect return; [NSGraphicsContext saveGraphicsState]; - [image drawInRect:clearButtonFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; + [image drawInRect:clearButtonFrame fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES hints:nil]; [NSGraphicsContext restoreGraphicsState]; } @@ -974,7 +974,7 @@ - (void)propagateValue:(id)aValue forBinding:(NSString *)aBinding ([boundObject isKindOfClass:NSUserDefaults.class] || [boundObject isKindOfClass:NSUserDefaultsController.class]) && [aValue isKindOfClass:SRShortcut.class]) { - os_trace_error("#Error The control is bound to NSUserDefaults but is not transformed into an allowed CFPreferences value"); + os_log_error(OS_LOG_DEFAULT, "#Error The control is bound to NSUserDefaults but is not transformed into an allowed CFPreferences value"); NSLog(@"WARNING: Shortcut Recroder 2 compatibility mode enabled. Getters of objectValue and NSValueBinding will return an instance of NSDictionary."); _isCompatibilityModeEnabled = YES; @@ -1009,17 +1009,17 @@ - (BOOL)canCaptureKeyEvent { if (!self.enabled) { - os_trace_debug("The control is disabled"); + os_log_debug(OS_LOG_DEFAULT, "The control is disabled"); return NO; } else if (self.window.firstResponder != self) { - os_trace_debug("The control is not the first responder"); + os_log_debug(OS_LOG_DEFAULT, "The control is not the first responder"); return NO; } else if (self->_mouseTrackingButtonTag != _SRRecorderControlInvalidButtonTag) { - os_trace_debug("The control is tracking %lu", self->_mouseTrackingButtonTag); + os_log_debug(OS_LOG_DEFAULT, "The control is tracking %lu", self->_mouseTrackingButtonTag); return NO; } else @@ -1049,18 +1049,18 @@ - (BOOL)canEndRecordingWithObjectValue:(nullable SRShortcut *)aShortcut { if (DelegateCanRecordShortcut(aShortcut)) { - os_trace_debug("Valid and accepted shortcut"); + os_log_debug(OS_LOG_DEFAULT, "Valid and accepted shortcut"); result = YES; } else { - os_trace_debug("Delegate rejected"); + os_log_debug(OS_LOG_DEFAULT, "Delegate rejected"); result = NO; } } else { - os_trace_debug("Modifier flags %lu rejected", aShortcut.modifierFlags); + os_log_debug(OS_LOG_DEFAULT, "Modifier flags %lu rejected", aShortcut.modifierFlags); result = NO; } }); @@ -1737,14 +1737,14 @@ - (BOOL)performKeyEquivalent:(NSEvent *)anEvent { // This shouldn't really happen ever, but was rarely observed. // See https://github.com/Kentzo/ShortcutRecorder/issues/40 - os_trace_debug("Invalid key code"); + os_log_debug(OS_LOG_DEFAULT, "Invalid key code"); result = NO; } else if (self.allowsEscapeToCancelRecording && anEvent.keyCode == SRKeyCodeEscape && (anEvent.modifierFlags & SRCocoaModifierFlagsMask) == 0) { - os_trace_debug("Cancel via Esc"); + os_log_debug(OS_LOG_DEFAULT, "Cancel via Esc"); [self endRecording]; result = YES; } @@ -1752,7 +1752,7 @@ - (BOOL)performKeyEquivalent:(NSEvent *)anEvent (anEvent.keyCode == SRKeyCodeDelete || anEvent.keyCode == SRKeyCodeForwardDelete) && (anEvent.modifierFlags & SRCocoaModifierFlagsMask) == 0) { - os_trace_debug("Clear via Delete"); + os_log_debug(OS_LOG_DEFAULT, "Clear via Delete"); [self clearAndEndRecording]; result = YES; } @@ -1773,7 +1773,7 @@ - (BOOL)performKeyEquivalent:(NSEvent *)anEvent } else if (anEvent.keyCode == SRKeyCodeSpace) { - os_trace_debug("Begin recording via Space"); + os_log_debug(OS_LOG_DEFAULT, "Begin recording via Space"); result = [self beginRecording]; } else diff --git a/Sources/ShortcutRecorder/SRRecorderControlStyle.m b/Sources/ShortcutRecorder/SRRecorderControlStyle.m index cfc47a01..5970ac0a 100644 --- a/Sources/ShortcutRecorder/SRRecorderControlStyle.m +++ b/Sources/ShortcutRecorder/SRRecorderControlStyle.m @@ -3,8 +3,8 @@ // CC BY 4.0 // -#import #import +#import #import "ShortcutRecorder/SRRecorderControl.h" #import "ShortcutRecorder/SRRecorderControlStyle.h" @@ -320,8 +320,6 @@ - (NSComparisonResult)compare:(SRRecorderControlStyleComponents *)anOtherCompone relativeToComponents:(SRRecorderControlStyleComponents *)anIdealComponents { static NSDictionary *> *AppearanceOrderMap = nil; - static NSDictionary *> *TintOrderMap = nil; - static NSDictionary *> *DirectionOrderMap = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ AppearanceOrderMap = @{ @@ -346,22 +344,6 @@ - (NSComparisonResult)compare:(SRRecorderControlStyleComponents *)anOtherCompone @(SRRecorderControlStyleComponentsAppearanceAqua), @(SRRecorderControlStyleComponentsAppearanceUnspecified)] }; - - TintOrderMap = @{ - @(SRRecorderControlStyleComponentsTintBlue): @[@(SRRecorderControlStyleComponentsTintBlue), - @(SRRecorderControlStyleComponentsTintGraphite), - @(SRRecorderControlStyleComponentsTintUnspecified)], - @(SRRecorderControlStyleComponentsTintGraphite): @[@(SRRecorderControlStyleComponentsTintGraphite), - @(SRRecorderControlStyleComponentsTintBlue), - @(SRRecorderControlStyleComponentsTintUnspecified)] - }; - - DirectionOrderMap = @{ - @(SRRecorderControlStyleComponentsLayoutDirectionLeftToRight): @[@(SRRecorderControlStyleComponentsLayoutDirectionLeftToRight), - @(SRRecorderControlStyleComponentsLayoutDirectionRightToLeft)], - @(SRRecorderControlStyleComponentsLayoutDirectionRightToLeft): @[@(SRRecorderControlStyleComponentsLayoutDirectionRightToLeft), - @(SRRecorderControlStyleComponentsLayoutDirectionLeftToRight)] - }; }); __auto_type CompareEnum = ^(NSUInteger a, NSUInteger b, NSArray *order) { @@ -718,9 +700,7 @@ - (instancetype)init __block NSDictionary *info = nil; os_activity_initiate("-[SRRecorderControlStyleResourceLoader infoForStyle:]", OS_ACTIVITY_FLAG_DEFAULT, (^{ - os_trace_debug_with_payload("Fetching info", ^(xpc_object_t d) { - xpc_dictionary_set_string(d, "identifier", aStyle.identifier.UTF8String); - }); + os_log_debug(OS_LOG_DEFAULT, "Fetching info: identifier: %s", aStyle.identifier.UTF8String); @synchronized (self) { @@ -728,7 +708,7 @@ - (instancetype)init if (!info) { - os_trace_debug("Info is not in cache"); + os_log_debug(OS_LOG_DEFAULT, "Info is not in cache"); NSString *resourceName = [NSString stringWithFormat:@"%@-info", aStyle.identifier]; NSData *data = [[NSDataAsset alloc] initWithName:resourceName bundle:SRBundle()].data; @@ -786,7 +766,7 @@ - (instancetype)init [self->_cache setObject:info forKey:aStyle.identifier]; } else - os_trace_debug("Info is in cache"); + os_log_debug(OS_LOG_DEFAULT, "Info is in cache"); } })); @@ -797,9 +777,7 @@ - (instancetype)init { __block NSArray *lookupPrefixes = nil; os_activity_initiate("-[SRRecorderControlStyleResourceLoader lookupPrefixesForStyle:]", OS_ACTIVITY_FLAG_DEFAULT, (^{ - os_trace_debug_with_payload("Fetching lookup prefixes", ^(xpc_object_t d) { - xpc_dictionary_set_string(d, "identifier", aStyle.identifier.UTF8String); - }); + os_log_debug(OS_LOG_DEFAULT, "Fetching lookup prefixes: identifier: %s", aStyle.identifier.UTF8String); @synchronized (self) { @@ -811,7 +789,7 @@ - (instancetype)init if (!lookupPrefixes) { - os_trace_debug("Lookup prefixes are not in cache"); + os_log_debug(OS_LOG_DEFAULT, "Lookup prefixes are not in cache"); SRRecorderControlStyleComponents *effectiveComponents = aStyle.effectiveComponents; NSComparator cmp = ^NSComparisonResult(SRRecorderControlStyleComponents *a, SRRecorderControlStyleComponents *b) { return [a compare:b relativeToComponents:effectiveComponents]; @@ -827,7 +805,7 @@ - (instancetype)init [self->_cache setObject:lookupPrefixes forKey:key]; } else - os_trace_debug("Lookup prefixes are in cache"); + os_log_debug(OS_LOG_DEFAULT, "Lookup prefixes are in cache"); } })); @@ -838,10 +816,7 @@ - (NSImage *)imageNamed:(NSString *)aName forStyle:(SRRecorderControlStyle *)aSt { __block NSImage *image = nil; os_activity_initiate("-[SRRecorderControlStyleResourceLoader imageNamed:forStyle:]", OS_ACTIVITY_FLAG_DEFAULT, (^{ - os_trace_debug_with_payload("Fetching image name", ^(xpc_object_t d) { - xpc_dictionary_set_string(d, "identifier", aStyle.identifier.UTF8String); - xpc_dictionary_set_string(d, "image", aName.UTF8String); - }); + os_log_debug(OS_LOG_DEFAULT, "Fetching image name: identifier: %s image: %s", aStyle.identifier.UTF8String, aName.UTF8String); @synchronized (self) { @@ -853,7 +828,7 @@ - (NSImage *)imageNamed:(NSString *)aName forStyle:(SRRecorderControlStyle *)aSt if (!imageNameCache) { - os_trace_debug("Image name is not in cache"); + os_log_debug(OS_LOG_DEFAULT, "Image name is not in cache"); NSString *imageName = nil; BOOL usesSRImage = YES; @@ -883,7 +858,7 @@ - (NSImage *)imageNamed:(NSString *)aName forStyle:(SRRecorderControlStyle *)aSt } else { - os_trace_debug("Image name is in cache"); + os_log_debug(OS_LOG_DEFAULT, "Image name is in cache"); NSString *imageName = imageNameCache[0]; BOOL usesSRImage = [imageNameCache[1] boolValue]; diff --git a/Sources/ShortcutRecorder/SRShortcut.m b/Sources/ShortcutRecorder/SRShortcut.m index c23e340f..0a182cc8 100644 --- a/Sources/ShortcutRecorder/SRShortcut.m +++ b/Sources/ShortcutRecorder/SRShortcut.m @@ -3,7 +3,7 @@ // CC BY 4.0 // -#import +#import #import "ShortcutRecorder/SRCommon.h" #import "ShortcutRecorder/SRKeyCodeTransformer.h" @@ -43,7 +43,7 @@ + (instancetype)shortcutWithEvent:(NSEvent *)aKeyboardEvent ignoringCharacters:( __auto_type eventType = aKeyboardEvent.type; if (((1 << eventType) & (NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged)) == 0) { - os_trace_error("#Error aKeyboardEvent must be either NSEventTypeKeyUp, NSEventTypeKeyDown or NSEventTypeFlagsChanged, but got %lu", aKeyboardEvent.type); + os_log_error(OS_LOG_DEFAULT, "#Error aKeyboardEvent must be either NSEventTypeKeyUp, NSEventTypeKeyDown or NSEventTypeFlagsChanged, but got %lu", aKeyboardEvent.type); return nil; } @@ -80,7 +80,7 @@ + (instancetype)shortcutWithEvent:(NSEvent *)aKeyboardEvent ignoringCharacters:( if (!NSThread.isMainThread) { NSParameterAssert(NO); - os_trace_error("#Error #Developer AppKit failed to extract characters because it is used in a non-main thread, see SRShortcut/shortcutWithEvent:ignoringCharacters:"); + os_log_error(OS_LOG_DEFAULT, "#Error #Developer AppKit failed to extract characters because it is used in a non-main thread, see SRShortcut/shortcutWithEvent:ignoringCharacters:"); } else @throw; @@ -427,8 +427,11 @@ - (void)encodeWithCoder:(NSCoder *)aCoder + (instancetype)new { +#ifndef __clang_analyzer__ + // Suppress static analyzer warning [self doesNotRecognizeSelector:_cmd]; return nil; +#endif } - (instancetype)init @@ -470,7 +473,7 @@ @implementation SRShortcut (Carbon) - (UInt32)carbonKeyCode { if (self.keyCode == SRKeyCodeNone) - os_trace_error("#Critical SRKeyCodeNone has no representation in Carbon"); + os_log_error(OS_LOG_DEFAULT, "#Critical SRKeyCodeNone has no representation in Carbon"); return self.keyCode; } @@ -499,7 +502,7 @@ - (UInt32)carbonModifierFlags case SRKeyCodeF18: case SRKeyCodeF19: case SRKeyCodeF20: - return SRCocoaToCarbonFlags(self.modifierFlags) | NSFunctionKeyMask; + return SRCocoaToCarbonFlags(self.modifierFlags) | NSEventModifierFlagFunction; default: return SRCocoaToCarbonFlags(self.modifierFlags); } diff --git a/Sources/ShortcutRecorder/SRShortcutAction.m b/Sources/ShortcutRecorder/SRShortcutAction.m index 67dd603a..a271a9ab 100644 --- a/Sources/ShortcutRecorder/SRShortcutAction.m +++ b/Sources/ShortcutRecorder/SRShortcutAction.m @@ -4,8 +4,8 @@ // #import -#import #import +#import #import "ShortcutRecorder/SRCommon.h" @@ -229,7 +229,7 @@ - (BOOL)performActionOnTarget:(id)aTarget os_activity_initiate("-[SRShortcutAction performActionOnTarget:]", OS_ACTIVITY_FLAG_DEFAULT, ^{ if (!self.isEnabled) { - os_trace_debug("Not performed: disabled"); + os_log_debug(OS_LOG_DEFAULT, "Not performed: disabled"); return; } @@ -237,7 +237,7 @@ - (BOOL)performActionOnTarget:(id)aTarget if (actionHandler) { - os_trace_debug("Using action handler"); + os_log_debug(OS_LOG_DEFAULT, "Using action handler"); isPerformed = actionHandler(self); } else @@ -245,7 +245,7 @@ - (BOOL)performActionOnTarget:(id)aTarget id target = aTarget != nil ? aTarget : self.target; if (!target) { - os_trace_debug("Not performed: no associated target"); + os_log_debug(OS_LOG_DEFAULT, "Not performed: no associated target"); return; } @@ -255,18 +255,18 @@ - (BOOL)performActionOnTarget:(id)aTarget BOOL canPerformProtocol = NO; if (!(canPerformAction = action && [target respondsToSelector:action]) && !(canPerformProtocol = [target respondsToSelector:@selector(performShortcutAction:)])) { - os_trace_debug("Not performed: target cannot respond to action"); + os_log_debug(OS_LOG_DEFAULT, "Not performed: target cannot respond to action"); return; } else if ([target respondsToSelector:@selector(validateUserInterfaceItem:)] && ![target validateUserInterfaceItem:self]) { - os_trace_debug("Not performed: target ignored action"); + os_log_debug(OS_LOG_DEFAULT, "Not performed: target ignored action"); return; } if (canPerformAction) { - os_trace_debug("Using action"); + os_log_debug(OS_LOG_DEFAULT, "Using action"); NSMethodSignature *sig = [target methodSignatureForSelector:action]; IMP actionMethod = [target methodForSelector:action]; BOOL returnsBool = strncmp(sig.methodReturnType, @encode(BOOL), 2) == 0; @@ -300,7 +300,7 @@ - (BOOL)performActionOnTarget:(id)aTarget } else if (canPerformProtocol) { - os_trace_debug("Using protocol"); + os_log_debug(OS_LOG_DEFAULT, "Using protocol"); isPerformed = [(id)target performShortcutAction:self]; } } @@ -397,7 +397,7 @@ + (SRKeyEventType)SR_keyEventTypeForEventType:(NSEventType)anEventType else if (keyCode == kVK_Control || keyCode == kVK_RightControl) eventType = modifierFlags & NSEventModifierFlagControl ? SRKeyEventTypeDown : SRKeyEventTypeUp; else - os_trace("#Error Unexpected key code %hu for the FlagsChanged event", keyCode); + os_log_error(OS_LOG_DEFAULT, "#Error Unexpected key code %hu for the FlagsChanged event", keyCode); break; } default: @@ -966,12 +966,12 @@ static OSStatus _SRCarbonEventHandler(EventHandlerCallRef aHandler, EventRef anE { if (!anEvent) { - os_trace_error("#Error Event is NULL"); + os_log_error(OS_LOG_DEFAULT, "#Error Event is NULL"); return eventNotHandledErr; } else if (GetEventClass(anEvent) != kEventClassKeyboard) { - os_trace_error("#Error Not a keyboard event"); + os_log_error(OS_LOG_DEFAULT, "#Error Not a keyboard event"); return eventNotHandledErr; } else @@ -1017,7 +1017,7 @@ - (void)resume { @synchronized (_actions) { - os_trace_debug("Global Shortcut Monitor counter: %ld -> %ld", _disableCounter, _disableCounter - 1); + os_log_debug(OS_LOG_DEFAULT, "Global Shortcut Monitor counter: %ld -> %ld", _disableCounter, _disableCounter - 1); _disableCounter -= 1; if (_disableCounter == 0) @@ -1034,7 +1034,7 @@ - (void)pause { @synchronized (_actions) { - os_trace_debug("Global Shortcut Monitor counter: %ld -> %ld", _disableCounter, _disableCounter + 1); + os_log_debug(OS_LOG_DEFAULT, "Global Shortcut Monitor counter: %ld -> %ld", _disableCounter, _disableCounter + 1); _disableCounter += 1; if (_disableCounter == 1) @@ -1054,19 +1054,19 @@ - (OSStatus)handleEvent:(EventRef)anEvent os_activity_initiate("-[SRGlobalShortcutMonitor handleEvent:]", OS_ACTIVITY_FLAG_DETACHED, ^{ if (self->_disableCounter > 0) { - os_trace_debug("Monitoring is currently disabled"); + os_log_debug(OS_LOG_DEFAULT, "Monitoring is currently disabled"); return; } EventHotKeyID hotKeyID; if (GetEventParameter(anEvent, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(hotKeyID), NULL, &hotKeyID) != noErr) { - os_trace_error("#Critical Failed to get hot key ID: %d", error); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to get hot key ID: %d", error); return; } else if (hotKeyID.id == 0 || hotKeyID.signature != SRShortcutActionSignature) { - os_trace_error("#Error Unexpected hot key with id %u and signature: %u", hotKeyID.id, hotKeyID.signature); + os_log_error(OS_LOG_DEFAULT, "#Error Unexpected hot key with id %u and signature: %u", hotKeyID.id, hotKeyID.signature); return; } @@ -1076,7 +1076,7 @@ - (OSStatus)handleEvent:(EventRef)anEvent if (!shortcut) { - os_trace("Unregistered hot key with id %u and signature %u", hotKeyID.id, hotKeyID.signature); + os_log_error(OS_LOG_DEFAULT, "Unregistered hot key with id %u and signature %u", hotKeyID.id, hotKeyID.signature); return; } @@ -1090,7 +1090,7 @@ - (OSStatus)handleEvent:(EventRef)anEvent eventType = SRKeyEventTypeUp; break; default: - os_trace("#Error Unexpected key event of type %u", GetEventKind(anEvent)); + os_log_error(OS_LOG_DEFAULT, "#Error Unexpected key event of type %u", GetEventKind(anEvent)); return; } @@ -1098,7 +1098,7 @@ - (OSStatus)handleEvent:(EventRef)anEvent if (!actions.count) { - os_trace("No actions for the shortcut"); + os_log_error(OS_LOG_DEFAULT, "No actions for the shortcut"); return; } @@ -1120,12 +1120,12 @@ - (OSStatus)handleEvent:(EventRef)anEvent - (void)didAddEventHandler { - os_trace_debug("Added Carbon HotKey Event Handler"); + os_log_debug(OS_LOG_DEFAULT, "Added Carbon HotKey Event Handler"); } - (void)didRemoveEventHandler { - os_trace_debug("Removed Carbon HotKey Event Handler"); + os_log_debug(OS_LOG_DEFAULT, "Removed Carbon HotKey Event Handler"); } #pragma mark Private @@ -1142,7 +1142,7 @@ - (void)_installEventHandlerIfNeeded { kEventClassKeyboard, kEventHotKeyPressed }, { kEventClassKeyboard, kEventHotKeyReleased } }; - os_trace("Installing Carbon hot key event handler"); + os_log_error(OS_LOG_DEFAULT, "Installing Carbon hot key event handler"); OSStatus error = InstallEventHandler(GetEventDispatcherTarget(), _SRCarbonEventHandler, sizeof(EventSpec) / sizeof(EventTypeSpec), @@ -1152,7 +1152,7 @@ - (void)_installEventHandlerIfNeeded if (error != noErr) { - os_trace_error("#Critical Failed to install event handler: %d", error); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to install event handler: %d", error); _carbonEventHandler = NULL; } else @@ -1167,11 +1167,11 @@ - (void)_removeEventHandlerIfNeeded if (_disableCounter <= 0 && _shortcutToHotKeyRef.count) return; - os_trace("Removing Carbon hot key event handler"); + os_log_error(OS_LOG_DEFAULT, "Removing Carbon hot key event handler"); OSStatus error = RemoveEventHandler(_carbonEventHandler); if (error != noErr) - os_trace_error("#Error Failed to remove event handler: %d", error); + os_log_error(OS_LOG_DEFAULT, "#Error Failed to remove event handler: %d", error); // Assume that an error happened due to _carbonEventHandler being invalid. _carbonEventHandler = NULL; @@ -1187,13 +1187,13 @@ - (void)_registerHotKeyForShortcutIfNeeded:(SRShortcut *)aShortcut if (aShortcut.keyCode == SRKeyCodeNone) { - os_trace_error("#Error Shortcut without a key code cannot be registered as Carbon hot key"); + os_log_error(OS_LOG_DEFAULT, "#Error Shortcut without a key code cannot be registered as Carbon hot key"); return; } static UInt32 CarbonID = _SRInvalidHotKeyID; EventHotKeyID hotKeyID = {SRShortcutActionSignature, ++CarbonID}; - os_trace("Registering Carbon hot key"); + os_log_error(OS_LOG_DEFAULT, "Registering Carbon hot key"); OSStatus error = RegisterEventHotKey(aShortcut.carbonKeyCode, aShortcut.carbonModifierFlags, hotKeyID, @@ -1203,17 +1203,11 @@ - (void)_registerHotKeyForShortcutIfNeeded:(SRShortcut *)aShortcut if (error != noErr || !hotKey) { - os_trace_error_with_payload("#Critical Failed to register Carbon hot key: %d", error, ^(xpc_object_t d) { - xpc_dictionary_set_uint64(d, "keyCode", aShortcut.keyCode); - xpc_dictionary_set_uint64(d, "modifierFlags", aShortcut.modifierFlags); - }); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to register Carbon hot key: %d, keyCode: %lu, modifierFlags: %lu", error, (unsigned long)aShortcut.keyCode, (unsigned long)aShortcut.modifierFlags); return; } - os_trace_with_payload("Registered Carbon hot key %u", hotKeyID.id, ^(xpc_object_t d) { - xpc_dictionary_set_uint64(d, "keyCode", aShortcut.keyCode); - xpc_dictionary_set_uint64(d, "modifierFlags", aShortcut.modifierFlags); - }); + os_log_debug(OS_LOG_DEFAULT, "Registered Carbon hot key %u, keyCode: %lu, modifierFlags: %lu", hotKeyID.id, (unsigned long)aShortcut.keyCode, (unsigned long)aShortcut.modifierFlags); [_shortcutToHotKeyRef setObject:(__bridge id _Nullable)(hotKey) forKey:aShortcut]; [_hotKeyIdToShortcut setObject:aShortcut forKey:@(hotKeyID.id)]; @@ -1229,22 +1223,16 @@ - (void)_unregisterHotKeyForShortcutIfNeeded:(SRShortcut *)aShortcut UInt32 hotKeyID = [_shortcutToHotKeyId objectForKey:aShortcut].unsignedIntValue; - os_trace("Removing Carbon hot key %u", hotKeyID); + os_log_error(OS_LOG_DEFAULT, "Removing Carbon hot key %u", hotKeyID); OSStatus error = UnregisterEventHotKey(hotKey); if (error != noErr) { - os_trace_error_with_payload("#Critical Failed to unregister Carbon hot key %u: %d", hotKeyID, error, ^(xpc_object_t d) { - xpc_dictionary_set_uint64(d, "keyCode", aShortcut.keyCode); - xpc_dictionary_set_uint64(d, "modifierFlags", aShortcut.modifierFlags); - }); + os_log_error(OS_LOG_DEFAULT, "#Critical Failed to unregister Carbon hot key %u, keyCode: %lu, modifierFlags: %lu: %d", hotKeyID, (unsigned long)aShortcut.keyCode, (unsigned long)aShortcut.modifierFlags, error); } else { - os_trace_with_payload("Unregistered Carbon hot key %u", hotKeyID, ^(xpc_object_t d) { - xpc_dictionary_set_uint64(d, "keyCode", aShortcut.keyCode); - xpc_dictionary_set_uint64(d, "modifierFlags", aShortcut.modifierFlags); - }); + os_log_debug(OS_LOG_DEFAULT, "Unregistered Carbon hot key %u, keyCode: %lu, modifierFlags: %lu", hotKeyID, (unsigned long)aShortcut.keyCode, (unsigned long)aShortcut.modifierFlags); } // Assume that an error to unregister the handler is due to the latter being invalid. @@ -1281,13 +1269,13 @@ CGEventRef _Nullable _SRQuartzEventHandler(CGEventTapProxy aProxy, CGEventType a if (aType == kCGEventTapDisabledByTimeout || aType == kCGEventTapDisabledByUserInput) { - os_trace_error("#Error #Developer The system disabled event tap due to %u", aType); + os_log_error(OS_LOG_DEFAULT, "#Error #Developer The system disabled event tap due to %u", aType); CGEventTapEnable(self.eventTap, true); return anEvent; } else if (aType != kCGEventKeyDown && aType != kCGEventKeyUp && aType != kCGEventFlagsChanged) { - os_trace_error("#Error #Developer Unexpected event of type %u", aType); + os_log_error(OS_LOG_DEFAULT, "#Error #Developer Unexpected event of type %u", aType); return anEvent; } else @@ -1317,7 +1305,7 @@ - (instancetype)initWithRunLoop:(NSRunLoop *)aRunLoop tapOptions:(CGEventTapOpti (__bridge void *)self); if (!eventTap) { - os_trace_error("#Critical Unable to create event tap: make sure Accessibility is enabled"); + os_log_error(OS_LOG_DEFAULT, "#Critical Unable to create event tap: make sure Accessibility is enabled"); return nil; } @@ -1389,7 +1377,7 @@ - (CGEventRef)handleEvent:(CGEventRef)anEvent }); if (!result && !_canActivelyFilterEvents) - os_trace_error("#Developer #Error The monitor is not configured to actively filter events"); + os_log_error(OS_LOG_DEFAULT, "#Developer #Error The monitor is not configured to actively filter events"); return result; } @@ -1590,7 +1578,7 @@ - (BOOL)handleEvent:(NSEvent *)anEvent withTarget:(nullable id)aTarget SRShortcut *shortcut = [SRShortcut shortcutWithEvent:anEvent ignoringCharacters:YES]; if (!shortcut) { - os_trace_error("#Error Not a keyboard event"); + os_log_error(OS_LOG_DEFAULT, "#Error Not a keyboard event"); return NO; } @@ -1661,9 +1649,7 @@ - (void)updateWithCocoaTextKeyBindings systemKeyBindings = [NSDictionary dictionaryWithContentsOfURL:systemKeyBindingsURL error:&error]; if (!systemKeyBindings) { - os_trace_error_with_payload("#Error unable to read system key bindings", ^(xpc_object_t d) { - xpc_dictionary_set_string(d, "error", error.localizedDescription.UTF8String); - }); + os_log_error(OS_LOG_DEFAULT, "#Error unable to read system key bindings: %s", error.localizedDescription.UTF8String); systemKeyBindings = @{}; } } @@ -1672,7 +1658,7 @@ - (void)updateWithCocoaTextKeyBindings systemKeyBindings = [NSDictionary dictionaryWithContentsOfURL:systemKeyBindingsURL]; if (!systemKeyBindings) { - os_trace_error("#Error unable to read system key bindings"); + os_log_error(OS_LOG_DEFAULT, "#Error unable to read system key bindings"); systemKeyBindings = @{}; } } @@ -1691,9 +1677,7 @@ - (void)updateWithCocoaTextKeyBindings userKeyBindings = [NSDictionary dictionaryWithContentsOfURL:userKeyBindingsURL error:&error]; if (!userKeyBindings) { - os_trace_debug_with_payload("#Error unable to read user key bindings", ^(xpc_object_t d) { - xpc_dictionary_set_string(d, "error", error.localizedDescription.UTF8String); - }); + os_log_debug(OS_LOG_DEFAULT, "#Error unable to read user key bindings: %s", error.localizedDescription.UTF8String); userKeyBindings = @{}; } } @@ -1702,7 +1686,7 @@ - (void)updateWithCocoaTextKeyBindings userKeyBindings = [NSDictionary dictionaryWithContentsOfURL:userKeyBindingsURL]; if (!userKeyBindings) { - os_trace_debug("#Error unable to read user key bindings"); + os_log_debug(OS_LOG_DEFAULT, "#Error unable to read user key bindings"); userKeyBindings = @{}; } } diff --git a/Sources/ShortcutRecorder/SRShortcutValidator.m b/Sources/ShortcutRecorder/SRShortcutValidator.m index a7785c0c..0e30b862 100644 --- a/Sources/ShortcutRecorder/SRShortcutValidator.m +++ b/Sources/ShortcutRecorder/SRShortcutValidator.m @@ -3,8 +3,8 @@ // CC BY 4.0 // -#import #import +#import #import "ShortcutRecorder/SRCommon.h" #import "ShortcutRecorder/SRKeyCodeTransformer.h" @@ -142,7 +142,7 @@ - (BOOL)validateShortcutAgainstSystemShortcuts:(SRShortcut *)aShortcut error:(NS if (err != noErr) { - os_trace_error("#Error Unable to read System Shortcuts: %d", err); + os_log_error(OS_LOG_DEFAULT, "#Error Unable to read System Shortcuts: %d", err); result = NO; return; }