1. Recipes
  2. Working with the ToDesktop API


Working with the ToDesktop API

ToDesktop provides core APIs for interacting with ToDesktop applications.

ToDesktop SDK

The @todesktop/client-core packages exposes useful functions for directly interacting with your todesktop app. You can install @todesktop/client-core in the codebase of the web app that you’re converting into a desktop app:

        npm install @todesktop/client-core


Using the SDK is as simple as importing the desired functionality for use in your desktop app.

        import { platform, notification } from '@todesktop/client-core';

if (platform.todesktop.isDesktopApp()) {
  notification.create({ title: 'Desktop App Notificiation' });


platform.todesktop.isDesktopApp will evaluate to true if the function is invoked within the context of a desktop app. notification.create will then create a native notification alert.

How It Works

When your desktop application is first loaded, ToDesktop exposes a window.todesktop object which provides information about the device as well as methods that provide extra features.

Functionality from @todesktop/client-core communicates with this window.todesktop object, but also provides safeguards to ensure backwards and forwards compatibility. For example, @todesktop/client-core may expose functionality which requires a certain desktop app runtime. If it detects that desktop app runtime is not suitable, it will log a warning in the browser instead of throwing an error.


In other words, prefer using @todesktop/client-core over the window.todesktop object directly. Additionally, @todesktop/client-core is strongly-typed which provides for a better developer experience.