-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [kmp/core,kmp/sys] 在模块中新增 dweb_permissions 字段
未来std的开发基本都是如此,只提供协议,然后由其它模块来认领该协议
- Loading branch information
Showing
8 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
next/kmp/core/src/commonMain/kotlin/org/dweb_browser/core/help/types/DwebPermissions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.dweb_browser.core.help.types | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class DwebPermissions( | ||
/** | ||
* 权限捕捉的路由,比如: | ||
* file://gaubee.com.dweb/info | ||
* | ||
* 其中,协议必须是 file,host 必须和 module 的 id 一致。 | ||
* 这里要求写完整,因为难免未来会作出其它协议的支持,比如 dweb://deeplink 协议、比如 https://\*.dweb 的请求 | ||
* | ||
* 这里使用“前缀路径捕捉”,也就是说 file://gaubee.com.dweb/info\* 与 都会被被拦截。如果想拦截全部,请编写 file://gaubee.com.dweb/ (PS: 这里末尾的`/`可以缺省,但缺省不意味着能捕捉 file://gaubee.com.dweb.gaubee2.com.dweb) | ||
* | ||
*/ | ||
val routes: List<String>, | ||
/** | ||
* 徽章,和icon类似,但是是附着在 module.icon 的右下方,如果不提供,默认使用 module.icon 来作为图标 | ||
*/ | ||
val badge: String? = null, | ||
/** | ||
* 权限标题,如果没有提供,默认使用 manifest.name | ||
*/ | ||
val title: String? = null, | ||
/** | ||
* 权限描述 | ||
*/ | ||
val description: String? = null | ||
) |
22 changes: 22 additions & 0 deletions
22
.../core/src/commonMain/kotlin/org/dweb_browser/core/std/permission/PermissionStdProtocol.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.dweb_browser.core.std.permission | ||
|
||
import io.ktor.http.HttpMethod | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import org.dweb_browser.core.http.router.bind | ||
import org.dweb_browser.core.module.NativeMicroModule | ||
|
||
/** | ||
* 权限模块需要附着到原生模块上才能完整,这里只提供一些基本标准 | ||
*/ | ||
suspend fun NativeMicroModule.permissionStdProtocol() { | ||
protocol("permission.std.dweb") { | ||
routes( | ||
/// 查询某些权限是否拥有过 | ||
"/query" bind HttpMethod.Get to defineJsonResponse { | ||
JsonPrimitive("qaq") | ||
}, | ||
/// 申请某些权限 | ||
// "/" bind HttpMethod.Get | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
next/kmp/core/src/commonMain/kotlin/org/dweb_browser/core/std/permission/const.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.dweb_browser.core.std.permission | ||
|
||
import org.dweb_browser.helper.Debugger | ||
|
||
val debugPermission = Debugger("permission") |
38 changes: 38 additions & 0 deletions
38
...e/src/commonMain/kotlin/org/dweb_browser/core/std/permission/permissionAdaptersManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.dweb_browser.core.std.permission | ||
|
||
import org.dweb_browser.core.help.AdapterManager | ||
import org.dweb_browser.core.module.MicroModule | ||
import org.dweb_browser.helper.compose.SimpleI18nResource | ||
|
||
|
||
/** | ||
* 权限提供商 | ||
* 一般来说,如果一个模块声明了类型是 Service | ||
*/ | ||
class PermissionProvider( | ||
val module: MicroModule, | ||
/** | ||
* 权限捕捉的路由,比如: | ||
* file://gaubee.com.dweb/info | ||
* | ||
*/ | ||
val routes: List<String>, | ||
/** | ||
* 徽章 | ||
*/ | ||
val badge: String? = null, | ||
/** | ||
* 权限标题,可以理解成短语,用户在熟悉详情后,可以通过识别短语来快速判断申请的权限信息 | ||
*/ | ||
val title: SimpleI18nResource, | ||
/** | ||
* 权限描述,用户第一次进行授权时,会默认展开的提示。未来默认收起,但是可以点击title展开 | ||
*/ | ||
val description: SimpleI18nResource? = null | ||
) | ||
|
||
/** | ||
* 权限适配器管理器 | ||
* 这个适配器只适用于内部构建使用,不支持运行时动态注册 | ||
*/ | ||
val permissionAdapterManager = AdapterManager<PermissionProvider>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
next/kmp/sys/src/commonMain/kotlin/org/dweb_browser/sys/permission/PermissionStdProtocol.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...mp/sys/src/commonMain/kotlin/org/dweb_browser/sys/permission/permissionAdaptersManager.kt
This file was deleted.
Oops, something went wrong.