Results 1 to 4 of 4

Thread: onAppUpdate prior to rendering?

  1. #1
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    121
    Answers
    5

    Default onAppUpdate prior to rendering?

    in my Application onAppUpdate method i automatically run window.location.reload() without asking the user.

    The app is rendered... then it goes away and re-renders after reloading the app. Is there a way to do this prior to any render as I am not giving the option to run the cached version?

    Thanks,
    Mark

  2. #2
    Sencha User
    Join Date
    Oct 2018
    Location
    Noida
    Posts
    56
    Answers
    10

    Default

    Hi,

    If you see source code of onBeforeLaunch() function, app update is fired at the end of the function. So what you can try is you can override this onBeforeLaunch function of Ext.app.Application class and try to move below line in the starting of the function and return from that if condition, if there is any update.
    // Microloader has detected an Application Cache or LocalStorage Cache update, inform everyone
    // that may have added listeners late.
    if (Ext.Microloader && Ext.Microloader.appUpdate && Ext.Microloader.appUpdate.updated) {
    return Ext.Microloader.fireAppUpdate();
    }

    As you will write return from that if-condition, when you will write location.reload() in onAppUpdate function, execution will come again there.
    Try that way, actually I havn't try that but just guessing that it will work




  3. #3
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    121
    Answers
    5

    Default

    Thanks for sending me down the correct path.

    Even with the return in the if statement the page was still first rendered then reloaded.
    I added the window.location.reload() directly in the if statement and that seems to do the trick.

    I need to figure out how to do this with an override. I will work on that next and update this thread.

    Thanks again for pointing me in the correct direction.


    Code:
     
    if (Ext.Microloader && Ext.Microloader.appUpdate && Ext.Microloader.appUpdate.updated) {
    	window.location.reload();
            //return Ext.Microloader.fireAppUpdate();
    			
    }
    -Mark

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    121
    Answers
    5

    Default

    I have not done much testing... and I am concerned if the new version is not loaded then it could get into an infinite loop of trying to reload.


    Code:
    Ext.define('Dcs.override.app.Application', {
        override: 'Ext.app.Application',
    	
    	config: {
    		autoReload: false
    	},
    	
        onBeforeLaunch: function() {
    		if (this.getAutoReload() && Ext.Microloader && Ext.Microloader.appUpdate && Ext.Microloader.appUpdate.updated) {
    			window.location.reload();
    		} else {
    			this.callParent(arguments);
    		}
    	}
    	
    });
    Then in your Application

    remember when testing you have to reload twice after changing autoReload to true. The version on your browser cache will still have false and ask for a reload.


    Code:
    Ext.define('Checkout.Application', { 
        extend: 'Ext.app.Application',
    
    	autoReload: true,
    
    
        // this will never be ran if autoReload is set to true.
        // you don't need this function.
        onAppUpdate: function () {
            Ext.Msg.confirm('Application Update', 'This application has an update, reload?',
                function (choice) {
                    if (choice === 'yes') {
                        window.location.reload();
                    }
                }
            );
        }
    
         // rest of your application.
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •