$ show gkd-kit/gkd
GKD is an open-source Android application that automates UI interactions, primarily to skip ads, auto-confirm dialogs, and perform custom click actions. It operates as an accessibility service, using a custom selector language (similar to CSS) to match UI nodes and execute actions defined in remote subscription rules. The app is built with Kotlin and Jetpack Compose, leveraging Room for local persistence, Ktor for HTTP, and Coroutines/Flow for reactive state management. It also integrates with Shizuku for privileged operations like input injection and screenshot capture. The architecture is modular: the main `gkd-app` module contains the UI, services, and rule engine; `gkd-selector` is a Kotlin Multiplatform library for parsing and matching the custom selector syntax; `gkd-db` provides a multiplatform database layer; and `gkd-hidden-api` contains stubs for Android hidden APIs used for automation. Key entry points include the accessibility service (`A11yService`), the subscription repository (`SubscriptionRepository`), and the snapshot capture system. Data flows involve downloading subscription rules, parsing them into internal representations, matching against accessibility node trees, and executing actions (click, swipe, etc.). External dependencies include AndroidX libraries, Ktor, Kotlin Serialization, Coil, and the Shizuku privilege library. The codebase demonstrates strong engineering practices with extensive unit tests, a well-defined selector engine, and reusable patterns like `Loadable` for async state and `MutexState` for concurrency. However, it relies heavily on hidden Android APIs and a custom DSL, which introduces maintenance risk. Overall, it is a high-quality, actively maintained project with significant reuse potential in its selector engine and utility components.
The LLM identified 5 files worth highlighting for reuse:
A sealed class representing three states of asynchronous data: Loading, Ready, and Failure. It is used throughout the app for UI state management and can be extracted as a generic pattern for any Kotlin/Android project needing a type-safe async state container.
Combines a Kotlin Mutex with a StateFlow to track whether a lock is held. Provides `withStateLock` for safe concurrent access and exposes a `locked` state flow for UI observation. Reusable in any coroutine-based application requiring synchronized access with visibility.
Ensures a save operation is executed exactly once, even if called multiple times concurrently. Uses an atomic boolean and a coroutine job to prevent duplicate saves. Useful for any editor or form where save actions must be idempotent and race-condition-free.
A lifecycle-aware container that holds a resource (e.g., a Closeable) and automatically closes the old resource when a new one is assigned. Integrates with Android lifecycle to release resources on destroy. Reusable pattern for managing one-at-a-time resources like database connections or network sockets.
The public API for the custom selector language. Provides `compile`, `parse`, `match`, and `typeCheck` methods. The selector engine is fully self-contained, multiplatform (JVM/JS), and includes a tokenizer, parser, type checker, and compiled matcher with fast-query optimization. It can be extracted and reused in any project needing a CSS-like selector for tree structures.