Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Android: First run (right after install) seems to ignore auto-download and auto-install #72

Closed
mauron85 opened this issue Dec 17, 2015 · 8 comments

Comments

@mauron85
Copy link

Hi, I've disabled auto-install and auto-download in config.xml.
But it seems to be ignored on first run (right after install).

App get stuck on update, and it has to be closed and reopened. On second and all others run, everything is fine.

I have preloader index.html page, which sets things up and redirects to an app.html page.
So basically I'm listening on deviceready event and do chcp update checks.

In my app, I was expecting console logs to be in following order:

  1. Device is ready
  2. Plugin configured successfully
  3. update is ready

But actually on first run I see:

  1. Device is ready
  2. update is ready
   function onUpdateReady () {
      console.log('update is ready');
      //this should be called only after chcp.fetchUpdate(fetchUpdateCallback);
   }

    function onDeviceReady () {
        console.log('Device is ready');
        var options = {
          'auto-download': false,
          'auto-install': false
        };

        chcp.configure(options, configureCallback);
    }
    function configureCallback (error) {
        if (error) {
          console.log('Error during the configuration process');
          console.log(error.description);
          init();
        } else {
          console.log('Plugin configured successfully');
          // from this moment only we control when to download and install new releases
          chcp.fetchUpdate(fetchUpdateCallback);
        }
    }

    function fetchUpdateCallback (error, data) {
        if (error) {
            console.log('Failed to load the update with error code: ' + error.code);
            console.log(error.description);
            init();
            return;
        } else {
            console.log('Update is loaded, running the installation');
            chcp.installUpdate(installationCallback);
        }
    }

    function installationCallback (error) {
        if (error) {
            console.log('Failed to install the update with error code: ' + error.code);
            console.log(error.description);
        } else {
            console.log('Update installed!');
        }
        init();
    }

    function init () {
        window.document.location = 'mobile.html';
    }

    document.addEventListener('deviceready', onDeviceReady, false);
    document.addEventListener('chcp_updateIsReadyToInstall', onUpdateReady, false);
@mauron85 mauron85 changed the title First run (right after install) seems to ignore auto-download and auto-install Android: First run (right after install) seems to ignore auto-download and auto-install Dec 17, 2015
@nikDemyankov
Copy link
Member

Hi,

Yes, that's sort of a bug. The reason is simple: when application is started for the very first time - it copies www folder from assets to the external storage. While doing so - it ignores any requests from the JS side. As soon as he finishes copying - requests are accepted.

So, if you are calling chcp.configure or chcp.fetchUpdate during that time - the requests are ignored. But on the next launches it doesn't need to copy anything, and that is why it's working.

If you know, that from the very beginning you don't need auto-updates and auto-installation - I'll suggest to disable them in the config.xml instead of JS. And for fetchUpdate - do as described in #63 .

In the future It will probably store those requests to execute after www installation.

@mauron85
Copy link
Author

@nikDemyankov thank you for the answer. I understand the complications, but actually I have disabled auto-download and auto-install in config.xml, so it should not auto update, but it tries on first run anyway.

Fragment of config.xml

...
  <chcp>
    <auto-download enabled="false"/>
    <auto-install enabled="false"/>
    <config-file url="http://some.url"/>
    <local-development enabled="false"/>
  </chcp>
...

Edit: As I see it. My issue is pretty much duplicate of #63. That guys is saying the same thing.

@nikDemyankov
Copy link
Member

Thanks, will check it.

@nikDemyankov nikDemyankov added this to the v1.2 milestone Dec 18, 2015
nikDemyankov added a commit that referenced this issue Dec 29, 2015
@nikDemyankov
Copy link
Member

Should be fixed in v1.2.0. If not - reopen the issue.

@diegodotta
Copy link

+1

I'm using the 1.3.2 plugin version and I have this same problem and more, every update the size of my app double it. The app has 40mb, and the first run doubles the app size, taking 5min to do this, probably is about this copy to external storage approach.

The auto-download=false doesn't affect this first copy to external.
So, like you said @nikDemyankov, after that I can call the fetchUpdate to check and download new files.

After the download completed and app reloaded, the app size was increased +40mb, and I changed only one file. I tried to close the app and open again to see if some clean up happens, but no! :(

I'm testing in:
Google Nexus 3 - Android 4.3 - API 18 - Genymotion (Takes 5min to copy)
Sony Xperia Z1 - Android 5.1.1 - Smartphone (Takes 30s)

Libs:
Cordova CLI: 6.1.1
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Version: 1.3.0
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
OS:
Node Version: v5.11.0

@nikDemyankov
Copy link
Member

@diegodotta Plugin stores 2 versions on the external storage: the current working www folder (displayed to the user), and the previous one as a backup. On the next update it will replace backup version without increasing the size of the app.

auto-download=false controls only download process, not the inner storage logic.

If you have some large files in the app (audio, movies, etc.) and they are not gonna change very often - then I suggest to update them a bit differently.

Store large files in assets instead of www

Instead of putting them in www folder - put them in the assets folder and access them via other cordova plugin (for example, cordova-plugin-file). In that case you would not be able to update them via chcp plugin, but if they are not changing that often - it's not a problem. Plus, it will make updates to be installed much faster.

Download large files after update

Instead of bundling large files in the app - you can download them dynamically on the first app launch. Some games does that, when their size is quite big. Yes, user will have to wait for some time, but if the size of the loaded files are not that big - it should not take too long.

When loading is finished - you can store files on file system with the help of cordova-plugin-file. When new release is available - you can re-download these large files (if needed).

You should use chcp plugin mainly for updating html/css/js/images, but for heavy stuff, if possible, add some logic.

@diegodotta
Copy link

Nice idea!! This approach about download the content is knocking the door every new sprint! Maybe it's time to open the door! 💃

@nikDemyankov
Copy link
Member

Maybe it is :) And it should not be too hard to implement.

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

No branches or pull requests

3 participants