mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add atom.update and atom.getUpdateStatus
This commit is contained in:
@@ -6,8 +6,10 @@ class AtomCefClient;
|
||||
@interface AtomApplication : NSApplication <CefAppProtocol, NSApplicationDelegate> {
|
||||
NSWindowController *_backgroundWindowController;
|
||||
NSDictionary *_arguments;
|
||||
NSInvocation *_updateInvocation;
|
||||
NSString *_updateStatus;
|
||||
BOOL _filesOpened;
|
||||
BOOL handlingSendEvent_;
|
||||
BOOL _handlingSendEvent;
|
||||
}
|
||||
|
||||
+ (AtomApplication *)sharedApplication;
|
||||
@@ -21,6 +23,8 @@ class AtomCefClient;
|
||||
- (void)runSpecsThenExit:(BOOL)exitWhenDone;
|
||||
- (NSDictionary *)arguments;
|
||||
- (void)runBenchmarksThenExit:(BOOL)exitWhenDone;
|
||||
- (NSString *)updateStatus;
|
||||
- (void)installUpdate;
|
||||
|
||||
@property (nonatomic, retain) NSDictionary *arguments;
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
- (void)dealloc {
|
||||
[_backgroundWindowController release];
|
||||
[_arguments release];
|
||||
[_updateInvocation release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -236,11 +237,11 @@
|
||||
# pragma mark CefAppProtocol
|
||||
|
||||
- (BOOL)isHandlingSendEvent {
|
||||
return handlingSendEvent_;
|
||||
return _handlingSendEvent;
|
||||
}
|
||||
|
||||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
|
||||
handlingSendEvent_ = handlingSendEvent;
|
||||
_handlingSendEvent = handlingSendEvent;
|
||||
}
|
||||
|
||||
- (void)sendEvent:(NSEvent*)event {
|
||||
@@ -256,26 +257,35 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)updateStatus {
|
||||
return _updateStatus ? _updateStatus : @"idle";
|
||||
}
|
||||
|
||||
- (void)installUpdate {
|
||||
if (_updateInvocation) [_updateInvocation invoke];
|
||||
}
|
||||
|
||||
#pragma mark SUUpdaterDelegate
|
||||
|
||||
- (void)updaterDidNotFindUpdate:(SUUpdater *)update {
|
||||
NSLog(@"No update found");
|
||||
_updateStatus = @"current";
|
||||
}
|
||||
|
||||
- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update {
|
||||
NSLog(@"Found Update");
|
||||
_updateStatus = @"downloading";
|
||||
}
|
||||
|
||||
- (void)updater:(SUUpdater *)updater willExtractUpdate:(SUAppcastItem *)update {
|
||||
NSLog(@"Extract update");
|
||||
_updateStatus = @"installing";
|
||||
}
|
||||
|
||||
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)update immediateInstallationInvocation:(NSInvocation *)invocation {
|
||||
NSLog(@"Install Update");
|
||||
_updateInvocation = invocation;
|
||||
_updateStatus = @"ready";
|
||||
}
|
||||
|
||||
- (void)updater:(SUUpdater *)updater didCancelInstallUpdateOnQuit:(SUAppcastItem *)update {
|
||||
NSLog(@"Cancel Update Install");
|
||||
_updateStatus = @"current";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -84,6 +84,12 @@ bool AtomCefClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
else if (name == "toggleFullScreen") {
|
||||
ToggleFullScreen(browser);
|
||||
}
|
||||
else if (name == "update") {
|
||||
Update();
|
||||
}
|
||||
else if (name == "getUpdateStatus") {
|
||||
GetUpdateStatus(messageId, browser);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -126,6 +126,8 @@ class AtomCefClient : public CefClient,
|
||||
void Log(const char *message);
|
||||
void Show(CefRefPtr<CefBrowser> browser);
|
||||
void ToggleFullScreen(CefRefPtr<CefBrowser> browser);
|
||||
void Update();
|
||||
void GetUpdateStatus(int replyId, CefRefPtr<CefBrowser> browser);
|
||||
|
||||
IMPLEMENT_REFCOUNTING(AtomCefClient);
|
||||
IMPLEMENT_LOCKING(AtomCefClient);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#import "native/atom_cef_client.h"
|
||||
#import "atom_application.h"
|
||||
#import "atom_window_controller.h"
|
||||
#import "atom_application.h"
|
||||
|
||||
void AtomCefClient::FocusNextWindow() {
|
||||
NSArray *windows = [NSApp windows];
|
||||
@@ -157,3 +158,18 @@ void AtomCefClient::Exit(int status) {
|
||||
void AtomCefClient::Log(const char *message) {
|
||||
std::cout << message << "\n";
|
||||
}
|
||||
|
||||
void AtomCefClient::Update() {
|
||||
[(AtomApplication *)NSApp installUpdate];
|
||||
}
|
||||
|
||||
void AtomCefClient::GetUpdateStatus(int replyId, CefRefPtr<CefBrowser> browser) {
|
||||
CefRefPtr<CefProcessMessage> replyMessage = CefProcessMessage::Create("reply");
|
||||
CefRefPtr<CefListValue> replyArguments = replyMessage->GetArgumentList();
|
||||
|
||||
replyArguments->SetSize(2);
|
||||
replyArguments->SetString(1, [[(AtomApplication *)NSApp updateStatus] UTF8String]);
|
||||
replyArguments->SetList(0, CreateReplyDescriptor(replyId, 0));
|
||||
|
||||
browser->SendProcessMessage(PID_RENDERER, replyMessage);
|
||||
}
|
||||
Reference in New Issue
Block a user