Tutorial: system.downloadAsset

system.downloadAsset

Downloads the given application asset.

Example

const appAsset = {
    src: `${ location.origin }/assets.zip`,
    alias: 'dirApp',
    version: '1.23.24',
    target: 'assets/run.bat'
};

function launchAsset() {
    fin.desktop.System.launchExternalProcess({
        alias: appAsset.alias,
        listener: function(e) {
                console.log(`the exit code ${e.exitCode}`);
            }
    },() => {
        console.log('all good');
    },(reason, err)=> {
        console.log(reason, err);
    });
}

function onProgress(progress) {
    const downloadedPercent = Math.floor((progress.downloadedBytes / progress.totalBytes) * 100);
    console.log(`Downloaded ${downloadedPercent}%`);
}

function onComplete() {
    console.log('Download complete, launching');
    launchAsset();
}

function onError(reason ,err) {
    if (err.message.includes('already installed')) {
        console.log('Asset already installed, just launching');
        launchAsset();
    } else {
        //failed the download.
        console.log(reason, err);
    }
}

fin.desktop.System.downloadAsset(appAsset, onProgress, onComplete , onError);