Skip to content

Commit c053249

Browse files
authored
Merge pull request #11400 from SofiBili/development
update extension docs
2 parents 1c3b191 + f646ce5 commit c053249

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/permissions.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@ When a user installs an extension that requests permissions, they can manage tho
5252
3. Find the extension in the list.
5353
4. In the **Permissions** section under the extension details, select or clear the checkbox next to each permission to grant or revoke access.
5454

55+
## Reacting to Permission Changes
56+
57+
Extensions can subscribe to the `permissionsChanged` event on `IExtensionPermissionsApi` to be notified whenever the user grants or revokes permissions for any extension. This allows you to reactively update your extension's behavior without requiring a restart.
58+
59+
The event carries no arguments. When it fires, call `getPermissions()` to retrieve the current state.
60+
Update your `main/index.ts` to the following to detect when a permission changes.
61+
62+
```typescript
63+
import { IComponent, getStudioProApi } from "@mendix/extensions-api";
64+
65+
export const component: IComponent = {
66+
async loaded(componentContext) {
67+
const studioPro = getStudioProApi(componentContext);
68+
69+
const permissionsApi = studioPro.ui.extensionPermissions;
70+
71+
let currentPermissions = await permissionsApi.getPermissions();
72+
73+
permissionsApi.addEventListener("permissionsChanged", async () => {
74+
const permissionsAfterChange = await permissionsApi.getPermissions();
75+
76+
for (const permission of permissionsAfterChange) {
77+
if (currentPermissions.find(p => p.name === permission.name)?.granted !== permission.granted) {
78+
if (permission.name === "runtime-configuration-private" && permission.granted === false) {
79+
studioPro.ui.notifications.show({
80+
title: "This extension requires a permission",
81+
message: "We need the 'runtime-configuration-private' permission to be granted",
82+
displayDurationInSeconds: 3
83+
});
84+
}
85+
}
86+
}
87+
88+
currentPermissions = permissionsAfterChange;
89+
});
90+
}
91+
};
92+
```
93+
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 respond to the same event simultaneously.
94+
95+
To check if a change affects your extension, compare the old granted state against the new one for each permission name your extension declared. Without this check, your extension fires a notification every time any permission changes, including changes unrelated to your extension.
96+
5597
## Available Permissions
5698

5799
The following permissions are available for web extensions:

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/preference-api.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ Before starting this how-to, complete the following prerequisites:
2323

2424
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/).
2525

26-
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.
26+
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.
27+
28+
{{% alert type="info" %}}
29+
Seeing the current Studio Pro version is available for Studio Pro 11.12 and above.
30+
{{% /alert %}}
2731

2832
Replace your `src/main/index.ts` file with the following:
2933

@@ -46,7 +50,7 @@ export const component: IComponent = {
4650

4751
await messageBoxApi.show(
4852
"info",
49-
`User Preferences are:\n Theme is: ${preferences.theme}\n Language is: ${preferences.language}`
53+
`User Preferences are:\n Theme is: ${preferences.theme}\n Language is: ${preferences.language}\nVersion is: ${preferences.version}\n`
5054
);
5155
};
5256

@@ -71,6 +75,7 @@ The `getPreferences()` function returns an object with two properties:
7175

7276
* Theme – either **Light** or **Dark**, representing the current theme setting in Studio Pro
7377
* Language – a string representing the current language setting, such as `en_US` for English (United States)
78+
* Version - a string representing the current version of Studio Pro, such as `11.12.0`.
7479

7580
## Extensibility Feedback
7681

content/en/docs/releasenotes/studio-pro/web-extensibility-api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ numberless_headings: true
88

99
These release notes cover changes to the [Extensibility API for Web Developers](/apidocs-mxsdk/apidocs/extensibility-api/).
1010

11+
## Version 11.12.0
12+
13+
* We added a `permissionsChanged` event to the [Permissions API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/extension-permissions/) that notifies you when the user changes the permissions of your extension.
14+
* We added the `documentsChanged` event, which notifies you when a document that your extension depends on is modified in Studio Pro.
15+
* The Studio Pro version is now available through the [Preferences API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/preference-api/).
16+
1117
## Version 11.11.0
1218

1319
* 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.

0 commit comments

Comments
 (0)