From 9b85081bae9d53eb7b580e744f145fb69bfba4c0 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 27 Dec 2019 12:34:31 +0100 Subject: [PATCH] Switch our defaults around so that Hammerspoon runs with its dock icon hidden by default. I believe this is more in line with what people expect from a tool like this, and it won't affect anyone who has already run the app at least once --- Hammerspoon/Hammerspoon-Info.plist | 6 ++---- Hammerspoon/MJAppDelegate.m | 2 +- Hammerspoon/MJDockIcon.m | 13 +++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Hammerspoon/Hammerspoon-Info.plist b/Hammerspoon/Hammerspoon-Info.plist index 7d5632171..f3ba2b778 100644 --- a/Hammerspoon/Hammerspoon-Info.plist +++ b/Hammerspoon/Hammerspoon-Info.plist @@ -167,8 +167,6 @@ - CFBundleTypeRole - Editor CFBundleURLName hammerspoon.Hammerspoon.http CFBundleURLSchemes @@ -177,8 +175,6 @@ - CFBundleTypeRole - Editor CFBundleURLName hammerspoon.Hammerspoon.https CFBundleURLSchemes @@ -207,6 +203,8 @@ public.app-category.developer-tools LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} + LSUIElement + NSAppSleepDisabled NSAppTransportSecurity diff --git a/Hammerspoon/MJAppDelegate.m b/Hammerspoon/MJAppDelegate.m index f76577372..d2c3fade1 100644 --- a/Hammerspoon/MJAppDelegate.m +++ b/Hammerspoon/MJAppDelegate.m @@ -280,7 +280,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende - (void) registerDefaultDefaults { [[NSUserDefaults standardUserDefaults] registerDefaults: @{@"NSApplicationCrashOnExceptions": @YES, - MJShowDockIconKey: @YES, + MJShowDockIconKey: @NO, MJShowMenuIconKey: @YES, HSAutoLoadExtensions: @YES, HSUploadCrashDataKey: @YES, diff --git a/Hammerspoon/MJDockIcon.m b/Hammerspoon/MJDockIcon.m index 76c871dff..9fefb9128 100644 --- a/Hammerspoon/MJDockIcon.m +++ b/Hammerspoon/MJDockIcon.m @@ -18,12 +18,21 @@ void MJDockIconSetVisible(BOOL visible) { } static void reflect_defaults(void) { - NSApplication* app = [NSApplication sharedApplication]; // NSApp is typed to 'id'; lame + NSApplication* app = [NSApplication sharedApplication]; + NSApplicationActivationPolicy currentPolicy = app.activationPolicy; + NSApplicationActivationPolicy targetPolicy = MJDockIconVisible() ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory; + + if (currentPolicy == targetPolicy) { + // No need to do anything, we already have the policy we want + return; + } + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" NSDisableScreenUpdates(); #pragma clang diagnostic pop - [app setActivationPolicy: MJDockIconVisible() ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory]; + + [app setActivationPolicy:targetPolicy]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [app unhide: nil]; [app activateIgnoringOtherApps:YES];