omlapp/OMLAppDelegate.m

90 lines
3.4 KiB
Mathematica
Raw Normal View History

//
// OMLAppDelegate.m
// OML
//
#import "OMLAppDelegate.h"
@interface WebPreferences (WebPreferencesPrivate)
- (void)_setLocalStorageDatabasePath:(NSString *)path;
- (void) setLocalStorageEnabled: (BOOL) localStorageEnabled;
@end
@implementation OMLAppDelegate
@synthesize window;
@synthesize webView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *basePath = [@"~/Library/Application Support/Open Media Library" stringByExpandingTildeInPath];
BOOL exists;
if ([fileManager fileExistsAtPath:basePath isDirectory: &exists] && exists) {
NSTask *task = [[NSTask alloc] init];
task.launchPath = [basePath stringByAppendingString:@"/ctl"];
task.arguments = @[@"start"];
[task launch];
NSString* dbPath = [WebStorageManager _storageDirectoryPath];
WebPreferences* prefs = [webView preferences];
//[prefs _setLocalStorageDatabasePath:[basePath stringByAppendingString:@"/localStorage"]];
NSString* localDBPath = [prefs _localStorageDatabasePath];
// PATHS MUST MATCH!!!! otherwise localstorage file is erased when starting program
if( [localDBPath isEqualToString:dbPath] == NO) {
[prefs setAutosaves:YES]; //SET PREFS AUTOSAVE FIRST otherwise settings aren't saved.
// Define application cache quota
static const unsigned long long defaultTotalQuota = 10 * 1024 * 1024; // 10MB
static const unsigned long long defaultOriginQuota = 5 * 1024 * 1024; // 5MB
[prefs setApplicationCacheTotalQuota:defaultTotalQuota];
[prefs setApplicationCacheDefaultOriginQuota:defaultOriginQuota];
[prefs setWebGLEnabled:YES];
[prefs setFullScreenEnabled:YES];
[prefs setOfflineWebApplicationCacheEnabled:YES];
[prefs setDatabasesEnabled:YES];
//[prefs setDeveloperExtrasEnabled:[[NSUserDefaults standardUserDefaults] boolForKey: @"developer"]];
[prefs _setLocalStorageDatabasePath:dbPath];
[prefs setLocalStorageEnabled:YES];
[webView setPreferences:prefs];
}
NSString *htmlPath = [basePath stringByAppendingString:@"/openmedialibrary/static/html/load.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
} else {
NSTask *task = [[NSTask alloc] init];
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
task.launchPath = @"/usr/bin/python";
task.arguments = @[[resourcesPath stringByAppendingString:@"/install.py"]];
[task launch];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/install.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
}
[window setContentView: webView];
}
2015-11-29 13:30:30 +00:00
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
NSString *basePath = [@"~/Library/Application Support/Open Media Library" stringByExpandingTildeInPath];
NSTask *task = [[NSTask alloc] init];
task.launchPath = [basePath stringByAppendingString:@"/ctl"];
task.arguments = @[@"stop"];
[task launch];
return YES;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app {
return YES;
}
@end