src/app/www/js/functions.js
/**
 * Runs the script.
 * It checkes if it can be ran with RUN_RAW. If not, it runs it as a file,
 * saving the file changes first if it's needed.
 */
Runs the script.
It checkes if it can be ran with RUN_RAW. If not, it runs it as a file,
saving the file changes first if it's needed.
Runs the script . It checkes if it can be ran with RUN_RAW . If not it runs it as a file saving the file changes first if it ' s needed .
function runScript() {
    if(status.hasErrors) {
        toast.show("There are errors in your script! Solve them before running.", Toast.Mode.ERROR);
        return;
    }
    const code = preProcessCode(editor.getValue());
    console.log(`Resulting Duckyscript:\n${code}`);
    if(code.length <= 450) {
        const form = API.createRequestForm({
            Code: preProcessCode(editor.getValue())
        });
        API.call(API.Resource.RUN_RAW, form)
           .then(() => {
                toast.show("Received command!", Toast.Mode.SUCCESS);
            })
            .catch(() => {});
        return;
    }
    if(!status.isSaved) {
        saveScript(status.filename)
        .then(() => {
            const form = API.createRequestForm({
                Filename: status.filename
            });
            API.call(API.Resource.RUN_FILE, form)
               .then(() => {
                    toast.show("Received command!", Toast.Mode.SUCCESS);
                })
                .catch(() => {});
        })
        .catch(() => {
            toast.show("Error saving script!", Toast.Mode.ERROR);
        });
    }
    else {
        const form = API.createRequestForm({
            Filename: status.filename
        });
        API.call(API.Resource.RUN_FILE, form)
           .then(() => {
                toast.show("Received command!", Toast.Mode.SUCCESS);
            })
            .catch(() => {});
    }
}
function runScript ( ) { if ( status . hasErrors ) { toast . show ( "There are errors in your script! Solve them before running." , Toast . Mode . ERROR ) ; return ; } const code = preProcessCode ( editor . getValue ( ) ) ; console . log ( ` \n ${ code } ` ) ; if ( code . length <= 450 ) { const form = API . createRequestForm ( { Code : preProcessCode ( editor . getValue ( ) ) } ) ; API . call ( API . Resource . RUN_RAW , form ) . then ( ( ) => { toast . show ( "Received command!" , Toast . Mode . SUCCESS ) ; } ) . catch ( ( ) => { } ) ; return ; } if ( ! status . isSaved ) { saveScript ( status . filename ) . then ( ( ) => { const form = API . createRequestForm ( { Filename : status . filename } ) ; API . call ( API . Resource . RUN_FILE , form ) . then ( ( ) => { toast . show ( "Received command!" , Toast . Mode . SUCCESS ) ; } ) . catch ( ( ) => { } ) ; } ) . catch ( ( ) => { toast . show ( "Error saving script!" , Toast . Mode . ERROR ) ; } ) ; } else { const form = API . createRequestForm ( { Filename : status . filename } ) ; API . call ( API . Resource . RUN_FILE , form ) . then ( ( ) => { toast . show ( "Received command!" , Toast . Mode . SUCCESS ) ; } ) . catch ( ( ) => { } ) ; } }
Runs the script.
Runs the script .