Fix checkApi ignored bug in YukiHookModulePrefs

This commit is contained in:
2022-08-27 21:55:22 +08:00
parent 11a0b3a693
commit 20aa1c89bc

View File

@@ -154,7 +154,8 @@ class YukiHookModulePrefs private constructor(private var context: Context? = nu
* @return [XSharedPreferences] * @return [XSharedPreferences]
*/ */
private val xPrefs private val xPrefs
get() = runCatching { get() = checkApi().let {
runCatching {
XSharedPreferences(YukiHookBridge.modulePackageName, prefsName).apply { XSharedPreferences(YukiHookBridge.modulePackageName, prefsName).apply {
checkApi() checkApi()
makeWorldReadable() makeWorldReadable()
@@ -162,21 +163,22 @@ class YukiHookModulePrefs private constructor(private var context: Context? = nu
} }
}.onFailure { yLoggerE(msg = it.message ?: "Operating system not supported", e = it) }.getOrNull() }.onFailure { yLoggerE(msg = it.message ?: "Operating system not supported", e = it) }.getOrNull()
?: error("Cannot load the XSharedPreferences, maybe is your Hook Framework not support it") ?: error("Cannot load the XSharedPreferences, maybe is your Hook Framework not support it")
}
/** /**
* 获得 [SharedPreferences] 对象 * 获得 [SharedPreferences] 对象
* @return [SharedPreferences] * @return [SharedPreferences]
*/ */
private val sPrefs private val sPrefs
get() = try { get() = checkApi().let {
checkApi() try {
context?.getSharedPreferences(prefsName, Context.MODE_WORLD_READABLE).also { isUsingNewXSharedPreferences = true } context?.getSharedPreferences(prefsName, Context.MODE_WORLD_READABLE).also { isUsingNewXSharedPreferences = true }
?: error("YukiHookModulePrefs missing Context instance") ?: error("YukiHookModulePrefs missing Context instance")
} catch (_: Throwable) { } catch (_: Throwable) {
checkApi()
context?.getSharedPreferences(prefsName, Context.MODE_PRIVATE).also { isUsingNewXSharedPreferences = false } context?.getSharedPreferences(prefsName, Context.MODE_PRIVATE).also { isUsingNewXSharedPreferences = false }
?: error("YukiHookModulePrefs missing Context instance") ?: error("YukiHookModulePrefs missing Context instance")
} }
}
/** 设置全局可读可写 */ /** 设置全局可读可写 */
private fun makeWorldReadable() = runCatching { private fun makeWorldReadable() = runCatching {