fix: not being able to enable bundle injection
This commit is contained in:
parent
1f8ddf4176
commit
2a223671b9
2 changed files with 39 additions and 25 deletions
|
|
@ -63,31 +63,38 @@ object LogBoxActions {
|
||||||
settingsFile.parentFile?.mkdirs()
|
settingsFile.parentFile?.mkdirs()
|
||||||
val settings = if (settingsFile.exists()) JSONObject(settingsFile.readText()) else JSONObject()
|
val settings = if (settingsFile.exists()) JSONObject(settingsFile.readText()) else JSONObject()
|
||||||
|
|
||||||
if (bundle.exists()) {
|
val currentlyDisabled = LogBoxUtils.isBundleInjectionDisabled(context)
|
||||||
if (disabled.exists()) disabled.delete()
|
val newState = !currentlyDisabled
|
||||||
val renamed = bundle.renameTo(disabled)
|
|
||||||
settings.put("bundleInjectionDisabled", true)
|
if (bundle.exists() && disabled.exists()) {
|
||||||
settingsFile.writeText(settings.toString())
|
bundle.delete()
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
if (renamed) "Bundle injection disabled" else "Bundle injection disabled (marker set)",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
} else if (disabled.exists()) {
|
|
||||||
val renamed = disabled.renameTo(bundle)
|
|
||||||
settings.put("bundleInjectionDisabled", false)
|
|
||||||
settingsFile.writeText(settings.toString())
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
if (renamed) "Bundle injection enabled" else "Bundle injection enabled (marker removed)",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
} else {
|
|
||||||
disabled.writeText("")
|
|
||||||
settings.put("bundleInjectionDisabled", true)
|
|
||||||
settingsFile.writeText(settings.toString())
|
|
||||||
Toast.makeText(context, "Bundle injection disabled (marker created)", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newState) {
|
||||||
|
// Disable injection
|
||||||
|
if (disabled.exists()) {
|
||||||
|
disabled.delete()
|
||||||
|
}
|
||||||
|
if (bundle.exists()) {
|
||||||
|
bundle.renameTo(disabled)
|
||||||
|
} else {
|
||||||
|
disabled.writeText("")
|
||||||
|
}
|
||||||
|
settings.put("bundleInjectionDisabled", true)
|
||||||
|
Toast.makeText(context, "Bundle injection disabled", Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
// Enable injection
|
||||||
|
if (disabled.exists()) {
|
||||||
|
disabled.renameTo(bundle)
|
||||||
|
} else if (!bundle.exists()) {
|
||||||
|
bundle.writeText("")
|
||||||
|
}
|
||||||
|
settings.put("bundleInjectionDisabled", false)
|
||||||
|
Toast.makeText(context, "Bundle injection enabled", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsFile.writeText(settings.toString())
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Error toggling bundle injection: ${e.message}")
|
Log.e("Error toggling bundle injection: ${e.message}")
|
||||||
showError(context, "Failed to toggle bundle injection", e.message)
|
showError(context, "Failed to toggle bundle injection", e.message)
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,16 @@ object LogBoxUtils {
|
||||||
val cacheDir = File(context.dataDir, Constants.CACHE_DIR)
|
val cacheDir = File(context.dataDir, Constants.CACHE_DIR)
|
||||||
val bundle = File(cacheDir, Constants.MAIN_SCRIPT_FILE)
|
val bundle = File(cacheDir, Constants.MAIN_SCRIPT_FILE)
|
||||||
val disabled = File(cacheDir, "${Constants.MAIN_SCRIPT_FILE}.disabled")
|
val disabled = File(cacheDir, "${Constants.MAIN_SCRIPT_FILE}.disabled")
|
||||||
if (disabled.exists()) return true
|
|
||||||
|
if (disabled.exists()) {
|
||||||
|
if (bundle.exists()) {
|
||||||
|
bundle.delete()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
if (bundle.exists()) return false
|
if (bundle.exists()) return false
|
||||||
|
|
||||||
|
// If neither file exists, check settings
|
||||||
val settingsFile = File(context.filesDir, "logbox/LOGBOX_SETTINGS")
|
val settingsFile = File(context.filesDir, "logbox/LOGBOX_SETTINGS")
|
||||||
if (!settingsFile.exists()) return false
|
if (!settingsFile.exists()) return false
|
||||||
val json = JSONObject(settingsFile.readText())
|
val json = JSONObject(settingsFile.readText())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue