pulsar/native/atom_application.mm

118 lines
3.3 KiB
Plaintext
Raw Normal View History

2012-08-10 23:32:19 +04:00
#import "include/cef_application_mac.h"
2012-08-28 00:21:59 +04:00
#import "native/atom_cef_client.h"
#import "native/atom_application.h"
#import "native/atom_window_controller.h"
#import "native/atom_cef_app.h"
2012-08-10 23:32:19 +04:00
2012-08-23 23:49:04 +04:00
@implementation AtomApplication
2012-08-10 23:32:19 +04:00
2012-08-21 02:25:17 +04:00
+ (id)sharedApplication {
2012-08-26 01:04:22 +04:00
NSApplication *application = [super sharedApplication];
CefInitialize(CefMainArgs(0, NULL), [self createCefSettings], new AtomCefApp);
return application;
}
2012-08-28 20:58:24 +04:00
+ (NSString *)supportDirectory {
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSString *supportDirectory = [cachePath stringByAppendingPathComponent:executableName];
NSFileManager *fs = [NSFileManager defaultManager];
NSError *error;
BOOL success = [fs createDirectoryAtPath:supportDirectory withIntermediateDirectories:YES attributes:nil error:&error];
if (!success) {
NSLog(@"Can't create support directory '%@' because %@", supportDirectory, [error localizedDescription]);
supportDirectory = @"";
}
return supportDirectory;
}
2012-08-26 01:04:22 +04:00
+ (CefSettings)createCefSettings {
2012-08-21 02:25:17 +04:00
CefSettings settings;
CefString(&settings.cache_path) = [[self supportDirectory] UTF8String];
2012-08-21 02:42:19 +04:00
CefString(&settings.user_agent) = "";
CefString(&settings.log_file) = "";
2012-08-28 20:58:24 +04:00
CefString(&settings.javascript_flags) = "";
2012-08-23 23:38:52 +04:00
settings.remote_debugging_port = 9090;
2012-08-21 02:42:19 +04:00
settings.log_severity = LOGSEVERITY_ERROR;
2012-08-26 01:04:22 +04:00
return settings;
2012-08-21 02:42:19 +04:00
}
2012-08-23 02:29:39 +04:00
- (void)dealloc {
[_backgroundWindowController release];
2012-08-23 02:29:39 +04:00
[super dealloc];
2012-08-21 00:33:31 +04:00
}
2012-08-23 02:29:39 +04:00
- (void)open:(NSString *)path {
[[AtomWindowController alloc] initWithPath:path];
2012-08-23 02:29:39 +04:00
}
- (IBAction)runSpecs:(id)sender {
[self runSpecsThenExit:NO];
}
- (void)runSpecsThenExit:(BOOL)exitWhenDone {
[[AtomWindowController alloc] initSpecsThenExit:exitWhenDone];
2012-08-23 02:29:39 +04:00
}
- (IBAction)runBenchmarks:(id)sender {
[self runBenchmarksThenExit:NO];
}
- (void)runBenchmarksThenExit:(BOOL)exitWhenDone {
[[AtomWindowController alloc] initBenchmarksThenExit:exitWhenDone];
2012-08-23 02:29:39 +04:00
}
2012-08-21 02:42:19 +04:00
# pragma mark NSApplicationDelegate
2012-08-23 02:29:39 +04:00
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
_backgroundWindowController = [[AtomWindowController alloc] initInBackground];
NSArray *processArguments = [[NSProcessInfo processInfo] arguments];
if ([processArguments containsObject:@"--benchmark"]) {
[self runBenchmarksThenExit:true];
}
else if ([processArguments containsObject:@"--test"]) {
[self runSpecsThenExit:true];
}
else {
#ifdef RESOURCE_PATH
[self open:[NSString stringWithUTF8String:RESOURCE_PATH]];
#else
[self open:nil];
#endif
}
2012-08-23 02:29:39 +04:00
}
- (void)applicationWillTerminate:(NSNotification *)notification {
2012-08-10 23:32:19 +04:00
CefShutdown();
}
2012-08-21 02:42:19 +04:00
# pragma mark CefAppProtocol
- (BOOL)isHandlingSendEvent {
return handlingSendEvent_;
}
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
handlingSendEvent_ = handlingSendEvent;
}
- (void)sendEvent:(NSEvent*)event {
CefScopedSendingEvent sendingEventScoper;
2012-08-23 02:29:39 +04:00
if ([[self mainMenu] performKeyEquivalent:event]) return;
if (_backgroundWindowController && ![self keyWindow] && [event type] == NSKeyDown) {
[_backgroundWindowController.window makeKeyWindow];
[_backgroundWindowController.window sendEvent:event];
2012-08-23 02:29:39 +04:00
}
else {
[super sendEvent:event];
}
2012-08-21 02:42:19 +04:00
}
2012-08-28 20:58:24 +04:00
@end