Neutralino.window
The Neutralino.window namespace contains methods related to the current native window instance.
This namespace's methods will work only for the window mode.
window.setTitle(title)
Sets the title of the native window.
Parameters
titleString (optional): Title of the window. Clears the title, if the function was called without the parameter.
await Neutralino.window.setTitle('New title');
window.getTitle()
Returns the title of the native window.
Return String (awaited):
The current title of the native window instance.
let title = await Neutralino.window.getTitle();
console.log(`title = ${title}`);
window.minimize()
Minimizes the native window.
await Neutralino.window.minimize();
window.unminimize()
Restores the native window from the minimized state.
await Neutralino.window.unminimize();
window.isMinimized()
Returns true if the native window is minimized.
Return Boolean (awaited):
trueorfalsebased on current minimized status.
let status = await Neutralino.window.isMinimized();
window.maximize()
Maximizes the native window.
await Neutralino.window.maximize();
window.unmaximize()
Restores the native window.
await Neutralino.window.unmaximize();
window.isMaximized()
Returns true if the native window is maximized.
Return Boolean (awaited):
trueorfalsebased on current maximized status.
let status = await Neutralino.window.isMaximized();
window.setFullScreen()
Enables the full screen mode.
await Neutralino.window.setFullScreen();
window.exitFullScreen()
Exits from the full screen mode.
await Neutralino.window.exitFullScreen();
window.isFullScreen()
Returns true if the native window is in the full screen mode.
Return Boolean (awaited):
trueorfalsebased on current full screen status.
let status = await Neutralino.window.isFullScreen();
window.show()
Shows the native window.
await Neutralino.window.show();
window.hide()
Hides the native window.
await Neutralino.window.hide();
window.isVisible()
Returns true if the native window is visible.
Return Boolean (awaited):
trueorfalsebased on current visibility status.
let status = await Neutralino.window.isVisible();
window.focus()
Focuses the native window.
await Neutralino.window.focus();
window.setAlwaysOnTop(onTop)
Activates or deactivates the always on top mode.
Parameters
onTopBoolean (optional): Says whether the on top mode should be activated or not. The default value istrue.
await Neutralino.window.setAlwaysOnTop(true); // or setAlwaysOnTop();
await Neutralino.window.setAlwaysOnTop(false);
window.move(x, y)
Moves the native window into given coordinates. Neutralinojs's cross-platform coordinate system starts from top-left corner of the screen.
In other words, x=0,y=0 point refers to the top-left corner of the device's main screen.
Parameters
xNumber: An integer value for the horizontal position.yNumber: An integer value for the vertical position.
await Neutralino.window.move(200, 400);
window.center()
Centers the native app window within the current display.
await Neutralino.window.center();
window.setIcon(icon)
Sets an icon for the native window or Dock.
Parameters
iconString: Path of the icon. A200x200PNG image file works fine on all supported operating systems.
const icon = '/resources/icons/appIcon.png';
await Neutralino.window.setIcon(icon);
window.setDraggableRegion(domId, options)
Converts a given DOM element to a draggable region. The user will be able to drag the native window by dragging the given DOM element. This feature is suitable to make custom window bars along with the borderless mode.
Parameters
domIdString | HTMLElement: A DOM element identifier.optionsDraggableRegionOptions (optional): Customize the behavior of the draggable region.
DraggableRegionOptions
exclusionsString[] | HTMLElement[] (optional): DOM element identifiers that should be excluded from the draggable region surface, i.e., window control buttons
Return Object (awaited):
exclusionsDraggableRegionExclusions: Add or remove draggable region exclusions.
DraggableRegionExclusions
add(...domIds: String | HTMLElement): Add new elements to exclusions.remove(...domIds: String | HTMLElement): Remove elements from exclusions.removeAll(): Clear exclusions.
await Neutralino.window.setDraggableRegion('myCustomTitleBar');
await Neutralino.window.setDraggableRegion('myCustomTitleBar', {
exclusions: ['closeButton', 'helpButton']
});
const d = await Neutralino.window.setDraggableRegion('myCustomTitleBar', {
exclusions: ['windowControls', 'tags']
});
d.exclusions.add('notifications');
d.exclusions.remove('tags');
window.unsetDraggableRegion(domId)
Converts a draggable region to a normal DOM elements by removing drag event handlers.
Parameters
domIdString | HTMLElement: A DOM element identifier.
await Neutralino.window.unsetDraggableRegion('myCustomTitleBar');
window.setSize(Options)
This method sets the size of the window.
Options
widthNumber (optional): Window width in pixels.heightNumber (optional): Window height in pixels.minWidthNumber (optional): Minimum width of the window in pixels.minHeightNumber (optional): Minimum height of the window in pixels.maxWidthNumber (optional): Maximum width of the window in pixels.maxHeightNumber (optional): Maximum height of the window in pixels.resizableBoolean (optional): A boolean value to make the window resizable or fixed.
This method always expects width and height couples.
For example, if you are setting minWidth, you should set minHeight too.
await Neutralino.window.setSize({
width: 500,
height: 200,
maxWidth: 600,
maxHeight: 400
});
await Neutralino.window.setSize({
resizable: false
});
window.getSize()
Returns window size information.
Return Boolean (awaited):
widthNumber: Window width in pixels.heightNumber: Window height in pixels.minWidthNumber Minimum width of the window in pixels.minHeightNumber: Minimum height of the window in pixels.maxWidthNumber: Maximum width of the window in pixels.maxHeightNumber: Maximum height of the window in pixels.resizableBoolean: Says whether the window resizable or fixed.
let sizeInfo = await Neutralino.window.getSize();
console.log(sizeInfo);
window.getPosition()
Returns window position coordinates.
Return Boolean (awaited):
xNumber: Horizontal coordinate of the left edge of the window.yNumber: Vertical coordinate of the top edge of the window.
let position = await Neutralino.window.getPosition();
console.log(position);
window.snapshot(path)
Takes a snapshop of the current window client area (without the window frame) and stores as a PNG image file.
Parameters
pathString: Path where the snapshot PNG file should be stored.
await Neutralino.window.snapshot(NL_PATH + '/images/window.png');
window.create(url, WindowOptions)
Creates a native window. You can use this method to create new window for your multi-window Neutralinojs app. Neutralinojs spawns a new process for each native window. Therefore, the new window works as an isolated app once the window is created.
However, you can build communication streams between windows with the storage API.
Parameters
urlString: URL to be loaded. Eg:/resources/aboutWindow.html. Supports loading both local and remote app resources. Local resource paths need to begin with/.options(optional): an instance ofWindowOptionstype.
WindowOptions
titleString: Window title.iconString: Window icon path.fullScreenBoolean: Sets full screen mode.alwaysOnTopBoolean: Activates the top-most mode.enableInspectorBoolean: Activates developer tools and opens the web inspector window.borderlessBoolean: Makes the window borderless.maximizeBoolean: Launches the window maximized.hiddenBoolean: Hides the window.maximizableBoolean: Makes the window maximizable or not.exitProcessOnCloseBoolean: Exits the application process when the user clicks the window's close button.widthNumber: Window width.heightNumber: Window height.xNumber: Windowxposition.yNumber: Windowyposition.minWidthNumber: Minimum width of the window.minHeightNumber: Minimum height of the window.maxWidthNumber: Maximum width of the window.maxHeightNumber: Maximum height of the window.extendUserAgentWithString: Extends the user agent string of the webview instance.injectGlobalsBoolean: Injects global variables directly to the webview instance.injectClientLibraryBoolean: Injects the client library source directly to the webview instance.injectScriptBoolean: A preload JavaScript source file that executes before web app resources.processArgsString: Additional command-line arguments for the new window process. Check all supported internal command-line arguments from here.
Return Object (awaited):
pidNumber: Process identifier.stdOutString: Standard output. This value is always empty since the new window process starts asynchronously.stdErrString: Standard error. This value is always empty since the new window process starts asynchronously.exitCodeNumber: Exit code of the process.
await Neutralino.window.create('/resources/aboutWindow.html', {
icon: '/resources/icons/aboutIcon.png',
enableInspector: false,
width: 500,
height: 300,
maximizable: false,
exitProcessOnClose: true,
processArgs: '--window-id=W_ABOUT'
});
window.setMainMenu(menu)
Creates/updates the main window menu on GNU/Linux and Windows and application menu on macOS.
Parameters
menuWindowMenuItem[]: An array ofWindowMenuItemobjects.
WindowMenuItem
idString (optional): A unique identifier for each menu item.textString: Label of the menu item. This field is a mandatory field. Use-(hyphen) character for a menu separator.isDisabledBoolean (optional): A boolean flag to disable/enable a specific menu item.isCheckedBoolean (optional): A boolean flag to mark a specific menu item as selected.menuItemsWindowMenuItem[]: Submenu for the current menu item.shortcutString (optional): Sets a key accelerator on macOS (e.g.,cforCommand + C) and only displays the shortcut on GNU/Linux and Windows, e.g.,Ctrl + C.actionString (optional): Pre-defined window action for macOS, i.e.,cut:,copy:,paste:, etc.
const menu = [
{id: 'file', text: 'File',
menuItems: [
{id: 'open', text: 'Open'},
{text: '-'},
{id: 'quit', text: 'Quit'},
]},
{id: 'edit', text: 'Edit',
menuItems: [
{id: 'cut', text: 'Cut'},
{id: 'copy', text: 'Copy'},
{id: 'paste', text: 'Paste'},
]}
];
await Neutralino.window.setMainMenu(menu);
await Neutralino.on('mainMenuItemClicked', (evt) => {
console.log('Menu item:', evt.detail);
});
window.print()
Displays the native print dialog for the current page. Developers can use this function instead of the built-in web window.print() function as a cross-platform solution
since macOS webview doesn't pre-implement window.print().
await Neutralino.window.print();
window.beginDrag()
Starts dragging the native window if the left mouse button is pressed. The draggable region API in the Neutralinojs client library uses this function internally to move the window with the pointer events web API.
await Neutralino.window.beginDrag();