-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from brave/sparkle_integration
Sparkle framework integration
- Loading branch information
Showing
18 changed files
with
549 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_ | ||
#define BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_ | ||
|
||
#if defined(__OBJC__) | ||
|
||
#import "chrome/browser/app_controller_mac.h" | ||
|
||
@interface BraveAppController : AppController | ||
|
||
@end | ||
|
||
#endif // __OBJC__ | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_ |
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#import "brave/browser/brave_app_controller_mac.h" | ||
|
||
#include <string> | ||
|
||
#import "brave/browser/sparkle_glue_mac.h" | ||
#include "base/command_line.h" | ||
#include "base/strings/sys_string_conversions.h" | ||
#include "brave/common/brave_switches.h" | ||
|
||
namespace { | ||
|
||
BOOL UpdateEnabled() { | ||
return base::CommandLine::ForCurrentProcess()->HasSwitch( | ||
switches::kEnableBraveUpdateTest); | ||
} | ||
|
||
std::string GetDescriptionFromAppcastItem(id item) { | ||
return [SparkleGlue descriptionFromAppcastItem:item]; | ||
} | ||
|
||
} | ||
|
||
@implementation BraveAppController | ||
{ | ||
SparkleGlue* sparkle_glue_; | ||
} | ||
|
||
- (void)applicationWillFinishLaunching:(NSNotification*)notification { | ||
[super applicationWillFinishLaunching:notification]; | ||
|
||
if (!UpdateEnabled()) | ||
return; | ||
|
||
[self initializeBraveUpdater]; | ||
} | ||
|
||
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | ||
if ([super validateUserInterfaceItem:item]) | ||
return YES; | ||
|
||
return [item action] == @selector(updateBrave:) ? UpdateEnabled() : NO; | ||
} | ||
|
||
- (IBAction)updateBrave:(id)sender { | ||
DCHECK(UpdateEnabled()); | ||
|
||
[sparkle_glue_ checkForUpdates:sender]; | ||
} | ||
|
||
- (void)initializeBraveUpdater { | ||
DCHECK(UpdateEnabled()); | ||
|
||
sparkle_glue_ = [SparkleGlue sharedSparkleGlue]; | ||
[sparkle_glue_ setDelegate:self]; | ||
} | ||
|
||
#pragma mark - SUUpdaterDelegate | ||
|
||
- (void)updater:(id)updater didFinishLoadingAppcast:(id)appcast { | ||
VLOG(0) << "brave update: did finish loading appcast"; | ||
} | ||
|
||
- (void)updater:(id)updater didFindValidUpdate:(id)item { | ||
VLOG(0) << "brave update: did finish valid update with " + | ||
GetDescriptionFromAppcastItem(item); | ||
} | ||
|
||
- (void)updaterDidNotFindUpdate:(id)updater { | ||
VLOG(0) << "brave update: did not find update"; | ||
} | ||
|
||
- (void)updater:(id)updater | ||
willDownloadUpdate:(id)item | ||
withRequest:(NSMutableURLRequest *)request { | ||
VLOG(0) << "brave update: willDownloadUpdate with " + | ||
GetDescriptionFromAppcastItem(item); | ||
} | ||
|
||
- (void)updater:(id)updater | ||
failedToDownloadUpdate:(id)item | ||
error:(NSError *)error { | ||
VLOG(0) << "brave update: failed to download update with " + | ||
GetDescriptionFromAppcastItem(item) + | ||
" with error - " + [[error description] UTF8String]; | ||
} | ||
|
||
- (void)userDidCancelDownload:(id)updater { | ||
VLOG(0) << "brave update: user did cancel download"; | ||
} | ||
|
||
- (void)updater:(id)updater willInstallUpdate:(id)item { | ||
VLOG(0) << "brave update: will install update with " + | ||
GetDescriptionFromAppcastItem(item); | ||
} | ||
|
||
- (void)updaterWillRelaunchApplication:(id)updater { | ||
VLOG(0) << "brave update: will relaunch application"; | ||
} | ||
|
||
- (void)updaterDidRelaunchApplication:(id)updater { | ||
VLOG(0) << "brave update: did relaunch application"; | ||
} | ||
|
||
- (void)updater:(id)updater | ||
willInstallUpdateOnQuit:(id)item | ||
immediateInstallationInvocation:(NSInvocation *)invocation { | ||
VLOG(0) << "brave update: will install update on quit with " + | ||
GetDescriptionFromAppcastItem(item); | ||
} | ||
|
||
- (void)updater:(id)updater didCancelInstallUpdateOnQuit:(id)item { | ||
VLOG(0) << "brave update: did cancel install update on quit with " + | ||
GetDescriptionFromAppcastItem(item); | ||
} | ||
|
||
- (void)updater:(id)updater didAbortWithError:(NSError *)error { | ||
VLOG(0) << [[error description] UTF8String]; | ||
} | ||
|
||
@end // @implementation BraveAppController |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_SPARKLE_GLUE_MAC_H_ | ||
#define BRAVE_BROWSER_SPARKLE_GLUE_MAC_H_ | ||
|
||
#include <string> | ||
|
||
#if defined(__OBJC__) | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface SparkleGlue : NSObject | ||
|
||
+ (instancetype)sharedSparkleGlue; | ||
|
||
+ (std::string)descriptionFromAppcastItem:(id)item; | ||
|
||
- (instancetype)init; | ||
|
||
- (void)setDelegate:(id)delegate; | ||
- (void)checkForUpdates:(id)sender; | ||
|
||
@end // @interface SparkleGlue | ||
|
||
#endif // __OBJC__ | ||
|
||
#endif // BRAVE_BROWSER_SPARKLE_GLUE_MAC_H_ |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#import "brave/browser/sparkle_glue_mac.h" | ||
|
||
#include "base/mac/bundle_locations.h" | ||
|
||
namespace { | ||
|
||
id GetSUUpdater() { | ||
NSString* sparkle_path = | ||
[[base::mac::FrameworkBundle() privateFrameworksPath] | ||
stringByAppendingPathComponent:@"Sparkle.framework"]; | ||
|
||
NSBundle* sparkle_bundle = [NSBundle bundleWithPath:sparkle_path]; | ||
[sparkle_bundle load]; | ||
|
||
Class sparkle_class = [sparkle_bundle classNamed:@"SUUpdater"]; | ||
return [sparkle_class performSelector:NSSelectorFromString(@"sharedUpdater")]; | ||
} | ||
|
||
} | ||
|
||
@implementation SparkleGlue | ||
{ | ||
id su_updater_; | ||
} | ||
|
||
+ (instancetype)sharedSparkleGlue { | ||
static SparkleGlue* shared; | ||
if (shared == nil) | ||
shared = [[SparkleGlue alloc] init]; | ||
return shared; | ||
} | ||
|
||
+ (std::string)descriptionFromAppcastItem:(id)item { | ||
NSString* description = | ||
[NSString stringWithFormat:@"AppcastItem(Date: %@, Version: %@)", | ||
[item performSelector:NSSelectorFromString(@"dateString")], | ||
[item performSelector:NSSelectorFromString(@"versionString")]]; | ||
return [description UTF8String]; | ||
} | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
su_updater_ = GetSUUpdater(); | ||
return self; | ||
} else { | ||
return nil; | ||
} | ||
} | ||
|
||
- (void)setDelegate:(id)delegate { | ||
[su_updater_ setDelegate:delegate]; | ||
} | ||
|
||
- (void)checkForUpdates:(id)sender { | ||
[su_updater_ checkForUpdates:sender]; | ||
} | ||
|
||
@end |
Oops, something went wrong.