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 supportedhtml
string - The HTML file to be loaded.width
number (optional) - Width of the window. Default value is640
.height
number (optional) - Height of the window. Default value is480
.title
string (optional) - Title of the window. Default value is""
.minimized
boolean (optional) - The window will be minimized upon creation. Default value isfalse
.maximized
boolean (optional) - The window will be maximized upon creation. Default value isfalse
.position
string (optional) - The windows position on screen. Supported values aredefault
,screenCenter
,desktopCenter
,mainCenter
andownerCenter
. Default value isdefault
.stayOnTop
boolean (optional) - Stays on top of other windows.border
string (optional) - Border kind of the window. Supported values arenone
,single
andsizeable
. Default value issizeable
.borderIcons
string[] (optional) - Array of icons to be shown in the title bar of the window. Supported values aremaximize
,minimize
andclose
.
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.