diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb68279 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +docs.zip diff --git a/docs.json b/docs.json index a746ed4..09a05e1 100644 --- a/docs.json +++ b/docs.json @@ -181,7 +181,9 @@ "en/api-reference/supernote-plugin/plugin-file-api/get-element-counts", "en/api-reference/supernote-plugin/plugin-file-api/get-element-num-list", "en/api-reference/supernote-plugin/plugin-file-api/get-element", - "en/api-reference/supernote-plugin/plugin-file-api/get-last-element" + "en/api-reference/supernote-plugin/plugin-file-api/get-last-element", + "en/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status", + "en/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password" ] }, { @@ -201,7 +203,9 @@ "en/api-reference/supernote-plugin/plugin-manager/get-plugin-dir-path", "en/api-reference/supernote-plugin/plugin-manager/get-plugin-name", "en/api-reference/supernote-plugin/plugin-manager/get-device-type", - "en/api-reference/supernote-plugin/plugin-manager/close-plugin-view" + "en/api-reference/supernote-plugin/plugin-manager/close-plugin-view", + "en/api-reference/supernote-plugin/plugin-manager/has-permission", + "en/api-reference/supernote-plugin/plugin-manager/request-permission" ] }, { @@ -412,7 +416,9 @@ "zh/api-reference/supernote-plugin/plugin-file-api/get-element-counts", "zh/api-reference/supernote-plugin/plugin-file-api/get-element-num-list", "zh/api-reference/supernote-plugin/plugin-file-api/get-element", - "zh/api-reference/supernote-plugin/plugin-file-api/get-last-element" + "zh/api-reference/supernote-plugin/plugin-file-api/get-last-element", + "zh/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status", + "zh/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password" ] }, { @@ -432,7 +438,9 @@ "zh/api-reference/supernote-plugin/plugin-manager/get-plugin-dir-path", "zh/api-reference/supernote-plugin/plugin-manager/get-plugin-name", "zh/api-reference/supernote-plugin/plugin-manager/get-device-type", - "zh/api-reference/supernote-plugin/plugin-manager/close-plugin-view" + "zh/api-reference/supernote-plugin/plugin-manager/close-plugin-view", + "zh/api-reference/supernote-plugin/plugin-manager/has-permission", + "zh/api-reference/supernote-plugin/plugin-manager/request-permission" ] }, { diff --git a/docs.zip b/docs.zip deleted file mode 100644 index 09b125d..0000000 Binary files a/docs.zip and /dev/null differ diff --git a/en/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx b/en/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx new file mode 100644 index 0000000..2dded77 --- /dev/null +++ b/en/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx @@ -0,0 +1,39 @@ +--- +title: "getPathEncryptionStatus" +description: "Get the encryption status of a file or directory." +--- + +```ts wrap +static getPathEncryptionStatus(filePath: string): Promise>; +``` + +**Parameters** + +| Parameter | Type | Description | +| --- | --- | --- | +| `filePath` | `string` | File or directory path | + +**Returns** + +- [`APIResponse`](/en/api-reference/supernote-plugin/types/api-response): +`result === true` means the path is encrypted, and `result === false` means it is not encrypted + +## Example + +```ts wrap +import { PluginFileAPI } from 'sn-plugin-lib'; + +/** + * Example: get the encryption status of a file or directory. + */ +export async function exampleGetPathEncryptionStatus() { + const filePath = '/storage/emulated/0/Note/demo.note'; + + const res = await PluginFileAPI.getPathEncryptionStatus(filePath); + if (!res.success) { + throw new Error(res.error?.message ?? 'getPathEncryptionStatus call failed'); + } + + return res.result; +} +``` diff --git a/en/api-reference/supernote-plugin/plugin-file-api/index.mdx b/en/api-reference/supernote-plugin/plugin-file-api/index.mdx index a0be42c..e17491a 100644 --- a/en/api-reference/supernote-plugin/plugin-file-api/index.mdx +++ b/en/api-reference/supernote-plugin/plugin-file-api/index.mdx @@ -53,3 +53,5 @@ Most async APIs return [`APIResponse`](/en/api-reference/supernote-plugin/typ - [getElementNumList](/en/api-reference/supernote-plugin/plugin-file-api/get-element-num-list) - [getElement](/en/api-reference/supernote-plugin/plugin-file-api/get-element) - [getLastElement](/en/api-reference/supernote-plugin/plugin-file-api/get-last-element) +- [getPathEncryptionStatus](/en/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status) +- [unlockPathWithPassword](/en/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password) diff --git a/en/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx b/en/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx new file mode 100644 index 0000000..489fb22 --- /dev/null +++ b/en/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx @@ -0,0 +1,41 @@ +--- +title: "unlockPathWithPassword" +description: "Unlock an encrypted file or directory with a password." +--- + +```ts wrap +static unlockPathWithPassword(filePath: string, password: string): Promise>; +``` + +**Parameters** + +| Parameter | Type | Description | +| --- | --- | --- | +| `filePath` | `string` | File or directory path | +| `password` | `string` | Password used to unlock the path | + +**Returns** + +- [`APIResponse`](/en/api-reference/supernote-plugin/types/api-response): +`result === true` means unlock succeeds, and `result === false` means unlock fails + +## Example + +```ts wrap +import { PluginFileAPI } from 'sn-plugin-lib'; + +/** + * Example: unlock an encrypted path with a password. + */ +export async function exampleUnlockPathWithPassword() { + const filePath = '/storage/emulated/0/Note/demo.note'; + const password = '123456'; + + const res = await PluginFileAPI.unlockPathWithPassword(filePath, password); + if (!res.success) { + throw new Error(res.error?.message ?? 'unlockPathWithPassword call failed'); + } + + return res.result; +} +``` diff --git a/en/api-reference/supernote-plugin/plugin-manager/has-permission.mdx b/en/api-reference/supernote-plugin/plugin-manager/has-permission.mdx new file mode 100644 index 0000000..46deb36 --- /dev/null +++ b/en/api-reference/supernote-plugin/plugin-manager/has-permission.mdx @@ -0,0 +1,44 @@ +--- +title: "hasPermission" +description: "Check whether the plugin already has a specific permission." +--- + +```ts +hasPermission(permission: string): Promise; +``` + +**Parameters** + +| Parameter | Type | Description | +| --- | --- | --- | +| `permission` | `string` | Permission name. Supported values: `plugin.permission.FILE:WRITE`, `plugin.permission.FILE:DELETE`, `plugin.permission.INTERNET` | + + +Regarding file access permissions: +1. The plugin has read, write, and delete access to its private directory by default: `/data/data/com.ratta.supernote.pluginhost/files/plugins/`. +2. The plugin has read access by default only to these directories under shared storage: `Document`, `EXPORT`, `INBOX`, `MyStyle`, `Note`, and `SCREENSHOT`. Other directories are not readable. +3. After requesting write or delete permission, the plugin can write to and delete files only in `Document`, `EXPORT`, `INBOX`, `MyStyle`, `Note`, and `SCREENSHOT` under shared storage. Other directories still do not grant write or delete access even after permission is requested. + + +**Returns** + +- `Promise`: permission status, where `0` means not granted, `1` means allowed while in use, and `2` means always allowed + +**Throws** + +- Throws a parameter validation error when `permission` is not a non-empty string + +## Example + +```ts wrap +import { PluginManager } from 'sn-plugin-lib'; + +/** + * Example: check the write-file permission status. + */ +export async function exampleHasPermission() { + const permission = 'plugin.permission.FILE:WRITE'; + const status = await PluginManager.hasPermission(permission); + return status; +} +``` diff --git a/en/api-reference/supernote-plugin/plugin-manager/index.mdx b/en/api-reference/supernote-plugin/plugin-manager/index.mdx index 588b9e3..a0fac7b 100644 --- a/en/api-reference/supernote-plugin/plugin-manager/index.mdx +++ b/en/api-reference/supernote-plugin/plugin-manager/index.mdx @@ -32,3 +32,5 @@ import { PluginManager } from 'sn-plugin-lib'; - [`getPluginName`](/en/api-reference/supernote-plugin/plugin-manager/get-plugin-name) - [`getDeviceType`](/en/api-reference/supernote-plugin/plugin-manager/get-device-type) - [`closePluginView`](/en/api-reference/supernote-plugin/plugin-manager/close-plugin-view) +- [`hasPermission`](/en/api-reference/supernote-plugin/plugin-manager/has-permission) +- [`requestPermission`](/en/api-reference/supernote-plugin/plugin-manager/request-permission) diff --git a/en/api-reference/supernote-plugin/plugin-manager/request-permission.mdx b/en/api-reference/supernote-plugin/plugin-manager/request-permission.mdx new file mode 100644 index 0000000..1ae6daf --- /dev/null +++ b/en/api-reference/supernote-plugin/plugin-manager/request-permission.mdx @@ -0,0 +1,48 @@ +--- +title: "requestPermission" +description: "Request a specific permission and return the user's authorization choice." +--- + +```ts +requestPermission(permission: string): Promise; +``` + +**Parameters** + +| Parameter | Type | Description | +| --- | --- | --- | +| `permission` | `string` | Permission name. Supported values: `plugin.permission.FILE:WRITE`, `plugin.permission.FILE:DELETE`, `plugin.permission.INTERNET` | + + +Regarding file access permissions: +1. The plugin has read, write, and delete access to its private directory by default: `/data/data/com.ratta.supernote.pluginhost/files/plugins/`. +2. The plugin has read access by default only to these directories under shared storage: `Document`, `EXPORT`, `INBOX`, `MyStyle`, `Note`, and `SCREENSHOT`. Other directories are not readable. +3. After requesting write or delete permission, the plugin can write to and delete files only in `Document`, `EXPORT`, `INBOX`, `MyStyle`, `Note`, and `SCREENSHOT` under shared storage. Other directories still do not grant write or delete access even after permission is requested. + + +**Returns** + +- `Promise`: user choice, where `0` means denied, `1` means allowed while in use, and `2` means always allowed + +**Description** + +- The host may show a permission dialog for the user to choose among "Deny / Allow while in use / Always allow" + +**Throws** + +- Throws a parameter validation error when `permission` is not a non-empty string + +## Example + +```ts wrap +import { PluginManager } from 'sn-plugin-lib'; + +/** + * Example: request internet permission. + */ +export async function exampleRequestPermission() { + const permission = 'plugin.permission.INTERNET'; + const result = await PluginManager.requestPermission(permission); + return result; +} +``` diff --git a/zh/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx b/zh/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx new file mode 100644 index 0000000..3c2eed5 --- /dev/null +++ b/zh/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status.mdx @@ -0,0 +1,39 @@ +--- +title: "getPathEncryptionStatus" +description: "获取文件或目录的加密状态。" +--- + +```ts wrap +static getPathEncryptionStatus(filePath: string): Promise>; +``` + +**参数** + +| 参数 | 类型 | 说明 | +| --- | --- | --- | +| `filePath` | `string` | 文件或目录路径 | + +**返回** + +- [`APIResponse`](/zh/api-reference/supernote-plugin/types/api-response): +`result === true` 表示该路径已加密,`result === false` 表示该路径未加密 + +## 示例 + +```ts wrap +import { PluginFileAPI } from 'sn-plugin-lib'; + +/** + * 查询文件或目录加密状态的示例。 + */ +export async function exampleGetPathEncryptionStatus() { + const filePath = '/storage/emulated/0/Note/demo.note'; + + const res = await PluginFileAPI.getPathEncryptionStatus(filePath); + if (!res.success) { + throw new Error(res.error?.message ?? 'getPathEncryptionStatus 调用失败'); + } + + return res.result; +} +``` diff --git a/zh/api-reference/supernote-plugin/plugin-file-api/index.mdx b/zh/api-reference/supernote-plugin/plugin-file-api/index.mdx index 75c4dbd..f265a9b 100644 --- a/zh/api-reference/supernote-plugin/plugin-file-api/index.mdx +++ b/zh/api-reference/supernote-plugin/plugin-file-api/index.mdx @@ -53,3 +53,5 @@ import { PluginFileAPI } from "sn-plugin-lib"; - [getElementNumList](/zh/api-reference/supernote-plugin/plugin-file-api/get-element-num-list) - [getElement](/zh/api-reference/supernote-plugin/plugin-file-api/get-element) - [getLastElement](/zh/api-reference/supernote-plugin/plugin-file-api/get-last-element) +- [getPathEncryptionStatus](/zh/api-reference/supernote-plugin/plugin-file-api/get-path-encryption-status) +- [unlockPathWithPassword](/zh/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password) diff --git a/zh/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx b/zh/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx new file mode 100644 index 0000000..f4bfb0e --- /dev/null +++ b/zh/api-reference/supernote-plugin/plugin-file-api/unlock-path-with-password.mdx @@ -0,0 +1,41 @@ +--- +title: "unlockPathWithPassword" +description: "使用密码解锁已加密的文件或目录。" +--- + +```ts wrap +static unlockPathWithPassword(filePath: string, password: string): Promise>; +``` + +**参数** + +| 参数 | 类型 | 说明 | +| --- | --- | --- | +| `filePath` | `string` | 文件或目录路径 | +| `password` | `string` | 用于解锁该路径的密码 | + +**返回** + +- [`APIResponse`](/zh/api-reference/supernote-plugin/types/api-response): +`result === true` 表示解锁成功,`result === false` 表示解锁失败 + +## 示例 + +```ts wrap +import { PluginFileAPI } from 'sn-plugin-lib'; + +/** + * 使用密码解锁加密路径的示例。 + */ +export async function exampleUnlockPathWithPassword() { + const filePath = '/storage/emulated/0/Note/demo.note'; + const password = '123456'; + + const res = await PluginFileAPI.unlockPathWithPassword(filePath, password); + if (!res.success) { + throw new Error(res.error?.message ?? 'unlockPathWithPassword 调用失败'); + } + + return res.result; +} +``` diff --git a/zh/api-reference/supernote-plugin/plugin-manager/has-permission.mdx b/zh/api-reference/supernote-plugin/plugin-manager/has-permission.mdx new file mode 100644 index 0000000..c4b69b8 --- /dev/null +++ b/zh/api-reference/supernote-plugin/plugin-manager/has-permission.mdx @@ -0,0 +1,46 @@ +--- +title: "hasPermission" +description: "查询插件是否已拥有指定权限。" +--- + +```ts +hasPermission(permission: string): Promise; +``` + +**参数** + +| 参数 | 类型 | 说明 | +| --- | --- | --- | +| `permission` | `string` | 权限名称,支持:`plugin.permission.FILE:WRITE`、`plugin.permission.FILE:DELETE`、`plugin.permission.INTERNET` | + + +关于文件访问权限: +1. 插件默认拥有私有目录 `/data/data/com.ratta.supernote.pluginhost/files/plugins/` 的读取、写入、删除权限。 +2. 插件默认拥有 `sdcard` 目录下 `Document`、`EXPORT`、`INBOX`、`MyStyle`、`Note`、`SCREENSHOT` 这几个目录的读取权限,其他目录默认不具备读取权限。 +3. 当插件申请写入或删除权限后,可获得 `sdcard` 目录下 `Document`、`EXPORT`、`INBOX`、`MyStyle`、`Note`、`SCREENSHOT` 这几个目录的写入和删除权限;其他目录即使申请相关权限,也无法获得对应的写入和删除权限。 + + + + +**返回** + +- `Promise`:权限状态,`0` 表示未授予,`1` 表示使用时允许,`2` 表示始终允许 + +**异常** + +- 当 `permission` 不是非空字符串时,会抛出参数校验异常 + +## 示例 + +```ts wrap +import { PluginManager } from 'sn-plugin-lib'; + +/** + * 查询插件写文件权限状态的示例。 + */ +export async function exampleHasPermission() { + const permission = 'plugin.permission.FILE:WRITE'; + const status = await PluginManager.hasPermission(permission); + return status; +} +``` diff --git a/zh/api-reference/supernote-plugin/plugin-manager/index.mdx b/zh/api-reference/supernote-plugin/plugin-manager/index.mdx index 14cb2b4..a6c3f55 100644 --- a/zh/api-reference/supernote-plugin/plugin-manager/index.mdx +++ b/zh/api-reference/supernote-plugin/plugin-manager/index.mdx @@ -32,3 +32,5 @@ import { PluginManager } from 'sn-plugin-lib'; - [`getPluginName`](/zh/api-reference/supernote-plugin/plugin-manager/get-plugin-name) - [`getDeviceType`](/zh/api-reference/supernote-plugin/plugin-manager/get-device-type) - [`closePluginView`](/zh/api-reference/supernote-plugin/plugin-manager/close-plugin-view) +- [`hasPermission`](/zh/api-reference/supernote-plugin/plugin-manager/has-permission) +- [`requestPermission`](/zh/api-reference/supernote-plugin/plugin-manager/request-permission) diff --git a/zh/api-reference/supernote-plugin/plugin-manager/request-permission.mdx b/zh/api-reference/supernote-plugin/plugin-manager/request-permission.mdx new file mode 100644 index 0000000..49be8ff --- /dev/null +++ b/zh/api-reference/supernote-plugin/plugin-manager/request-permission.mdx @@ -0,0 +1,48 @@ +--- +title: "requestPermission" +description: "申请指定权限,并返回用户的授权选择结果。" +--- + +```ts +requestPermission(permission: string): Promise; +``` + +**参数** + +| 参数 | 类型 | 说明 | +| --- | --- | --- | +| `permission` | `string` | 权限名称,支持:`plugin.permission.FILE:WRITE`、`plugin.permission.FILE:DELETE`、`plugin.permission.INTERNET` | + + +关于文件访问权限: +1. 插件默认拥有私有目录 `/data/data/com.ratta.supernote.pluginhost/files/plugins/` 的读取、写入、删除权限。 +2. 插件默认拥有 `sdcard` 目录下 `Document`、`EXPORT`、`INBOX`、`MyStyle`、`Note`、`SCREENSHOT` 这几个目录的读取权限,其他目录默认不具备读取权限。 +3. 当插件申请写入或删除权限后,可获得 `sdcard` 目录下 `Document`、`EXPORT`、`INBOX`、`MyStyle`、`Note`、`SCREENSHOT` 这几个目录的写入和删除权限;其他目录即使申请相关权限,也无法获得对应的写入和删除权限。 + + +**返回** + +- `Promise`:用户授权结果,`0` 表示拒绝,`1` 表示使用时允许,`2` 表示始终允许 + +**说明** + +- 宿主可能会弹出授权对话框,供用户在“拒绝 / 使用时允许 / 始终允许”之间选择 + +**异常** + +- 当 `permission` 不是非空字符串时,会抛出参数校验异常 + +## 示例 + +```ts wrap +import { PluginManager } from 'sn-plugin-lib'; + +/** + * 申请网络权限的示例。 + */ +export async function exampleRequestPermission() { + const permission = 'plugin.permission.INTERNET'; + const result = await PluginManager.requestPermission(permission); + return result; +} +```