ShortcutRecorder icon indicating copy to clipboard operation
ShortcutRecorder copied to clipboard

Indentation cleanup

Open JanX2 opened this issue 4 years ago • 3 comments

I think I caught the last remaining tab character.

JanX2 avatar Dec 30 '21 13:12 JanX2

@JanX2 Ah, When saw in my email I first thought about some edge-case key combination on rare locale with some mysterious input method :) Happy NYE!

Kentzo avatar Dec 30 '21 21:12 Kentzo

@Kentzo Thank you! To you and yours as well.

A bit off topic: I’m still trying to figure out how to do menu item shortcuts with the recent versions. Do you have any pointers? Any code that does this? I keep running into issues with bindings that I can’t seem to be able to figure out.

This is what I’ve been doing with the 2017 version of the framework: https://github.com/JanX2/Play/blob/64-bit-prep/Preferences/HotKeyPreferencesController.m https://github.com/JanX2/Play/blob/64-bit-prep/Application/PlayApplicationDelegate.m https://github.com/JanX2/Play/blob/64-bit-prep/English.lproj/HotKeyPreferences.xib

One of my main issues currently is that the new persistence format in defaults is different and I need to find a way to bridge the old format to new somehow. When a user launches the a new version of the app for the first time there are crashes/exceptions due to this.

The other is how to properly bind the customized shortcut and set it on a menu item.

Also there are a great many API changes and sometimes the behavior has changed as well.

From the git history I have understood that -pausesGlobalShortcutMonitorWhileRecording is now the default behavior. So we don’t need to do that manually anymore.

SRValidatorDelegate -> SRShortcutValidatorDelegate flags unsigned int -> NSEventModifierFlags SRValidator -> SRShortcutValidator shortcutRecorder:… -> recorderControl:… key code unsigned short -> SRKeyCode shortcut taken… -> shortcut valid with inversion of meaning of boolean value

Additionally, it looks like, as of macOS 10.14, this is now the correct transformer for the bindings to defaults: NSSecureUnarchiveFromData. So the binding options should probably look something like this:

NSDictionary *options;
if (@available(macOS 10.14, *)) {
	options = @{NSValueTransformerNameBindingOption: NSSecureUnarchiveFromDataTransformerName};
} else {
	options = @{NSValueTransformerNameBindingOption: NSKeyedUnarchiveFromDataTransformerName};
}

JanX2 avatar Dec 31 '21 10:12 JanX2

One of my main issues currently is that the new persistence format in defaults is different and I need to find a way to bridge the old format to new somehow.

Do you mean old-style dictionary vs SRShortcut?

You should be able to bind old-style dictionary to SRRecorderControl and it should just work in the compatibility mode. SRKeyEquivalentTransformer and SRKeyEquivalentModifierMaskTransformer (the ones you should use when binding Cocoa's keyEquivalents <-> NSUserDefaults) should be able to read and transform old-style serialized dictionary as well.

The other is how to properly bind the customized shortcut and set it on a menu item.

I suggest to migrate values in defaults to new SRShortcut some time very early in your app (before bindings are set up). The same transformers should be used for Cocoa Bindings

From the git history I have understood that -pausesGlobalShortcutMonitorWhileRecording is now the default behavior. So we don’t need to do that manually anymore.

Yup.

Additionally, it looks like, as of macOS 10.14, this is now the correct transformer for the bindings to defaults: NSSecureUnarchiveFromData.

Seems reasonable. Could you add a test to the suite that verifies that data previously written via NSKeyedUnarchiveFromDataTransformerName can be read via NSSecureUnarchiveFromDataTransformerName and vice versa?

IIRC if you specify options as nil, the appropriate transformation (keyed or keyed secure) will be done by NSUserDefaultsController regardless. You can verify that by putting a breakpoint inside SRShortcut's -initWithCoder: and -encodeWithCoder: and inspecting the passed object.

Also there are a great many API changes and sometimes the behavior has changed as well.

Let me know what workflow you need help with.

Kentzo avatar Jan 05 '22 20:01 Kentzo