1. Recipes
  2. Version 1.0.0 Breaking Changes

Recipes

Version 1.0.0 Breaking Changes

With version 1.0.0 of @todesktop/client-core now released, please make note of the following breaking changes:

Updated signature when unsubscribing from listeners

Previously, creating listeners involved managing an eventId and passing it to an off invocation:

        const eventId = await electronUpdater.on('update-available', () => {
  // ...
});
// unsubscribing from update available events
await electronUpdater.off('update-available', { eventId });

      

Now, every on invocation will return a unsubscribe function. You can then execute this function to unsubscribe from the listener (note that unsubscribe is a function that returns a Promise and can thus be awaited):

        const unsubscribe = await nativeWindow.on('enter-full-screen', () => {
  console.log('enter full screen');
});
// successfully unsubscribes
await unsubscribe();

      

Naturally, this means we've removed off and removeEventListener from our namespace objects:

        await nativeWindow.off(...) // ❌
await nativeWindow.removeEventListener(...) // ❌

      

For the sake of completeness, we've also removed addEventListener as the on function is now preferred:

        await nativeWindow.addEventListener(...) // ❌
await nativeWindow.on(...) // ✅

      

New object namespace

For version 1.0.0, we're exposing a new object namespace. The object namespace allows you to programmatically control resources that you have defined in the ToDesktop Builder interface. For now, we're including support for controlling trays. See the following for an example:

ToDesktop Builder interface which showcases the currently-selected tray.
        import { object, tray } from '@todesktop/client-core';

const trayIdFromToDesktopBuilder = 'JWJ3pS82Oe-6IA7beIAhm';

const trayRef = await object.retrieve({ id: trayIdFromToDesktopBuilder });
await tray.setTitle({ ref: trayRef, title: 'Title' });

const title = await tray.getTitle({ ref: trayRef });
console.log(title); // Title

      

You can find a full recipe here.

releaseMemoryBindings moved to object namespace

Finally, we've moved releaseMemoryBindings from the performance namespace to the object namespace. This is particularly useful if you're managing a lot of object references and want to optimize performance.

Before:

        import { performance } from "@todesktop/client-core";

const objectRef = ...
await performance.releaseMemoryBindings(objectRef);

      

After:

        import { object } from "@todesktop/client-core";

const objectRef = ...
await object.releaseMemoryBindings(objectRef);