1. Recipes
  2. Managing Windows Programmatically


Managing Windows Programmatically

Windows that are created with ToDesktop Builder can be managed programmatically through the @todesktop/client-core API.

Getting the Window ID

After you have configured your window, take note of the "Window ID" value. This is the identifier for your windows, and can be used to manage the window programmatically from your app code. Copy this value to your clipboard.

ToDesktop Builder interface with the Window ID hightlighted.

Managing the Window from your app code.

To manage a window programmatically, you'll need the @todesktop/client-core NPM package installed in your project. From this package, we'll import the following:

        import { object, nativeWindow } from '@todesktop/client-core';

  • object exposes functions for retrieving primitives such as trays and windows.
  • nativeWindow exposes functions for manipulating windows.

With @todesktop/client-core installed, managing a window is as a simple as retrieving the window reference and calling the nativeWindow utility functions. For example, we can do the following to show the window and get the window dimensions:

        const winIdFromToDesktopBuilder = 'uCpx0KV2eUa1VZUw5AEiC';

const winRef = await object.retrieve({ id: winIdFromToDesktopBuilder });
await nativeWindow.show({ ref: winRef });
const [width, height] = await nativeWindow.getSize({ ref: winRef });

console.log(`Window is now visible with dimensions of ${width}x${height}`);