App Activation Events
iTwin Studio apps are initialized by iTwin studio but there are certain activation events that allow you to customize their behavior/look and feel in all sort of ways. In this section, we shall introduce you to some of the available options
Backend events
Section titled “Backend events”-
activateBackend: If an iTwin Studio app has backend code to contribute, it will require a TypeScript module that contains an “activateBackend” function (defined in @bentley/studio-apps-backend-api). This function will be the entry point for any backend code and should be where your app’s IPC should be registered.The path to the file that contains this function should be passed to the studio-cli apps build command via the
--backendEntryflag -
deactivateBackend: This function could also be added to the file that was listed as a “backendEntry”. It will execute when an app is unloaded or exited and should contain any backend cleanup code that your app requires (de-registration of IPC, etc.). -
startupOptions: If you need to customizeIModelHostOptions, export astartupOptionsfunction and return whichever parameters you want to customize. They will be merged with iTwin Studio’s defaults. -
import { StudioHostConfigurableOpts } from "@bentley/studio-startup-apps-backend-api";import { IModelHost } from "@itwin/core-backend";export async function startupOptions(): Promise<StudioHostConfigurableOpts> {// access token is available when onlineconst accessToken = await IModelHost.authorizationClient?.getAccessToken();return {};}
Frontend events
Section titled “Frontend events”-
activateFrontend: If an iTwin Studio app has a frontend (any UI/UX), it will require a Typescript module that contains an “activateFrontend” function (defined in @bentley/studio-apps-frontend-api). This function will be the entry point for any frontend code and should be where UiItemsProviders are registered.The path to the file that contains this function should be passed to the studio-cli apps tool via the
--frontendEntryargument. -
deactivateFrontend: This function could also be added to the file that was listed as a “frontendEntry”. It will execute when an app is uninstalled or unloaded and should contain any frontend cleanup code that your app requires (de-registration of UiItemsProviders, etc.). -
startupOptions: If you need to customize IModelAppOptions export a startupOptions function and return whichever parameters you want to customize. They will be merged with iTwin Studio’s defaults.import { StudioAppConfigurableOpts } from "@bentley/studio-startup-apps-frontend-api";import { IModelApp } from "@itwin/core-frontend";export async function startupOptions(): Promise<StudioAppConfigurableOpts> {// access token is available when onlineconst accessToken = await IModelApp.authorizationClient?.getAccessToken();return {};}