1. API
  2. nativeWindow

API

Methods for querying and manipulating elements pertaining to a native ToDesktop window shell.

Remarks

This package exposes a number of methods for querying and manipulating elements pertaining to a native ToDesktop window shell.

Functions

Function Description
addBrowserView({ ref, viewRef, }) Adds a BrowserView to the reference BrowserWindow.
areTabsSupported()
blur() Removes the current window from focus on the user's desktop.
close({ ref }) Close the BrowserWindow corresponding to the ref.
create(options) Creates a new BrowserWindow.
createNewTab() Creates a new tab and loads the pre-defined app URL.
destroy({ ref }) Destroys the BrowserWindow corresponding to the ref.
enterFullscreen() Enters fullscreen mode on the current ToDesktop window.
exitFullscreen() Exits fullscreen mode on the current ToDesktop window.
focus() Causes the current window to be focussed on the user's desktop.
getAllWindows()
getSize({ ref }) Gets the width and height of the reference browser window
getTitle({ ref }) The title of the native window.
getWebContents({ ref }) Get a WebContents reference for a BrowserWindow. WebContents is responsible for rendering and controlling a web page
hide({ ref }) Hides the BrowserWindow corresponding to the ref.
isFullscreen() Returns true if the current ToDesktop window is in fullscreen mode.
isMaximized() Returns true if the current ToDesktop window is maximized.
isMinimized() Returns true if the current ToDesktop window is minimized.
maximize() Maximises the current ToDesktop window.
minimize() Minimize the current window.
reload({ ref }) Reloads the web page.
removeBrowserView({ ref, viewRef, }) Removes a BrowserView from the reference BrowserWindow.
restore() Unminimize the current window.
setAlwaysOnTop({ ref }, args) Sets whether the window should show always on top of other windows. After setting this, the window is still a normal window, not a toolbox window which can not be focused on.
setBrowserView({ ref, viewRef, }) Sets a BrowserView on the reference BrowserWindow. If there are other BrowserViews attached, they will be removed from the window.
setContentProtection({ ref }, args) Prevents the window contents from being captured by other apps.
setIcon({ ref }, args) Changes window icon.
setProgressBar(percent)
setTitle({ ref, title }) Changes the title of the reference BrowserWindow.
show({ ref }) Shows the BrowserWindow corresponding to the ref.
unmaximize() Minimizes the current ToDesktop window.

addBrowserView()

Adds a BrowserView to the reference BrowserWindow.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.addBrowserView({ ref, viewRef, }: {
    ref?: Ref;
    viewRef: Ref;
}): Promise<void>;

      
Parameters
Parameter Type Description
{ ref, viewRef, } { ref?: Ref; viewRef: Ref; }

Returns:

Promise<void>

areTabsSupported()

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.areTabsSupported(): Promise<boolean>;

      

Returns:

Promise<boolean>

blur()

Removes the current window from focus on the user's desktop.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.blur(): Promise<void>;

      

Returns:

Promise<void>

close()

Close the BrowserWindow corresponding to the ref.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.close({ ref }?: RefOptions): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<void>

create()

Creates a new BrowserWindow.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.create(options: BrowserWindowConstructorOptions): Promise<Ref>;

      
Parameters
Parameter Type Description
options BrowserWindowConstructorOptions BrowserWindow constructor options.

Returns:

Promise<Ref>

Identifier for the newly created BrowserWindow.

createNewTab()

Creates a new tab and loads the pre-defined app URL.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.createNewTab(): Promise<void>;

      

Returns:

Promise<void>

destroy()

Destroys the BrowserWindow corresponding to the ref.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.destroy({ ref }?: RefOptions): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<void>

enterFullscreen()

Enters fullscreen mode on the current ToDesktop window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.enterFullscreen(): Promise<void>;

      

Returns:

Promise<void>

Example

        import { nativeWindow } from "@todesktop/client";

const video: HTMLVideoElement;

video.addEventListener("play", async () => {
  nativeWindow.enterFullScreen();
});


      

exitFullscreen()

Exits fullscreen mode on the current ToDesktop window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.exitFullscreen(): Promise<void>;

      

Returns:

Promise<void>

Example

        import { nativeWindow } from "@todesktop/client";

const video: HTMLVideoElement;

video.addEventListener("suspend", async () => {
  nativeWindow.exitFullScreen();
});


      

focus()

Causes the current window to be focussed on the user's desktop.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.focus(): Promise<void>;

      

Returns:

Promise<void>

getAllWindows()

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.getAllWindows(): Promise<InstanceRefObject[]>;

      

Returns:

Promise<InstanceRefObject[]>

An array of all opened browser windows.

getSize()

Gets the width and height of the reference browser window

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.getSize({ ref }?: RefOptions): Promise<number[]>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<number[]>

getTitle()

The title of the native window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.getTitle({ ref }?: RefOptions): Promise<string>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<string>

getWebContents()

Get a WebContents reference for a BrowserWindow. WebContents is responsible for rendering and controlling a web page

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.getWebContents({ ref }?: RefOptions): Promise<InstanceRefObject>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<InstanceRefObject>

hide()

Hides the BrowserWindow corresponding to the ref.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.hide({ ref }?: RefOptions): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<void>

isFullscreen()

Returns true if the current ToDesktop window is in fullscreen mode.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.isFullscreen(): Promise<boolean>;

      

Returns:

Promise<boolean>

Example

        import { nativeWindow } from "@todesktop/client";

if (nativeWindow.isFullscreen) {
  // change something in the UI
}


      

isMaximized()

Returns true if the current ToDesktop window is maximized.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.isMaximized(): Promise<boolean>;

      

Returns:

Promise<boolean>

isMinimized()

Returns true if the current ToDesktop window is minimized.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.isMinimized(): Promise<boolean>;

      

Returns:

Promise<boolean>

maximize()

Maximises the current ToDesktop window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.maximize(): Promise<void>;

      

Returns:

Promise<void>

minimize()

Minimize the current window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.minimize(): Promise<void>;

      

Returns:

Promise<void>

reload()

Reloads the web page.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.reload({ ref }?: RefOptions): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<void>

removeBrowserView()

Removes a BrowserView from the reference BrowserWindow.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.removeBrowserView({ ref, viewRef, }: {
    ref?: Ref;
    viewRef: Ref;
}): Promise<void>;

      
Parameters
Parameter Type Description
{ ref, viewRef, } { ref?: Ref; viewRef: Ref; }

Returns:

Promise<void>

restore()

Unminimize the current window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.restore(): Promise<void>;

      

Returns:

Promise<void>

setAlwaysOnTop()

Sets whether the window should show always on top of other windows. After setting this, the window is still a normal window, not a toolbox window which can not be focused on.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setAlwaysOnTop({ ref }: RefOptions, ...args: Parameters<BrowserWindow["setAlwaysOnTop"]>): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions
args Parameters&lt;BrowserWindow["setAlwaysOnTop"]>

Returns:

Promise<void>

setBrowserView()

Sets a BrowserView on the reference BrowserWindow. If there are other BrowserViews attached, they will be removed from the window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setBrowserView({ ref, viewRef, }: {
    ref?: Ref;
    viewRef: Ref;
}): Promise<void>;

      
Parameters
Parameter Type Description
{ ref, viewRef, } { ref?: Ref; viewRef: Ref; }

Returns:

Promise<void>

setContentProtection()

Prevents the window contents from being captured by other apps.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setContentProtection({ ref }: RefOptions, ...args: Parameters<BrowserWindow["setContentProtection"]>): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions
args Parameters&lt;BrowserWindow["setContentProtection"]>

Returns:

Promise<void>

setIcon()

Changes window icon.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setIcon({ ref }: RefOptions, ...args: [InstanceRefObject]): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions
args [InstanceRefObject]

Returns:

Promise<void>

setProgressBar()

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setProgressBar(percent: number): Promise<void>;

      
Parameters
Parameter Type Description
percent number An float between 0-1 will set the progress bar to a certain percentage. e.g. 0.75 will show a progress bar 75% filled.Values above 1 will enable intermediate mode.Values below 0 will disable the progress bar.

Returns:

Promise<void>

setTitle()

Changes the title of the reference BrowserWindow.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.setTitle({ ref, title }: {
    ref?: Ref;
    title: string;
}): Promise<void>;

      
Parameters
Parameter Type Description
{ ref, title } { ref?: Ref; title: string; }

Returns:

Promise<void>

show()

Shows the BrowserWindow corresponding to the ref.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.show({ ref }?: RefOptions): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } RefOptions

Returns:

Promise<void>

unmaximize()

Minimizes the current ToDesktop window.

Signature:

        import { nativeWindow } from "@todesktop/client-core"
nativeWindow.unmaximize(): Promise<void>;

      

Returns:

Promise<void>

Variables

Variable Description
on
removeAllListeners

on

Signature:

        on: <E extends "minimize" | "close" | "hide" | "blur" | "focus" | "maximize" | "restore" | "show" | "unmaximize" | "resize" | "new-window-for-tab" | "always-on-top-changed" | "app-command" | "closed" | "enter-full-screen" | "enter-html-full-screen" | "leave-full-screen" | "leave-html-full-screen" | "move" | "moved" | "page-title-updated" | "ready-to-show" | "resized" | "responsive" | "rotate-gesture" | "scroll-touch-begin" | "scroll-touch-edge" | "scroll-touch-end" | "session-end" | "sheet-begin" | "sheet-end" | "swipe" | "unresponsive" | "will-move" | "will-resize">(eventName: E, callback: NamespaceEvents<{
    "always-on-top-changed": (isAlwaysOnTop: boolean) => void;
    "app-command": (command: string) => void;
    blur: () => void;
    close: () => void;
    closed: () => void;
    "enter-full-screen": () => void;
    "enter-html-full-screen": () => void;
    focus: () => void;
    hide: () => void;
    "leave-full-screen": () => void;
    "leave-html-full-screen": () => void;
    maximize: () => void;
    minimize: () => void;
    move: () => void;
    moved: () => void;
    "new-window-for-tab": () => void;
    "page-title-updated": (title: string, explicitSet: boolean) => void;
    "ready-to-show": () => void;
    resize: () => void;
    resized: () => void;
    responsive: () => void;
    restore: () => void;
    "rotate-gesture": (rotation: number) => void;
    "scroll-touch-begin": () => void;
    "scroll-touch-edge": () => void;
    "scroll-touch-end": () => void;
    "session-end": () => void;
    "sheet-begin": () => void;
    "sheet-end": () => void;
    show: () => void;
    swipe: (direction: string) => void;
    unmaximize: () => void;
    unresponsive: () => void;
    "will-move": (newBounds: Rectangle) => void;
    "will-resize": (newBounds: Rectangle, details: WillResizeDetails) => void;
}>[E], { ref, preventDefault }?: {
    ref?: InstanceRefObject;
    preventDefault?: boolean;
}) => Promise<() => Promise<void>>

      

removeAllListeners

Signature:

        removeAllListeners: <E extends "minimize" | "close" | "hide" | "blur" | "focus" | "maximize" | "restore" | "show" | "unmaximize" | "resize" | "new-window-for-tab" | "always-on-top-changed" | "app-command" | "closed" | "enter-full-screen" | "enter-html-full-screen" | "leave-full-screen" | "leave-html-full-screen" | "move" | "moved" | "page-title-updated" | "ready-to-show" | "resized" | "responsive" | "rotate-gesture" | "scroll-touch-begin" | "scroll-touch-edge" | "scroll-touch-end" | "session-end" | "sheet-begin" | "sheet-end" | "swipe" | "unresponsive" | "will-move" | "will-resize">(eventName: E, { ref, }?: {
    ref?: InstanceRefObject;
}) => Promise<void>

      

Type Aliases

LegacyNativeWindowEvent

EVENTS

Signature:

        export declare type LegacyNativeWindowEvent = "enterFullscreen" | "exitFullscreen";

      

NativeWindowEvents

Signature:

        export declare type NativeWindowEvents = NamespaceEvents<{
    "always-on-top-changed": (isAlwaysOnTop: boolean) => void;
    "app-command": (command: string) => void;
    blur: () => void;
    close: () => void;
    closed: () => void;
    "enter-full-screen": () => void;
    "enter-html-full-screen": () => void;
    focus: () => void;
    hide: () => void;
    "leave-full-screen": () => void;
    "leave-html-full-screen": () => void;
    maximize: () => void;
    minimize: () => void;
    move: () => void;
    moved: () => void;
    "new-window-for-tab": () => void;
    "page-title-updated": (title: string, explicitSet: boolean) => void;
    "ready-to-show": () => void;
    resize: () => void;
    resized: () => void;
    responsive: () => void;
    restore: () => void;
    "rotate-gesture": (rotation: number) => void;
    "scroll-touch-begin": () => void;
    "scroll-touch-edge": () => void;
    "scroll-touch-end": () => void;
    "session-end": () => void;
    "sheet-begin": () => void;
    "sheet-end": () => void;
    show: () => void;
    swipe: (direction: string) => void;
    unmaximize: () => void;
    unresponsive: () => void;
    "will-move": (newBounds: Rectangle) => void;
    "will-resize": (newBounds: Rectangle, details: WillResizeDetails) => void;
}>;

      
Type Alias Description
LegacyNativeWindowEvent EVENTS
NativeWindowEvents