Platform
Overview
Available since io.Connect Desktop 10.0 & @interopio/desktop 6.16.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 shut down, 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);Platform Preferences
Available since io.Connect Desktop 10.6 & @interopio/desktop 6.24.0
The Platform Preferences API enables you to retrieve, update, and reset the platform preferences, and to get notified when they change. The Platform Preferences API is accessible via the io.platform.prefs object.
ℹ️ For details on providing default and locked values for the platform preferences, and for details on the precedence order in which platform preferences are applied, see the Developers > Configuration > System > Platform Preferences section.
Retrieve
To retrieve the platform preferences, use the get() method. It resolves with a PlatformPreferences object containing the preferences currently in effect, the preferences saved by the user, the default and locked values provided via configuration, and the default values provided by the platform:
const { values, user, defaults, locked, builtIn } = await io.platform.prefs.get();
console.log(`Notification toasts will be hidden after ${values.notifications.settings.toastExpiry} ms.`);Update
To update the platform preferences, use the update() method. The changes will be merged with the existing user preferences - nested objects will be merged with the existing ones, and arrays will replace the existing ones.
Locked settings and invalid values will be ignored. The method resolves with a PreferencesUpdateResult object whose ignored property contains the paths of the ignored settings in dot notation:
const changes = { notifications: { settings: { toastExpiry: 5000 } } };
const { ignored } = await io.platform.prefs.update(changes);
if (ignored.length > 0) {
console.warn(`The following settings weren't saved: ${ignored.join(", ")}`);
}⚠️ Note that the
update()method can't be used for changing the schedules for platform restart and shutdown - the schedule settings will be ignored. Use the Platform Schedules API instead.
Reset
To remove the user preferences for specific settings, use the reset() method and pass an array of paths in dot notation to the settings to reset. The settings will use the default values provided via configuration or by the platform. Locked settings will remain unchanged:
await io.platform.prefs.reset(["notifications.settings.toastExpiry", "downloadManager.autoSave"]);Events
To get notified when the platform preferences change, use the subscribe() method. The handler will be invoked with the current platform preferences and after that on each update:
const handler = ({ values }) => console.log(values);
const unsubscribe = io.platform.prefs.subscribe(handler);Platform Schedules
Available since io.Connect Desktop 10.6 & @interopio/desktop 6.24.0
The Platform Schedules API enables you to retrieve, update, and reset the schedules for platform restart and shutdown, and to get notified when they change. The Platform Schedules API is accessible via the io.platform.schedules object.
ℹ️ For details on providing default and locked values for the schedules for platform restart and shutdown, and for details on the precedence order in which platform preferences are applied, see the Developers > Configuration > System > Platform Preferences section.
Retrieve
To retrieve the schedules for platform restart and shutdown, use the list() method. It resolves with an array of Schedule objects describing the restart and the shutdown schedules, in that order:
const [restartSchedule, shutdownSchedule] = await io.platform.schedules.list();To retrieve a specific schedule, use the get() method and pass the name of the schedule. The locked property of the returned object contains the names of the schedule settings locked via configuration:
const { enabled, time, repeat, day, locked } = await io.platform.schedules.get("restart");Update
To update a schedule, use the update() method. Pass the name of the schedule and a ScheduleUpdate object with the settings to change. Locked and unspecified settings will remain unchanged. Changing the time, repeat, or day property will replace the custom cron expression of the schedule, unless you specify a new one in the cron property.
Use the options property to specify settings for the warning dialog displayed to the user before the scheduled operation and whether to save the current Global Layout. If you specify the warning object, it will replace the existing warning settings entirely. The method resolves with a Schedule object describing the updated schedule:
const changes = {
enabled: true,
time: "02:00",
repeat: "weekly",
day: "friday",
options: {
warning: {
title: "Scheduled Restart",
message: "io.Connect Desktop will restart in 2 minutes.",
countdown: 120
},
autoSaveLayout: true
}
};
const updatedSchedule = await io.platform.schedules.update("restart", changes);Reset
To remove the user settings for a schedule, use the reset() method. The custom cron expression and the custom options of the schedule will also be removed, and the schedule will use the settings provided via configuration or by the platform. Locked settings will remain unchanged. The method resolves with a Schedule object describing the reset schedule:
const resetSchedule = await io.platform.schedules.reset("shutdown");Events
To get notified when a schedule changes, use the onChanged() method. The handler will receive a Schedule object describing the changed schedule as an argument. The handler will be invoked separately for each changed schedule and won't be invoked when you subscribe:
const handler = ({ name, enabled, time }) => console.log(`The ${name} schedule is ${enabled ? `set for ${time}` : "disabled"}.`);
const unsubscribe = io.platform.schedules.onChanged(handler);API Reference
For a complete list of the available Platform API methods and properties, see the Platform API reference documentation.