add lua libs repository, fix manifest generator

This commit is contained in:
CherretGit
2026-03-20 14:07:48 +07:00
parent 154d8214bb
commit 2a2de41132
10 changed files with 38 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ import com.cherret.zaprett.ui.viewmodel.BinRepoViewModel
import com.cherret.zaprett.ui.viewmodel.HomeViewModel
import com.cherret.zaprett.ui.viewmodel.HostRepoViewModel
import com.cherret.zaprett.ui.viewmodel.IpsetRepoViewModel
import com.cherret.zaprett.ui.viewmodel.LuaLibsRepoViewModel
import com.cherret.zaprett.ui.viewmodel.StrategyRepoViewModel
import com.cherret.zaprett.utils.checkModuleInstallation
import com.cherret.zaprett.utils.checkStoragePermission
@@ -232,6 +233,10 @@ class MainActivity : ComponentActivity() {
val viewModel: BinRepoViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
RepoScreen(navController, viewModel)
}
"lua_libs" -> {
val viewModel: LuaLibsRepoViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
RepoScreen(navController, viewModel)
}
}
}
composable("debugScreen") { DebugScreen(navController) }

View File

@@ -1,5 +1,5 @@
package com.cherret.zaprett.data
enum class ItemType {
bin, byedpi, nfqws, nfqws2, list, list_exclude, ipset, ipset_exclude
bin, lua_lib, byedpi, nfqws, nfqws2, list, list_exclude, ipset, ipset_exclude
}

View File

@@ -2,6 +2,7 @@ package com.cherret.zaprett.data
enum class RepoTab {
bins,
lua_libs,
lists,
strategies,
ipsets

View File

@@ -262,6 +262,12 @@ fun SettingsScreen(navController: NavController, viewModel : SettingsViewModel =
onClick = {
navController.navigate("repo?source=bin") { launchSingleTop = true }
}
),
Setting.Action(
title = stringResource(R.string.lua_libs_repo),
onClick = {
navController.navigate("repo?source=lua_libs") { launchSingleTop = true }
}
)
)

View File

@@ -34,6 +34,7 @@ abstract class BaseListsViewModel(application: Application) : AndroidViewModel(a
val json = Json {
prettyPrint = true
ignoreUnknownKeys = true
encodeDefaults = true
}
var allItems by mutableStateOf<List<StorageData>>(emptyList())
private set

View File

@@ -83,6 +83,7 @@ abstract class BaseRepoViewModel(application: Application) : AndroidViewModel(ap
private val Json = Json {
prettyPrint = true
ignoreUnknownKeys = true
encodeDefaults = true
}
@OptIn(ExperimentalCoroutinesApi::class)
@@ -96,6 +97,10 @@ abstract class BaseRepoViewModel(application: Application) : AndroidViewModel(ap
ItemType.bin -> true
else -> false
}
RepoTab.lua_libs -> when(item.type) {
ItemType.lua_lib -> true
else -> false
}
RepoTab.lists -> when (item.type) {
ItemType.list -> listType == ListType.whitelist
ItemType.list_exclude -> listType == ListType.blacklist
@@ -193,6 +198,7 @@ abstract class BaseRepoViewModel(application: Application) : AndroidViewModel(ap
if (getFileSha256(sourceFile) == item.artifact.sha256) {
val targetDirSuffix = when (index.type) {
ItemType.bin -> "bin"
ItemType.lua_lib -> "libs"
ItemType.byedpi -> "strategies/byedpi"
ItemType.nfqws -> "strategies/nfqws"
ItemType.nfqws2 -> "strategies/nfqws2"

View File

@@ -0,0 +1,11 @@
package com.cherret.zaprett.ui.viewmodel
import android.app.Application
import com.cherret.zaprett.data.RepoTab
import com.cherret.zaprett.data.StorageData
import com.cherret.zaprett.utils.getAllLibs
class LuaLibsRepoViewModel(application: Application): BaseRepoViewModel(application) {
override fun getInstalledLists(): Array<StorageData> = getAllLibs()
override val repoTab = RepoTab.lua_libs
}

View File

@@ -216,6 +216,11 @@ fun getAllBin(): Array<StorageData> {
return getValidManifests(listsDir)
}
fun getAllLibs(): Array<StorageData> {
val listsDir = getManifestsPath().resolve("libs")
return getValidManifests(listsDir)
}
fun getActiveLists(sharedPreferences: SharedPreferences): Array<StorageData> {
if (getServiceType(sharedPreferences) != ServiceType.byedpi) {
return readConfig().activeLists.mapNotNull { parseManifestFromFile(File(it)).getOrNull() }.toTypedArray()

View File

@@ -9,6 +9,7 @@
<string name="general_section">Основные настройки</string>
<string name="byedpi_section">Настройки ByeDPI</string>
<string name="bins_repo">Репозиторий фейков</string>
<string name="lua_libs_repo">Репозиторий Lua библиотек</string>
<string name="btn_continue">Продолжить</string>
<string name="btn_update">Обновить</string>
<string name="btn_dismiss">Отмена</string>

View File

@@ -9,6 +9,7 @@
<string name="general_section">General settings</string>
<string name="byedpi_section">ByeDPI settings</string>
<string name="bins_repo">Fakes repository</string>
<string name="lua_libs_repo">Lua libs repository</string>
<string name="btn_continue">Continue</string>
<string name="btn_update">Update</string>
<string name="btn_dismiss">Dismiss</string>