You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/04/24 22:34:51 UTC
mac commit: CB-4319 localStorage database is relocated when
restarting app on OSX
Repository: cordova-osx
Updated Branches:
refs/heads/master cf43a8df4 -> 806ed0575
CB-4319 localStorage database is relocated when restarting app on OSX
fixes:
- initialize web storage earlier
- read location from config.xml
- add fallback with bundleId if missing
- add missing placeholders in config.xml template
Signed-off-by: Shazron Abdullah <sh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/806ed057
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/806ed057
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/806ed057
Branch: refs/heads/master
Commit: 806ed0575ce578d52e1f42828f049913fbcb6081
Parents: cf43a8d
Author: Tobias Bocanegra <tr...@adobe.com>
Authored: Thu Apr 24 01:16:31 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Apr 24 13:33:28 2014 -0700
----------------------------------------------------------------------
.../CordovaLib/Classes/CDVViewController.h | 13 ++++++++
.../CordovaLib/Classes/CDVViewController.m | 32 ++++++++++++++++++--
.../Classes/MainViewController.m | 11 -------
.../project/__CDV_PRODUCT_NAME__/config.xml | 6 ++--
4 files changed, 44 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/806ed057/CordovaLib/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.h b/CordovaLib/CordovaLib/Classes/CDVViewController.h
index cdd3bfd..5b75daf 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.h
@@ -56,3 +56,16 @@
- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName;
@end
+
+// add private web preferences
+@interface WebPreferences (WebPrivate)
+
+- (BOOL)webGLEnabled;
+- (void)setWebGLEnabled:(BOOL)enabled;
+
+- (BOOL)localStorageEnabled;
+- (void)setLocalStorageEnabled:(BOOL)localStorageEnabled;
+
+- (NSString *)_localStorageDatabasePath;
+- (void)_setLocalStorageDatabasePath:(NSString *)path;
+@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/806ed057/CordovaLib/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.m b/CordovaLib/CordovaLib/Classes/CDVViewController.m
index f9fdaa7..89d1cc2 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.m
@@ -86,11 +86,37 @@
BOOL enableWebGL = [[self.settings objectForKey:@"EnableWebGL"] boolValue];
WebPreferences* prefs = [self.webView preferences];
-
+ [prefs setAutosaves:YES];
+
// Note that this preference may not be Mac App Store safe
- if (enableWebGL && [prefs respondsToSelector:@selector(setWebGLEnabled:)]) {
- [prefs performSelector:@selector(setWebGLEnabled:) withObject:[NSNumber numberWithBool:enableWebGL]];
+ if (enableWebGL) {
+ [prefs setWebGLEnabled:YES];
+ }
+
+ // ensure that local storage is enable and paths are correct
+ NSString* webStoragePath = [self.settings valueForKey:@"OSXLocalStoragePath"];
+ if (webStoragePath == nil) {
+ NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
+ NSFileManager* fileManager = [[NSFileManager alloc] init];
+ NSError* err = nil;
+ NSURL* dir = [fileManager URLForDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appropriateForURL:nil
+ create:YES
+ error:&err];
+ if (err) {
+ NSLog(@"error finding app support directory %@", err);
+ webStoragePath = [NSString stringWithFormat:@"~/Library/Application Support/%@", appBundleID];
+ } else {
+ NSURL* folder = [[NSURL alloc] initFileURLWithPath:[dir path] isDirectory:YES];
+ NSURL* storageURL = [NSURL URLWithString:appBundleID relativeToURL:folder];
+ webStoragePath = storageURL.path;
+ }
}
+ [prefs _setLocalStorageDatabasePath:webStoragePath];
+ [prefs setLocalStorageEnabled:YES];
+ NSLog(@"WebStoragePath is '%@', modify in config.xml.", webStoragePath);
+ [self.webView setPreferences:prefs];
}
- (void) __init
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/806ed057/templates/project/__CDV_PRODUCT_NAME__/Classes/MainViewController.m
----------------------------------------------------------------------
diff --git a/templates/project/__CDV_PRODUCT_NAME__/Classes/MainViewController.m b/templates/project/__CDV_PRODUCT_NAME__/Classes/MainViewController.m
index be7c5d6..0e04f3f 100644
--- a/templates/project/__CDV_PRODUCT_NAME__/Classes/MainViewController.m
+++ b/templates/project/__CDV_PRODUCT_NAME__/Classes/MainViewController.m
@@ -66,17 +66,6 @@
[super awakeFromNib];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
-
- // enable HTML5 webStorage
- WebPreferences* prefs = [self.webView preferences];
- if ([prefs respondsToSelector:@selector(_setLocalStorageDatabasePath:)]) {
- NSString* webStoragePath = @"~/Library/Application Support/__CDV_PRODUCT_NAME__";
- [prefs performSelector:@selector(_setLocalStorageDatabasePath:) withObject:webStoragePath];
- NSLog(@"WebStoragePath is '%@', modify in MainViewController.m.", webStoragePath);
- }
- if ([prefs respondsToSelector:@selector(setLocalStorageEnabled:)]) {
- [prefs performSelector:@selector(setLocalStorageEnabled:) withObject:[NSNumber numberWithBool:YES]];
- }
}
@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/806ed057/templates/project/__CDV_PRODUCT_NAME__/config.xml
----------------------------------------------------------------------
diff --git a/templates/project/__CDV_PRODUCT_NAME__/config.xml b/templates/project/__CDV_PRODUCT_NAME__/config.xml
index d38c344..aa2c6b4 100644
--- a/templates/project/__CDV_PRODUCT_NAME__/config.xml
+++ b/templates/project/__CDV_PRODUCT_NAME__/config.xml
@@ -16,10 +16,8 @@
<preference name="PageLength" value="0" />
<preference name="PaginationBreakingMode" value="page" />
<preference name="PaginationMode" value="unpaginated" />
- <feature name="LocalStorage">
- <param name="ios-package" value="CDVLocalStorage" />
- </feature>
- <name>Pong</name>
+ <preference name="OSXLocalStoragePath" value="~/Library/Application Support/__CDV_PRODUCT_NAME__" />
+ <name>__CDV_PRODUCT_NAME__</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>