Skip to content

Commit

Permalink
✨ [kmp/core,kmp/sys] 在模块中新增 dweb_permissions 字段
Browse files Browse the repository at this point in the history
未来std的开发基本都是如此,只提供协议,然后由其它模块来认领该协议
  • Loading branch information
Gaubee committed Oct 31, 2023
1 parent af92385 commit 04e7c2f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ object CommonAppManifestSerializer : PropMetasSerializer<CommonAppManifest>(Comm

@Serializable(with = CommonAppManifestSerializer::class)
class CommonAppManifest(p: PropMetas.PropValues = P.buildValues()) :
PropMetas.Constructor<CommonAppManifest>(p, P),
ICommonAppManifest {
PropMetas.Constructor<CommonAppManifest>(p, P), ICommonAppManifest {
companion object {
internal val P = PropMetas("CommonAppManifest", { CommonAppManifest(it) })
private val P_id = P.required("id", "")
private val P_dweb_deeplinks = P.list<DWEB_DEEPLINK>("dweb_deeplinks")
private val P_dweb_protocols = P.list<DWEB_PROTOCOL>("dweb_protocols")
private val P_dweb_permissions = P.list<DwebPermissions>("dweb_permissions")
private val P_dir = P.optional<String>("dir")
private val P_lang = P.optional<String>("lang")
private val P_name = P.required("name", "")
Expand All @@ -46,6 +46,7 @@ class CommonAppManifest(p: PropMetas.PropValues = P.buildValues()) :
override var id by P_id(p)
override var dweb_deeplinks by P_dweb_deeplinks(p)
override var dweb_protocols by P_dweb_protocols(p)
override var dweb_permissions by P_dweb_permissions(p)
override var dir by P_dir(p)
override var lang by P_lang(p)
override var name by P_name(p)
Expand All @@ -62,11 +63,11 @@ class CommonAppManifest(p: PropMetas.PropValues = P.buildValues()) :
override var version by P_version(p)
}


interface ICommonAppManifest {
var id: MMID
var dweb_deeplinks: List<DWEB_DEEPLINK>
var dweb_protocols: List<DWEB_PROTOCOL>
var dweb_permissions: List<DwebPermissions>
var dir: String?// 文本方向
var lang: String?
var name: String// 应用名称
Expand Down
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
)
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
)
}
}
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")
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>()
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package org.dweb_browser.sys.permission
import org.dweb_browser.core.help.types.MICRO_MODULE_CATEGORY
import org.dweb_browser.core.module.BootstrapContext
import org.dweb_browser.core.module.NativeMicroModule
import org.dweb_browser.helper.Debugger
import org.dweb_browser.core.std.permission.permissionStdProtocol
import org.dweb_browser.helper.ImageResource
import org.dweb_browser.sys.window.core.helper.setFromManifest
import org.dweb_browser.sys.window.ext.getMainWindow
import org.dweb_browser.sys.window.ext.onRenderer

val debugPermission = Debugger("permission")

class PermissionNMM : NativeMicroModule("permission.sys.dweb", "Permission Management") {
init {
Expand All @@ -23,16 +22,11 @@ class PermissionNMM : NativeMicroModule("permission.sys.dweb", "Permission Manag
icons = listOf(
ImageResource(src = "file:///sys/icons/$mmid.svg", type = "image/svg+xml")
)

/// 提供JsMicroModule的文件适配器
/// 这个适配器不需要跟着bootstrap声明周期,只要存在JmmNMM模块,就能生效
permissionAdaptersManager.append {

}
}

override suspend fun _bootstrap(bootstrapContext: BootstrapContext) {
permissionStdProtocol()

onRenderer {
getMainWindow().state.setFromManifest(this@PermissionNMM)
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 04e7c2f

Please sign in to comment.