From Wiki96
Jump to: navigation, search
(having a //!wrt executable with a .js extension still makes it launch-able)
Tag: Reverted
m (Reverted edits by 94.233.241.205 (talk) to last revision by Kelbaz)
Tags: Replaced Rollback
 
(8 intermediate revisions by 4 users not shown)
Line 4: Line 4:


== Structure of an application ==
== Structure of an application ==
Windows 96 applications are simply JavaScript files without (or with) the .JS extension that include a WRT shebang (<code>//!wrt</code>). The shebang denotes that this regular file is a WRT bin, and must be the very first line in any WRT application. It may sometimes include a binary specification (BSPEC) suffix to describe some metadata about the application.
Windows 96 applications are simply JavaScript files without the .JS extension that include a WRT shebang (<code>//!wrt</code>). The shebang denotes that this regular file is a WRT bin, and must be the very first line in any WRT application. It may sometimes include a binary specification (BSPEC) suffix to describe some metadata about the application.


=== The binary specification (BSPEC) ===
=== The binary specification (BSPEC) ===
Line 23: Line 23:
</syntaxhighlight>
</syntaxhighlight>


=== An example program ===
=== A GUI example program ===


Here is an example of a very basic Windows 96 GUI program:<syntaxhighlight lang="javascript" line="1">
Here is an example of a very basic Windows 96 GUI program:<syntaxhighlight lang="javascript" line="1">
Line 29: Line 29:
const { Theme } = w96.ui;
const { Theme } = w96.ui;


class MyApplication extends WApplication {
class GUIApplication extends WApplication {
     /**
     /**
     * Application constructor.
     * Application constructor.
     * */
     */
     constructor() {
     constructor() {
         super();
         super();
Line 40: Line 40:
     * Main entry point.
     * Main entry point.
     * @param {String[]} argv The program arguments.
     * @param {String[]} argv The program arguments.
     * */
     */
     async main(argv) {
     async main(argv) {
        super.main(argv);
         // Create the window
         // Create the window
         const mainwnd = this.createWindow({
         const mainwnd = this.createWindow({
Line 59: Line 61:
}
}


return await WApplication.execAsync(new MyApplication(), this.boxedEnv.args);
return await WApplication.execAsync(new GUIApplication(), this.boxedEnv.args);
</syntaxhighlight>Save this file anywhere, without a file extension, and then double click to run it. You may need to refresh your explorer view to allow it to recognize this file as a program.
</syntaxhighlight>Save this file anywhere, without a file extension, and then double click to run it. You may need to refresh your explorer view to allow it to recognize this file as a program.
=== A CLI example program ===
Here is an example of a very basic Windows 96 terminal program:<syntaxhighlight lang="javascript" line="1">
//!wrt $BSPEC:{"ssy":"cli"}
const term = this.boxedEnv.term;
// If the program is not executed in a terminal, exit.
if (!term) return;
class CLIApplication extends WApplication {
    /**
    * Application constructor.
    */
    constructor() {
        super()
    }
   
    /**
    * Main entry point.
    * @param {String[]} argv The program arguments.
    */
    async main(argv) {
        super.main(argv);
       
        // Write some text in the terminal.
        term.writeln("Hello World!");
        term.writeln("Welcome to the most useful app!");
       
        // Get user input and store it in a variable.
        let e = await term.prompt("Enter your first name: ");
        term.writeln("Nice job " + e + "!");
       
        let r = await term.prompt("Last name: ");
        term.writeln(`Hi there ${e} ${r}!`);
       
        // Pause the program.
        await term.pause()
    }
}
return await WApplication.execAsync(new CLIApplication(), this.boxedEnv.args, this);
</syntaxhighlight>Save this file anywhere, without a file extension, and then enter the path to the file in the terminal to run it.


== Running an application ==
== Running an application ==
Line 68: Line 112:
* Double click it in an explorer window to execute it in the current directory.
* Double click it in an explorer window to execute it in the current directory.
* Enter the absolute path of the application bin in a Run box or terminal window.
* Enter the absolute path of the application bin in a Run box or terminal window.
[[Category:Tutorials]]

Latest revision as of 18:36, 16 May 2023

Windows 96 includes a flexible API for developing your own applications. All applications are ran under WRT, which is a partial sandbox and runtime provided by Windows 96 for applications.

Applications may be referred to as "bins", "WRT bins", "application bin", or "sysbins" depending on the context.

Structure of an application

Windows 96 applications are simply JavaScript files without the .JS extension that include a WRT shebang (//!wrt). The shebang denotes that this regular file is a WRT bin, and must be the very first line in any WRT application. It may sometimes include a binary specification (BSPEC) suffix to describe some metadata about the application.

The binary specification (BSPEC)

As mentioned before, the binary specification (BSPEC) is a way to describe metadata for a WRT bin. It always follows the shebang on the same line, where the cumulative line size must not exceed 256 characters.

The BSPEC is a simple JSON object prefixed with $BSPEC: and contains the following fields:

  • icn - The name of the icon to use.
  • cpr - The copyright holder of the application.
  • dsc - A basic description of the application.
  • frn - The display name of the application.
  • aut - The application author.
  • ssy - The subsystem to use for this application. Can either be gui or cli.
  • ver - The version of the application.

Below is an example of a binary specification declaration for the File Explorer application.

//!wrt $BSPEC:{"icn":"apps/explorer","cpr":"Copyright (C) Windows 96 Team 2021.","dsc":"System File Explorer","frn":"Explorer","ver":1}

A GUI example program

Here is an example of a very basic Windows 96 GUI program:

//!wrt
const { Theme } = w96.ui;

class GUIApplication extends WApplication {
    /**
     * Application constructor.
     */
    constructor() {
        super();
    }
    
    /**
     * Main entry point.
     * @param {String[]} argv The program arguments.
     */
    async main(argv) {
        super.main(argv);

        // Create the window
        const mainwnd = this.createWindow({
            title: "Sample Application",
            body: "Sample text",
            bodyClass: "sample-app",
            taskbar: true,
            resizable: true,
            initialHeight: 480,
            initialWidth: 640,
            icon: await Theme.getIconUrl("mime/executable", '16x16')
        }, true);
        
        // Show the window
        mainwnd.show();
    }
}

return await WApplication.execAsync(new GUIApplication(), this.boxedEnv.args);

Save this file anywhere, without a file extension, and then double click to run it. You may need to refresh your explorer view to allow it to recognize this file as a program.

A CLI example program

Here is an example of a very basic Windows 96 terminal program:

//!wrt $BSPEC:{"ssy":"cli"}

const term = this.boxedEnv.term;
// If the program is not executed in a terminal, exit.
if (!term) return;

class CLIApplication extends WApplication {
    /**
     * Application constructor.
     */
    constructor() {
        super()
    }
    
    /**
     * Main entry point.
     * @param {String[]} argv The program arguments.
     */
    async main(argv) {
        super.main(argv);
        
        // Write some text in the terminal.
        term.writeln("Hello World!");
        term.writeln("Welcome to the most useful app!");
        
        // Get user input and store it in a variable.
        let e = await term.prompt("Enter your first name: ");
        term.writeln("Nice job " + e + "!");
        
        let r = await term.prompt("Last name: ");
        term.writeln(`Hi there ${e} ${r}!`);
        
        // Pause the program.
        await term.pause()
    }
}

return await WApplication.execAsync(new CLIApplication(), this.boxedEnv.args, this);

Save this file anywhere, without a file extension, and then enter the path to the file in the terminal to run it.

Running an application

To run an application, you can either:

  • Run it from the Run box or terminal with its executable name, if the binary is present in any directory denoted by the PATH environment variable.
  • Double click it in an explorer window to execute it in the current directory.
  • Enter the absolute path of the application bin in a Run box or terminal window.