Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve local storage #25

Closed
chesleybrown opened this issue Dec 27, 2015 · 7 comments
Closed

Preserve local storage #25

chesleybrown opened this issue Dec 27, 2015 · 7 comments

Comments

@chesleybrown
Copy link

From what I can tell, local storage is not preserved after quitting the WebShell application. This means for applications that use local storage to save information such as authentication tokens, they are lost when exiting the application resulting in the user having to re-login.

Any idea on how to get local storage to be preserved after exiting the application?

@djyde djyde added the bug label Dec 28, 2015
@djyde
Copy link
Owner

djyde commented Dec 28, 2015

It seems that the Cocoa WebView not support localStorage now. I have to find a hack way to implement it.

@chesleybrown
Copy link
Author

I was looking at this example "Enabling localStorage": http://www.lostdecadegames.com/completing-your-native-mac-osx-app-built-in-h/

And looks like it might be possible using something like:

var prefs: WebPreferences = webView.preferences()
prefs._setLocalStorageDatabasePath("~/Library/<APP_NAME>/LocalStorage")

But really not sure where this configuration would be set?

@djyde
Copy link
Owner

djyde commented Dec 28, 2015

There is no method called setLocalStorageDatabasePath. It might be deprecated.

@0xWDG
Copy link
Collaborator

0xWDG commented Dec 28, 2015

@djyde (bug on iOS) http://stackoverflow.com/questions/18964410/localstorage-no-longer-working-in-ios-7-webview

But the problem with the _setLocalStorageDatabasePath is that it is a private property and isn't built to use it.

we have mainWebview.preferences.cacheModel for caching maybe that will help.

@chesleybrown http://www.lostdecadegames.com/completing-your-native-mac-osx-app-built-in-h/
_Note: this may generate the warning "'WebPreferences' may not respond to '-setLocalStorageDatabasePath:'".


Update

http://stackoverflow.com/questions/28174541/how-to-access-ios-private-apis-in-swift

We'll need to access the private API's also to fix #23

@0xWDG
Copy link
Collaborator

0xWDG commented Jan 26, 2016

Update:

Tried (Objective-C Bridging header):

#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

@interface WebPreferences (WebPreferencesPrivate)
- (void)_setLocalStorageDatabasePath:(NSString *)path;
- (void) setLocalStorageEnabled: (BOOL) localStorageEnabled;
- (void) setOfflineWebApplicationCacheEnabled:(BOOL)offlineWebApplicationCacheEnabled;
- (void) setDatabasesEnabled:(BOOL)databasesEnabled;
@end

And then:

mainWebview.preferences._setLocalStorageDatabasePath("~/Library/Application Support/WebShell/db")
mainWebview.preferences.setLocalStorageEnabled(true)
mainWebview.preferences.setDatabasesEnabled(true)
mainWebview.preferences.setOfflineWebApplicationCacheEnabled(true)

And it's not working.

Notes:


i think the best option is that we'll grab the local storage items and put them in a NSUserDefaults? or something like that. (a better option is Core Data) but i don't know how to use it.
I can make a wrapper what copy and insert the local storage, but for images i think it is tricky.
i will look Thursday for a wrapper

@0xWDG
Copy link
Collaborator

0xWDG commented Jan 28, 2016

Update got something working (after reboot).

> localStorage;
< Storage {WebShell: "is Cool", Product: "WebShell", length: 2} = $2
> localStorage.getItem("Product");
< "WebShell" = $3

Now i only need to build a timer, to get them all saved for re-use.

@0xWDG 0xWDG closed this as completed in e3dae3e Jan 28, 2016
@djyde djyde added this to the v0.1.11 milestone Jan 29, 2016
@djyde
Copy link
Owner

djyde commented Jan 29, 2016

@wdg great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants