Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from gkd-kit:main #18

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
本应用 **默认不携带任何规则**,官方也不再提供任何规则, 需要用户自行添加本地规则,或者通过订阅规则的方式获取规则

| | | | |
|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| ![img](https://github.com/gkd-kit/gkd/assets/38517192/e99f43b7-2247-4682-9981-f5d4ec9b483f) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/2d22ee71-d6fd-4dfe-b52f-d73df02f5009) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/b2deafde-d933-402f-a9ce-ebae521b439f) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/7be30706-3e76-4685-b853-3294c362999f) |
| ![img](https://github.com/gkd-kit/gkd/assets/38517192/1cca31e6-ab1e-4f05-b2bb-ce4844029d52) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/905c2f8d-6af4-4870-b00e-27f6844467aa) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/79f4b6cd-c9c9-4c58-a613-f7f8951dfa61) | ![img](https://github.com/gkd-kit/gkd/assets/38517192/43f7024c-2227-4476-b90c-7dc6f1e4264d) |

## 选择器

<details open>
<summary>示例: 选择器路径视图</summary>
<https://gkd.li/selector/>

![image](https://github.com/gkd-kit/inspect/assets/38517192/27d0656a-2239-426c-930c-749ffb9f189b)
[@[vid=\"menu\"] < [vid=\"menu_container\"] - [vid=\"dot_text_layout\"] > [text^=\"广告\"]](https://i.gkd.li/i/14881985?gkd=QFt2aWQ9Im1lbnUiXSA8IFt2aWQ9Im1lbnVfY29udGFpbmVyIl0gLSBbdmlkPSJkb3RfdGV4dF9sYXlvdXQiXSA-IFt0ZXh0Xj0i5bm_5ZGKIl0)

</details>
![image](https://github.com/gkd-kit/gkd/assets/38517192/980db09f-2c50-4ca0-a8e3-43dce10e38f0)

## LICENSE

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/li/songe/gkd/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import li.songe.gkd.data.RawSubscription
import li.songe.gkd.data.SubsItem
Expand Down Expand Up @@ -43,7 +42,7 @@ class MainViewModel : ViewModel() {
id = -2, order = -2, mtime = System.currentTimeMillis()
)
viewModelScope.launchTry(Dispatchers.IO) {
val subsItems = DbSet.subsItemDao.query().first()
val subsItems = DbSet.subsItemDao.queryAll()
if (!subsItems.any { s -> s.id == localSubsItem.id }) {
updateSubscription(
RawSubscription(
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -767,26 +767,26 @@ data class RawSubscription(
val text = if (json5) json5ToJson(source) else source
val subscription = jsonToSubscriptionRaw(json.parseToJsonElement(text).jsonObject)
subscription.categories.findDuplicatedItem { v -> v.key }?.let { v ->
error("duplicated category: key=${v.key}")
error("id=${subscription.id}, duplicated category: key=${v.key}")
}
subscription.globalGroups.findDuplicatedItem { v -> v.key }?.let { v ->
error("duplicated global group: key=${v.key}")
error("id=${subscription.id}, duplicated global group: key=${v.key}")
}
subscription.globalGroups.forEach { g ->
g.rules.findDuplicatedItem { v -> v.key }?.let { v ->
error("duplicated global rule: key=${v.key}, groupKey=${g.key}")
error("id=${subscription.id}, duplicated global rule: key=${v.key}, groupKey=${g.key}")
}
}
subscription.apps.findDuplicatedItem { v -> v.id }?.let { v ->
error("duplicated app: ${v.id}")
error("id=${subscription.id}, duplicated app: ${v.id}")
}
subscription.apps.forEach { a ->
a.groups.findDuplicatedItem { v -> v.key }?.let { v ->
error("duplicated app group: key=${v.key}, appId=${a.id}")
error("id=${subscription.id}, duplicated app group: key=${v.key}, appId=${a.id}")
}
a.groups.forEach { g ->
g.rules.findDuplicatedItem { v -> v.key }?.let { v ->
error("duplicated app rule: key=${v.key}, groupKey=${g.key}, appId=${a.id}")
error("id=${subscription.id}, duplicated app rule: key=${v.key}, groupKey=${g.key}, appId=${a.id}")
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/data/SubsItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ data class SubsItem(
@Query("SELECT * FROM subs_item ORDER BY `order`")
fun query(): Flow<List<SubsItem>>

@Query("SELECT * FROM subs_item ORDER BY `order`")
fun queryAll(): List<SubsItem>

@Query("SELECT * FROM subs_item WHERE id=:id")
fun queryById(id: Long): Flow<SubsItem?>
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/util/SubsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ fun deleteSubscription(subsId: Long) {
val newMap = subsIdToRawFlow.value.toMutableMap()
newMap.remove(subsId)
subsIdToRawFlow.value = newMap.toImmutableMap()
subsFolder.resolve("$subsId.json").apply {
if (exists()) {
delete()
}
}
}

fun getGroupRawEnable(
Expand Down Expand Up @@ -277,9 +282,9 @@ fun initSubsState() {
subsRefreshingFlow.value = true
if (subsFolder.exists() && subsFolder.isDirectory) {
updateSubsFileMutex.withLock {
val fileRegex = Regex("^-?\\d+\\.json$")
val filenames = DbSet.subsItemDao.queryAll().map { s -> "${s.id}.json" }
val files =
subsFolder.listFiles { f -> f.isFile && f.name.matches(fileRegex) }
subsFolder.listFiles { f -> f.isFile && filenames.contains(f.name) }
?: emptyArray()
val subscriptions = files.mapNotNull { f ->
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ package li.songe.selector.data
data class PolynomialExpression(val a: Int = 0, val b: Int = 1) : ConnectExpression() {

override fun toString(): String {
if (a == 0 && b == 0) return "0"
if (a == 1 && b == 1) return "(n+1)"
if (a > 0 && b > 0) {
if (a == 1) {
return "(n+$b)"
}
return "(${a}n+$b)"
}
if (a < 0 && b > 0) {
if (a == -1) {
return "($b-n)"
}
return "($b${a}n)"
}
if (b == 0) {
if (a == 1) return "n"
return if (a > 0) {
Expand Down