Skip to content

AppWindow

Create and control new application windows.

import { AppWindow } from `miletus`;

let win = new AppWindow({html: 'index.html', title: 'Title of the window'});
win.show();

window.appWindow

window.appWindow refers to the AppWindow instance of the current window.

Messaging between windows

Sending messages between windows is based on a subscripiton system. Each window that wants to receive messages must first register itself by calling the register() method.

let win = new AppWindow({html: 'products.html'});

win.on('window-ready', () => {
    win.register('my-id');
});

win.on('window-message', (e) => {
    console.log('Received message from ' + e.sender + ':');
    console.log(e.message);
});

win.show();

//...

window.appWindow.sendMessageTo('my-id', 'Hello!');

Methods

new AppWindow(options)

  • options WindowOptions - The following options are supported
    • html string - The HTML file to be loaded.
    • width number (optional) - Width of the window. Default value is 640.
    • height number (optional) - Height of the window. Default value is 480.
    • title string (optional) - Title of the window. Default value is "".
    • minimized boolean (optional) - The window will be minimized upon creation. Default value is false.
    • maximized boolean (optional) - The window will be maximized upon creation. Default value is false.
    • position string (optional) - The windows position on screen. Supported values are default, screenCenter, desktopCenter, mainCenter and ownerCenter. Default value is default.
    • stayOnTop boolean (optional) - Stays on top of other windows.
    • border string (optional) - Border kind of the window. Supported values are none, single and sizeable. Default value is sizeable.
    • borderIcons string[] (optional) - Array of icons to be shown in the title bar of the window. Supported values are maximize, minimize and close.

Create new application window.

show()

Show the application window.

showModal()

Show the application window as modal.

close()

Close the application window.

hide()

Hide the application window.

maximize()

Maximizes the application window.

minimize()

Minimizes the application window.

getWidth()

Returns number - The width of the application window.

setWidth(width)

  • width number - Width of the window.

Sets the width of the application window.

getHeight()

Returns number - The height of the application window.

setHeight(height)

  • height number - Height of the window.

Sets the height of the application window.

setTitle(label)

  • title string - Title of the window.

Sets the title of the application window.

register(id)

  • id string - Unique id for messaging.

Register the application window to receive messages sent through sendMessageTo() and sendMessageAll().

unregister()

Unregister the application from receiving messages.

sendMessageTo(id, message)

  • id string - ID of the window to send the message to.
  • message string - The message to be sent.

Send message to the window which was registered with id.

sendMessageAll(message)

  • message string - The message to be sent.

Sends message to all windows that registered for receiving messages.

Events

'window-close'

Event triggered when the window is closed.

'window-hide'

Event triggered when the window is hidden via hide().

'window-show'

Event triggered when the window is shown via show()/showModal().

'window-resize'

Event triggered when the window is resized. Object parameter with width and height properties.

'window-minimize'

Event triggered when the window is minimized.

'window-maximize'

Event triggered when the window is maximized.

'window-ready'

Event triggered when the window is ready.

'window-message'

Event triggered when the window receives a message. See Messaging between windows for further details.