Skip to content

Commit

Permalink
Switch our defaults around so that Hammerspoon runs with its dock ico…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
cmsj committed Dec 27, 2019
1 parent 77a5885 commit 9b85081
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 2 additions & 4 deletions Hammerspoon/Hammerspoon-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>hammerspoon.Hammerspoon.http</string>
<key>CFBundleURLSchemes</key>
Expand All @@ -177,8 +175,6 @@
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>hammerspoon.Hammerspoon.https</string>
<key>CFBundleURLSchemes</key>
Expand Down Expand Up @@ -207,6 +203,8 @@
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>LSUIElement</key>
<true/>
<key>NSAppSleepDisabled</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
2 changes: 1 addition & 1 deletion Hammerspoon/MJAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions Hammerspoon/MJDockIcon.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 9b85081

Please sign in to comment.