Modify change appContext, appResources return object with null-safe type in PackageParam

This commit is contained in:
2022-09-16 02:39:36 +08:00
parent f236ea3940
commit 9585d4b91f
2 changed files with 14 additions and 8 deletions

View File

@@ -59,13 +59,17 @@ val appUserId: Int
### appContext *- field*
```kotlin
val appContext: Application
val appContext: Application?
```
**变更记录**
`v1.0.72` `新增`
`v1.0.93` `修改`
加入可空类型 (空安全)
**功能描述**
> 获取当前 Hook APP 的 `Application`。
@@ -75,13 +79,17 @@ val appContext: Application
### appResources *- field*
```kotlin
val appResourcesResources
val appResourcesResources?
```
**变更记录**
`v1.0.80` `新增`
`v1.0.93` `修改`
加入可空类型 (空安全)
**功能描述**
> 获取当前 Hook APP 的 Resources。

View File

@@ -88,19 +88,17 @@ open class PackageParam internal constructor(@PublishedApi internal var wrapper:
* 获取当前 Hook APP 的 [Application] 实例
*
* - ❗首次装载可能是空的 - 请延迟一段时间再获取或通过设置 [onAppLifecycle] 监听来完成
* @return [Application]
* @throws IllegalStateException 如果 [Application] 是空的
* @return [Application] or null
*/
val appContext get() = AppParasitics.hostApplication ?: YukiHookAppHelper.currentApplication() ?: error("PackageParam got null appContext")
val appContext get() = AppParasitics.hostApplication ?: YukiHookAppHelper.currentApplication()
/**
* 获取当前 Hook APP 的 Resources
*
* - ❗你只能在 [HookResources.hook] 方法体内或 [appContext] 装载完毕时进行调用
* @return [Resources]
* @throws IllegalStateException 如果当前处于 [loadZygote] 或 [appContext] 尚未加载
* @return [Resources] or null
*/
val appResources get() = wrapper?.appResources ?: appContext.resources ?: error("You cannot call to appResources in this time")
val appResources get() = wrapper?.appResources ?: appContext?.resources
/**
* 获取当前系统框架的 [Context]