Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Status Bar Behaviour #117

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions WhatsMac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://web.whatsapp.com"]];
[_webView loadRequest:urlRequest];
[_window makeKeyAndOrderFront:self];

// show dock icon if status bar item is hidden
if ([[NSUserDefaults standardUserDefaults] boolForKey:WAMShouldHideStatusItem]) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[_window makeKeyAndOrderFront:self];
[self showAppWindow:nil];
}
else {
[self hideAppWindow:nil];
}

[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate: self];

Expand Down Expand Up @@ -179,9 +188,21 @@ - (IBAction)toggleStatusItem:(id)sender {
}

- (void)showAppWindow:(id)sender {
if (![[NSUserDefaults standardUserDefaults] boolForKey:WAMShouldHideStatusItem]) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
}
[NSApp activateIgnoringOtherApps:YES];
}

- (void)hideAppWindow:(id)sender {
if (![[NSUserDefaults standardUserDefaults] boolForKey:WAMShouldHideStatusItem]) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
}
else {
[NSApp terminate:self];
}
}

- (void)applicationDidBecomeActive:(NSNotification *)notification {
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
[self.window makeKeyAndOrderFront:self];
Expand Down Expand Up @@ -353,6 +374,7 @@ - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNot
[NSString stringWithFormat:@"openChat(\"%@\")", notification.identifier]
completionHandler:nil];
[center removeDeliveredNotification:notification];
[self showAppWindow:nil];
}

- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
Expand All @@ -379,10 +401,10 @@ - (void)updateTitlebarOfWindow:(NSWindow*)window fullScreen:(BOOL)fullScreen {

// Set position of window buttons
CGFloat buttonX = 12; // initial LHS margin, matching Safari 8.0 on OS X 10.10.
NSView *closeButton = [window standardWindowButton:NSWindowCloseButton];
NSView *minimizeButton = [window standardWindowButton:NSWindowMiniaturizeButton];
NSView *zoomButton = [window standardWindowButton:NSWindowZoomButton];
for (NSView *buttonView in @[closeButton, minimizeButton, zoomButton]){
NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
NSButton *minimizeButton = [window standardWindowButton:NSWindowMiniaturizeButton];
NSButton *zoomButton = [window standardWindowButton:NSWindowZoomButton];
for (NSButton *buttonView in @[closeButton, minimizeButton, zoomButton]){
CGRect buttonFrame = buttonView.frame;

// in fullscreen, the titlebar frame is not governed by kTitlebarHeight but rather appears to be fixed by the system.
Expand All @@ -398,7 +420,9 @@ - (void)updateTitlebarOfWindow:(NSWindow*)window fullScreen:(BOOL)fullScreen {

[buttonView setFrameOrigin:buttonFrame.origin];
};


[closeButton setAction:@selector(hideAppWindow:)];
[closeButton setTarget:self];
}

- (NSWindow*)createWindow:(NSString*)identifier title:(NSString*)title URL:(NSString*)url {
Expand Down
2 changes: 2 additions & 0 deletions WhatsMac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<string>WAMApplication</string>
<key>SUFeedURL</key>
<string>https://raw.githubusercontent.com/stonesam92/ChitChat/master/update_appcast.xml</string>
<key>LSUIElement</key>
<true/>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
</dict>
Expand Down