src/extensions/default/AutoUpdate/main.js
function handleSafeToDownload() {
        var downloadFn = function () {
            if (isFirstIterationDownload()) {
                // For the first iteration of download, show download
                //status info in Status bar, and pass download to node
                UpdateStatus.showUpdateStatus("initial-download");
                postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, true);
            } else {
                /* For the retry iterations of download, modify the
                download status info in Status bar, and pass download to node */
                var attempt = (MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining);
                if (attempt > 1) {
                    var info = attempt.toString() + "/5";
                    var status = {
                        target: "retry-download",
                        spans: [{
                            id: "attempt",
                            val: info
                        }]
                    };
                    UpdateStatus.modifyUpdateStatus(status);
                } else {
                    UpdateStatus.showUpdateStatus("retry-download");
                }
                postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, false);
            }

            --downloadAttemptsRemaining;
        };

        if(!isAutoUpdateInitiated) {
            isAutoUpdateInitiated = true;
            updateJsonHandler.refresh()
                .done(function() {
                    setUpdateStateInJSON('downloadCompleted', false)
                        .done(downloadFn);
                });
        } else {
            setUpdateStateInJSON('downloadCompleted', false)
                .done(downloadFn);
        }
    }
function handleSafeToDownload() {
        var downloadFn = function () {
            if (isFirstIterationDownload()) {
                // For the first iteration of download, show download
                //status info in Status bar, and pass download to node
                UpdateStatus.showUpdateStatus("initial-download");
                postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, true);
            } else {
                /* For the retry iterations of download, modify the
                download status info in Status bar, and pass download to node */
                var attempt = (MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining);
                if (attempt > 1) {
                    var info = attempt.toString() + "/5";
                    var status = {
                        target: "retry-download",
                        spans: [{
                            id: "attempt",
                            val: info
                        }]
                    };
                    UpdateStatus.modifyUpdateStatus(status);
                } else {
                    UpdateStatus.showUpdateStatus("retry-download");
                }
                postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, false);
            }

            --downloadAttemptsRemaining;
        };

        if(!isAutoUpdateInitiated) {
            isAutoUpdateInitiated = true;
            updateJsonHandler.refresh()
                .done(function() {
                    setUpdateStateInJSON('downloadCompleted', false)
                        .done(downloadFn);
                });
        } else {
            setUpdateStateInJSON('downloadCompleted', false)
                .done(downloadFn);
        }
    }
function handleSafeToDownload ( ) { var downloadFn = function ( ) { if ( isFirstIterationDownload ( ) ) { // For the first iteration of download, show download //status info in Status bar, and pass download to node UpdateStatus . showUpdateStatus ( "initial-download" ) ; postMessageToNode ( MessageIds . DOWNLOAD_INSTALLER , true ) ; } else { /* For the retry iterations of download, modify the
                download status info in Status bar, and pass download to node */ var attempt = ( MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining ) ; if ( attempt > 1 ) { var info = attempt . toString ( ) + "/5" ; var status = { target : "retry-download" , spans : [ { id : "attempt" , val : info } ] } ; UpdateStatus . modifyUpdateStatus ( status ) ; } else { UpdateStatus . showUpdateStatus ( "retry-download" ) ; } postMessageToNode ( MessageIds . DOWNLOAD_INSTALLER , false ) ; } -- downloadAttemptsRemaining ; } ; if ( ! isAutoUpdateInitiated ) { isAutoUpdateInitiated = true ; updateJsonHandler . refresh ( ) . done ( function ( ) { setUpdateStateInJSON ( 'downloadCompleted' , false ) . done ( downloadFn ) ; } ) ; } else { setUpdateStateInJSON ( 'downloadCompleted' , false ) . done ( downloadFn ) ; } }
Handles a safe download of the latest installer,
safety is ensured by cleaning up any pre-existing installers
from update directory before beginning a fresh download
Handles a safe download of the latest installer safety is ensured by cleaning up any pre - existing installers from update directory before beginning a fresh download