-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit shows the edits we make to the standard Cordova project. We obtain the diff by reversing the rsync call.
- Loading branch information
Showing
10 changed files
with
344 additions
and
1,383 deletions.
There are no files selected for viewing
504 changes: 94 additions & 410 deletions
504
src/cordova/apple/xcode/ios/Outline.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
707 changes: 104 additions & 603 deletions
707
src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
205 changes: 36 additions & 169 deletions
205
src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,190 +1,57 @@ | ||
// Copyright 2018 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import "AppDelegate.h" | ||
#import "Outline-Swift.h" | ||
|
||
@import ServiceManagement; | ||
|
||
@interface AppDelegate() | ||
@property (strong, nonatomic) NSStatusItem *statusItem; | ||
@property (strong, nonatomic) NSPopover *popover; | ||
@property (strong, nonatomic) EventMonitor *eventMonitor; | ||
@property bool isSystemShuttingDown; | ||
@end | ||
#import "MainViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
@synthesize window; | ||
|
||
- (id)init { | ||
self = [super init]; | ||
return self; | ||
} | ||
|
||
#pragma mark - Lifecycle | ||
@synthesize window; | ||
|
||
- (void)applicationDidStartLaunching:(NSNotification*)aNotification { | ||
- (id)init | ||
{ | ||
self = [super init]; | ||
return self; | ||
} | ||
|
||
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification { | ||
[[NSAppleEventManager sharedAppleEventManager] | ||
setEventHandler:self | ||
andSelector:@selector(handleURLEvent:withReplyEvent:) | ||
forEventClass:kInternetEventClass | ||
andEventID:kAEGetURL]; | ||
// Don't ever show the default Cordova window, as we will display its content view in a popover. | ||
[self.window close]; | ||
|
||
[NSWorkspace.sharedWorkspace.notificationCenter | ||
addObserverForName:NSWorkspaceWillPowerOffNotification | ||
object:nil | ||
queue:nil | ||
usingBlock:^(NSNotification *_Nonnull n) { | ||
self.isSystemShuttingDown = YES; | ||
}]; | ||
[NSNotificationCenter.defaultCenter addObserverForName:OutlinePlugin.kVpnConnectedNotification | ||
object:nil | ||
queue:nil | ||
usingBlock:^(NSNotification * _Nonnull note) { | ||
[self setAppIcon:@"StatusBarButtonImageConnected"]; | ||
}]; | ||
[NSNotificationCenter.defaultCenter addObserverForName:OutlinePlugin.kVpnDisconnectedNotification | ||
object:nil | ||
queue:nil | ||
usingBlock:^(NSNotification * _Nonnull note) { | ||
[self setAppIcon:@"StatusBarButtonImage"]; | ||
}]; | ||
- (void) applicationDidStartLaunching:(NSNotification*) aNotification | ||
{ | ||
} | ||
|
||
- (void)handleURLEvent:(NSAppleEventDescriptor*)event | ||
withReplyEvent:(NSAppleEventDescriptor*)replyEvent { | ||
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; | ||
[[NSNotificationCenter defaultCenter] | ||
postNotificationName:CDVMacOsUrlHandler.kCDVHandleOpenURLNotification object:url]; | ||
if (!self.popover.isShown) { | ||
[self showPopover]; | ||
} | ||
- (void) applicationWillFinishLaunching:(NSNotification*)aNotification | ||
{ | ||
} | ||
|
||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification { | ||
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; | ||
self.statusItem.button.action = @selector(togglePopover); | ||
[self setAppIcon:@"StatusBarButtonImage"]; | ||
self.popover = [[NSPopover alloc] init]; | ||
self.popover.contentViewController = [[NSViewController alloc] initWithNibName:@"MainViewController" | ||
bundle:[NSBundle mainBundle]]; | ||
self.popover.contentViewController.view = self.window.contentView; | ||
// Monitor clicks outside the popover in order to close it. | ||
NSEventMask eventMask = NSEventMaskLeftMouseDown|NSEventMaskRightMouseDown; | ||
self.eventMonitor = [[EventMonitor alloc] initWithMask:eventMask handler:^(NSEvent* event) { | ||
if (self.popover.isShown) { | ||
[self closePopover]; | ||
} | ||
}]; | ||
- (void) applicationDidFinishLaunching:(NSNotification*)aNotification | ||
{ | ||
|
||
if ([self wasStartedByLauncherApp]) { | ||
[OutlineVpn.shared startLastSuccessfulTunnel:^(enum ErrorCode errorCode) { | ||
if (errorCode != ErrorCodeNoError) { | ||
NSLog(@"Failed to auto-connect the VPN on startup."); | ||
} | ||
}]; | ||
} else { | ||
[self showPopover]; | ||
} | ||
[self setAppLauncherEnabled:true]; // Enable app launcher to start on boot. | ||
} | ||
|
||
- (void)applicationWillTerminate:(NSNotification *)notification { | ||
if (!self.isSystemShuttingDown) { | ||
// Don't post a quit notification if the system is shutting down so the VPN is not stopped | ||
// and it auto-connects on startup. | ||
[[NSNotificationCenter defaultCenter] postNotificationName:OutlinePlugin.kAppQuitNotification | ||
object:nil]; | ||
} | ||
} | ||
|
||
#pragma mark - Popover | ||
|
||
- (void)togglePopover { | ||
if (self.popover.isShown) { | ||
[self closePopover]; | ||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)visibleWindows | ||
{ | ||
if (visibleWindows) { | ||
[self.window orderFront:self]; | ||
} else { | ||
[self showPopover]; | ||
} | ||
} | ||
|
||
- (void)closePopover { | ||
[self.popover close]; | ||
[self.eventMonitor stop]; | ||
} | ||
|
||
- (void)showPopover { | ||
[self.popover showRelativeToRect:self.statusItem.button.bounds | ||
ofView:self.statusItem.button | ||
preferredEdge:NSRectEdgeMinY]; | ||
[self.eventMonitor start]; | ||
// Activate the application in order to focus the popover. | ||
[[NSRunningApplication currentApplication] | ||
activateWithOptions:NSApplicationActivateIgnoringOtherApps]; | ||
} | ||
|
||
- (void)setAppIcon:(NSString *)imageName { | ||
self.statusItem.button.image = [NSImage imageNamed:imageName]; | ||
self.statusItem.button.image.template = YES; | ||
} | ||
|
||
#pragma mark - Launcher | ||
|
||
// Enables or disables the embedded app launcher as a login item. | ||
- (void)setAppLauncherEnabled:(bool)enabled { | ||
NSString *launcherBundleId = [self getLauncherBundleId]; | ||
if (launcherBundleId == nil) { | ||
return; | ||
} | ||
if (!SMLoginItemSetEnabled((__bridge CFStringRef) launcherBundleId, enabled)) { | ||
return NSLog(@"Failed to %@ launcher %@", enabled ? @"enable" : @"disable", launcherBundleId); | ||
} | ||
} | ||
|
||
// Returns the embedded launcher application's bundle ID. | ||
- (NSString *)getLauncherBundleId { | ||
static NSString *kAppLauncherName = @"launcher"; | ||
NSString *bundleId = NSBundle.mainBundle.bundleIdentifier; | ||
if (bundleId == nil) { | ||
NSLog(@"Failed to retrieve the application's bundle ID"); | ||
return nil; | ||
} | ||
return [[NSString alloc] initWithFormat:@"%@.%@", bundleId, kAppLauncherName]; | ||
} | ||
|
||
// Returns whether the app was started by the embedded launcher app by inspecting the launch event. | ||
- (bool)wasStartedByLauncherApp { | ||
NSAppleEventDescriptor *descriptor = [[NSAppleEventManager sharedAppleEventManager] | ||
currentAppleEvent]; | ||
if (descriptor == nil) { | ||
return false; | ||
} | ||
NSAppleEventDescriptor *launcherDescriptor = [descriptor paramDescriptorForKeyword:keyAEPropData]; | ||
if (launcherDescriptor == nil) { | ||
return false; | ||
} | ||
NSString *launcherBundleId = [self getLauncherBundleId]; | ||
if (launcherBundleId == nil) { | ||
return false; | ||
[self.window makeKeyAndOrderFront:self]; | ||
} | ||
return [launcherBundleId isEqual:launcherDescriptor.stringValue]; | ||
return YES; | ||
} | ||
|
||
@end |
Oops, something went wrong.