Platform

Overview

Available since io.Connect Desktop 10.0

The Platform API is accessible via the io.platform object.

Restart

To restart the io.Connect platform, use the restart() method:

await io.platform.restart();

The restart() method accepts an ExitOptions object as an optional argument. Use this object to specify settings for the restart operation:

const options = {
    // Instructing the platform to save the current Global Layout before restarting.
    autoSave: true,
    // Disabling showing a dialog to the user.
    showDialog: false,
    // Specifying a reason for the platform restart.
    reason: "Platform restarted to apply updates."
};

await io.platform.restart(options);

Shut Down

To shut down the io.Connect platform, use the shutdown() method:

await io.platform.shutdown();

The shutdown() method accepts an ExitOptions object as an optional argument. Use this object to specify settings for the shutdown operation:

const options = {
    // Instructing the platform to save the current Global Layout before shutdown.
    autoSave: true,
    // Disabling showing a dialog to the user.
    showDialog: false,
    // Specifying a reason for the platform shutdown.
    reason: "Scheduled platform shutdown."
};

await io.platform.shutdown(options);

Events

To get notified when the platform is about to be restarted or shutdown, use the onShuttingDown() method and provide a handler for the event. The handler will receive a ShuttingDownEventArgs object as an argument.

This event enables you to execute custom code before the platform restarts or shuts down. The available time for the execution of your code is 60 seconds:

const handler = async ({ restarting, reason, initiator }) => {
    // Use the `restarting` flag to determine whether that platform is being restarted or shut down.
    console.log(`Platform is being ${restarting ? "restarted" : "shut down"} by "${initiator.applicationName}" due to: ${reason}`);

    // Your custom code will be executed before platform restart or shutdown and will be awaited up to 60 seconds.
    await executeMyCustomCode();
};

const unsubscribe = io.platform.onShuttingDown(handler);

To prevent shutdown or restart of the platform, the handler must resolve with an object with a prevent property set to true:

// Preventing platform restart or shutdown.
const handler = async () => {
    await executeMyCustomCode();

    return { prevent: true };
};

io.platform.onShuttingDown(handler);

API Reference

For a complete list of the available Platform API methods and properties, see the Platform API reference documentation.