diff --git a/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/permissions.md b/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/permissions.md index 5c12fa45896..fc8b4b7a711 100644 --- a/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/permissions.md +++ b/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/permissions.md @@ -52,6 +52,49 @@ When a user installs an extension that requests permissions, they can manage tho 3. Find the extension in the list. 4. In the **Permissions** section under the extension details, select or clear the checkbox next to each permission to grant or revoke access. +## Reacting to Permission Changes + +Extensions can subscribe to the `permissionsChanged` event on `IExtensionPermissionsApi` to be notified whenever the user grants or revokes permissions for any of the extensions. This allows you to reactively update your extension's behaviour without requiring a restart. + +The event carries no arguments. When it fires, call `getPermissions()` to retrieve the current state. +Update you main/index.ts to the following to check when someone unchecked the permissions. + +```typescript +import { IComponent, getStudioProApi } from "@mendix/extensions-api"; + +export const component: IComponent = { + async loaded(componentContext) { + const studioPro = getStudioProApi(componentContext); + + const permissionsApi = studioPro.ui.extensionPermissions; + + let currentPermissions = await permissionsApi.getPermissions(); + + permissionsApi.addEventListener("permissionsChanged", async () => { + const permissionsAfterChange = await permissionsApi.getPermissions(); + + for (const permission of permissionsAfterChange) { + if (currentPermissions.find(p => p.name === permission.name)?.granted !== permission.granted) { + if (permission.name === "runtime-configuration-private" && permission.granted === false) { + studioPro.ui.notifications.show({ + title: "This extension requires a permission", + message: "We need the 'runtime-configuration-private' permission to be granted", + displayDurationInSeconds: 3 + }); + } + } + } + + currentPermissions = permissionsAfterChange; + }); + } +}; +``` +The `permissionsChanged` event fires for all extensions whenever any permission is granted or revoked anywhere in the system, not just for your extension. This means multiple extensions may be responding to the same event simultaneously. + +To check if the change happened for your extension you must compare the old granted state against the new one for the permission name you want to be granted. +Without this check, your extension would fire a notification every time any extension's permission changes, even ones completely unrelated to you. + ## Available Permissions The following permissions are available for web extensions: diff --git a/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/preference-api.md b/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/preference-api.md index dbdee3a6b11..c5159d9e60c 100644 --- a/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/preference-api.md +++ b/content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/preference-api.md @@ -23,7 +23,7 @@ Before starting this how-to, complete the following prerequisites: Create a menu that displays a dialog with text in the `loaded` method in the main entry point (`src/main/index.ts`). This can be done by following the steps in [Create a Menu Using Web API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu-api/). -In the example below, you create one menu item that shows a message box with the user's preferences, such as `Light` or `Dark` mode, and current language. +In the example below, you create one menu item that shows a message box with the user's preferences, such as `Light` or `Dark` mode, current language and the version of Studio Pro the user is using. Replace your `src/main/index.ts` file with the following: @@ -46,7 +46,7 @@ export const component: IComponent = { await messageBoxApi.show( "info", - `User Preferences are:\n Theme is: ${preferences.theme}\n Language is: ${preferences.language}` + `User Preferences are:\n Theme is: ${preferences.theme}\n Language is: ${preferences.language}\nVersion is: ${preferences.version}\n` ); }; @@ -71,6 +71,7 @@ The `getPreferences()` function returns an object with two properties: * Theme – either **Light** or **Dark**, representing the current theme setting in Studio Pro * Language – a string representing the current language setting, such as `en_US` for English (United States) +* Version - a string representing the current version of Studio Pro, such as `11.12.0`. ## Extensibility Feedback diff --git a/content/en/docs/releasenotes/studio-pro/web-extensibility-api.md b/content/en/docs/releasenotes/studio-pro/web-extensibility-api.md index e6b9cfdf71b..b1aa60152f2 100644 --- a/content/en/docs/releasenotes/studio-pro/web-extensibility-api.md +++ b/content/en/docs/releasenotes/studio-pro/web-extensibility-api.md @@ -8,6 +8,12 @@ numberless_headings: true These release notes cover changes to the [Extensibility API for Web Developers](/apidocs-mxsdk/apidocs/extensibility-api/). +## Version 11.12.0 + +* We added a `permissionsChanged` event that can help you know if the user changed the permissions of your extensions in the [Permissions API] (/apidocs-mxsdk/apidocs/web-extensibility-api-11/extension-permissions/) +* We added the `documentsChanged` event for when one of your dependencies gets modified in Studio Pro and is a dependency you can get notified. +* The version of the studio pro is available though the [Preferences API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/preference-api/). + ## Version 11.11.0 * We added a **New** button to the [Element Selector API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/element-selector-api/), which allows users to add new documents and entities from the element selector.