1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.h"
7 #import <Cocoa/Cocoa.h>
9 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h"
11 @implementation RemotingUninstallerAppDelegate
17 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
20 - (void)showSuccess:(bool)success withMessage:(NSString*) message {
21 NSString* summary = success ? @"Uninstall succeeded" : @"Uninstall failed";
22 NSAlert* alert = [NSAlert alertWithMessageText:summary
26 informativeTextWithFormat:@"%@", message];
28 (success ? NSInformationalAlertStyle : NSCriticalAlertStyle)];
32 - (IBAction)uninstall:(NSButton*)sender {
34 NSLog(@"Chrome Remote Desktop uninstall starting.");
36 RemotingUninstaller* uninstaller =
37 [[[RemotingUninstaller alloc] init] autorelease];
38 OSStatus status = [uninstaller remotingUninstall];
40 NSLog(@"Chrome Remote Desktop Host uninstall complete.");
43 NSString* message = nullptr;
44 if (status == errAuthorizationSuccess) {
46 message = @"Chrome Remote Desktop Host successfully uninstalled.";
47 } else if (status == errAuthorizationCanceled) {
48 message = @"Chrome Remote Desktop Host uninstall canceled.";
49 } else if (status == errAuthorizationDenied) {
50 message = @"Chrome Remote Desktop Host uninstall authorization denied.";
52 [NSException raise:@"AuthorizationCopyRights Failure"
53 format:@"Error during AuthorizationCopyRights status=%d",
54 static_cast<int>(status)];
56 if (message != nullptr) {
57 NSLog(@"Uninstall %s: %@", success ? "succeeded" : "failed", message);
58 [self showSuccess:success withMessage:message];
61 @catch (NSException* exception) {
62 NSLog(@"Exception %@ %@", [exception name], [exception reason]);
64 @"Error! Unable to uninstall Chrome Remote Desktop Host.";
65 [self showSuccess:false withMessage:message];
68 [NSApp terminate:self];
71 - (IBAction)cancel:(id)sender {
72 [NSApp terminate:self];
75 - (IBAction)handleMenuClose:(NSMenuItem*)sender {
76 [NSApp terminate:self];
81 int main(int argc, char* argv[])
83 // The no-ui option skips the UI confirmation dialogs. This is provided as
84 // a convenience for our automated testing.
85 // There will still be an elevation prompt unless the command is run as root.
86 if (argc == 2 && !strcmp(argv[1], "--no-ui")) {
88 NSLog(@"Chrome Remote Desktop uninstall starting.");
89 NSLog(@"--no-ui : Suppressing UI");
91 RemotingUninstaller* uninstaller =
92 [[[RemotingUninstaller alloc] init] autorelease];
93 OSStatus status = [uninstaller remotingUninstall];
95 NSLog(@"Chrome Remote Desktop Host uninstall complete.");
96 NSLog(@"Status = %d", static_cast<int>(status));
97 return status != errAuthorizationSuccess;
100 return NSApplicationMain(argc, (const char**)argv);