crosswalk+cordova indexedDB overwritten on app update

340 views Asked by At

I'm making an hybrid app with crosswalk+cordova using pouchDB as storage. the problem is that when I install a new version (on android) browser indexedDB/webSQL gets completely overwritten, so all user data...is there any way to update an hybrid app on android/ios keeping userdata? thanks

1

There are 1 answers

0
Tudor Ilisoi On BEST ANSWER

IndexedDB is tied to your base URL

if you change app name or your base URL (content src) in config.xml, you will not be able to access the previous one.

I, for one, am using the localforage library and cordova sqlite plugin to smooth out browser bugs and implementation details. iOS can cause some headaches, be warned

My content entry in config.xml:

<content src="index.html" />

My relevant plugin related entries in config.xml:

<plugin name="cordova-plugin-sqlite-2" spec="~1.0.4" />
    <plugin name="cordova-plugin-crosswalk-webview" spec="~2.1.0">
        <variable name="XWALK_VERSION" value="21+" />
        <variable name="XWALK_LITEVERSION" value="xwalk_core_library_canary:17+" />
        <variable name="XWALK_COMMANDLINE" value="--disable-pull-to-refresh-effect" />
        <variable name="XWALK_MODE" value="embedded" />
        <variable name="XWALK_MULTIPLEAPK" value="false" />
    </plugin>

Here's my DB init function in the Javascript app (it returns a promise):

    function initDB() {

    let driver = [localforage.INDEXEDDB, localforage.WEBSQL]
    //force shim
    if (platform() === constants.PLATFORM_IOS) {
        if (window.sqlitePlugin) {
            //WEBSQL shim throgh sqlite2
            window.openDatabase = window.sqlitePlugin.openDatabase
        }
        driver = localforage.WEBSQL
    }


    let opts = {
        driver: driver,
        name: constants.DBName + '_forage',
        version: constants.appVersion,
        size: 4980736
    }

    localforage.config(opts)


    let stores = {
        state: localforage.createInstance({storeName: 'state'}),
        api_cache: localforage.createInstance({storeName: 'apiCache'})
    }

    const keys = Object.keys(stores)

    let p = new Promise((res, rej)=> {
        let r = 0;

        function check() {
            r++
            if (r === keys.length) {
                res(stores)
            }
        }
        keys.forEach(k=>stores[k].ready(check))

    })

    return p

}

localforage can be found here: https://github.com/localForage/localForage.git