Wrap Sparkle's minimum interface with C++.
This commit is contained in:
parent
312744b863
commit
08dbdd9718
6 changed files with 188 additions and 0 deletions
89
browser/auto_updater_mac.mm
Normal file
89
browser/auto_updater_mac.mm
Normal file
|
@ -0,0 +1,89 @@
|
|||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "browser/auto_updater.h"
|
||||
|
||||
// Sparkle's headers are throwing compilation warnings, supress them.
|
||||
#pragma GCC diagnostic ignored "-Wmissing-method-return-type"
|
||||
#import <Sparkle/Sparkle.h>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "browser/auto_updater_delegate.h"
|
||||
|
||||
using auto_updater::AutoUpdaterDelegate;
|
||||
|
||||
namespace {
|
||||
|
||||
struct NSInvocationDeleter {
|
||||
inline void operator()(NSInvocation* invocation) const {
|
||||
[invocation release];
|
||||
}
|
||||
};
|
||||
|
||||
typedef scoped_ptr<NSInvocation, NSInvocationDeleter> ScopedNSInvocation;
|
||||
|
||||
// We are passing the NSInvocation as scoped_ptr, because we want to make sure
|
||||
// whether or not the callback is called, the NSInvocation should alwasy be
|
||||
// released, the only way to ensure it is to use scoped_ptr.
|
||||
void CallNSInvocation(ScopedNSInvocation invocation) {
|
||||
[invocation.get() invoke];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@interface SUUpdaterDelegate : NSObject {
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation SUUpdaterDelegate
|
||||
|
||||
- (void)updater:(SUUpdater*)updater
|
||||
willInstallUpdateOnQuit:(SUAppcastItem*)update
|
||||
immediateInstallationInvocation:(NSInvocation*)invocation {
|
||||
AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate();
|
||||
if (!delegate) {
|
||||
[invocation invoke];
|
||||
return;
|
||||
}
|
||||
|
||||
std::string version(base::SysNSStringToUTF8([update versionString]));
|
||||
ScopedNSInvocation invocation_ptr([invocation retain]);
|
||||
delegate->WillInstallUpdate(
|
||||
version,
|
||||
base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass())));
|
||||
}
|
||||
|
||||
- (void)updaterWillRelaunchApplication:(SUUpdater*)updater {
|
||||
[[SUUpdater sharedUpdater] setDelegate:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace auto_updater {
|
||||
|
||||
// static
|
||||
void AutoUpdater::Init() {
|
||||
SUUpdaterDelegate* delegate = [[SUUpdaterDelegate alloc] init];
|
||||
[delegate autorelease];
|
||||
[[SUUpdater sharedUpdater] setDelegate:delegate];
|
||||
}
|
||||
|
||||
// static
|
||||
void AutoUpdater::SetAutomaticallyChecksForUpdates(bool yes) {
|
||||
[[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:yes];
|
||||
}
|
||||
|
||||
// static
|
||||
void AutoUpdater::SetAutomaticallyDownloadsUpdates(bool yes) {
|
||||
[[SUUpdater sharedUpdater] setAutomaticallyDownloadsUpdates:yes];
|
||||
}
|
||||
|
||||
// static
|
||||
void AutoUpdater::CheckForUpdatesInBackground() {
|
||||
[[SUUpdater sharedUpdater] checkForUpdatesInBackground];
|
||||
}
|
||||
|
||||
} // namespace auto_updater
|
Loading…
Add table
Add a link
Reference in a new issue