Repository: OpenHub-Store/GitHub-Store
Branch: main
Commit: 223c091207e9
Files: 593
Total size: 2.3 MB
Directory structure:
gitextract_ol6wqqha/
├── .claude/
│ └── memory/
│ └── feedback_coding_boundaries.md
├── .coderabbit.yaml
├── .editorconfig
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ ├── custom.md
│ │ └── feature_request.md
│ └── workflows/
│ └── build-desktop-platforms.yml
├── .gitignore
├── CLAUDE.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── build-logic/
│ ├── convention/
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ └── main/
│ │ └── kotlin/
│ │ ├── AndroidApplicationComposeConventionPlugin.kt
│ │ ├── AndroidApplicationConventionPlugin.kt
│ │ ├── BuildKonfigConventionPlugin.kt
│ │ ├── CmpApplicationConventionPlugin.kt
│ │ ├── CmpFeatureConventionPlugin.kt
│ │ ├── CmpLibraryConventionPlugin.kt
│ │ ├── KmpLibraryConventionPlugin.kt
│ │ ├── KtlintConventionPlugin.kt
│ │ ├── RoomConventionPlugin.kt
│ │ └── zed/
│ │ └── rainxch/
│ │ └── githubstore/
│ │ └── convention/
│ │ ├── AndroidCompose.kt
│ │ ├── KotlinAndroid.kt
│ │ ├── KotlinAndroidTarget.kt
│ │ ├── KotlinJvmTarget.kt
│ │ ├── KotlinMultiplatform.kt
│ │ ├── PathUtil.kt
│ │ └── ProjectExt.kt
│ ├── gradle.properties
│ └── settings.gradle.kts
├── build.gradle.kts
├── composeApp/
│ ├── build.gradle.kts
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidMain/
│ │ ├── AndroidManifest.xml
│ │ ├── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── githubstore/
│ │ │ ├── MainActivity.kt
│ │ │ └── app/
│ │ │ └── GithubStoreApp.kt
│ │ └── res/
│ │ ├── drawable/
│ │ │ ├── ic_launcher_monochrome.xml
│ │ │ └── ic_splash.xml
│ │ ├── mipmap-anydpi-v26/
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── splash.xml
│ │ │ └── strings.xml
│ │ └── xml/
│ │ ├── filepaths.xml
│ │ └── network_security_config.xml
│ ├── commonMain/
│ │ ├── composeResources/
│ │ │ └── drawable/
│ │ │ └── ic_github.xml
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── githubstore/
│ │ ├── Main.kt
│ │ ├── MainAction.kt
│ │ ├── MainState.kt
│ │ ├── MainViewModel.kt
│ │ └── app/
│ │ ├── components/
│ │ │ ├── RateLimitDialog.kt
│ │ │ └── SessionExpiredDialog.kt
│ │ ├── deeplink/
│ │ │ └── DeepLinkParser.kt
│ │ ├── desktop/
│ │ │ ├── KeyboardNavigation.kt
│ │ │ └── KeyboardNavigationEvent.kt
│ │ ├── di/
│ │ │ ├── SharedModules.kt
│ │ │ ├── ViewModelsModule.kt
│ │ │ └── initKoin.kt
│ │ └── navigation/
│ │ ├── AppNavigation.kt
│ │ ├── BottomNavigation.kt
│ │ ├── BottomNavigationUtils.kt
│ │ ├── GithubStoreGraph.kt
│ │ └── NavigationUtils.kt
│ └── jvmMain/
│ ├── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── githubstore/
│ │ ├── DesktopApp.kt
│ │ └── DesktopDeepLink.kt
│ └── resources/
│ └── logo/
│ └── app_icon.icns
├── core/
│ ├── data/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ ├── schemas/
│ │ │ └── zed.rainxch.core.data.local.db.AppDatabase/
│ │ │ ├── 3.json
│ │ │ ├── 4.json
│ │ │ ├── 5.json
│ │ │ └── 6.json
│ │ └── src/
│ │ ├── androidMain/
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── aidl/
│ │ │ │ └── zed/
│ │ │ │ └── rainxch/
│ │ │ │ └── core/
│ │ │ │ └── data/
│ │ │ │ └── services/
│ │ │ │ └── shizuku/
│ │ │ │ └── IShizukuInstallerService.aidl
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── core/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── PlatformModule.android.kt
│ │ │ ├── local/
│ │ │ │ ├── data_store/
│ │ │ │ │ └── createDataStore.kt
│ │ │ │ └── db/
│ │ │ │ ├── initDatabase.kt
│ │ │ │ └── migrations/
│ │ │ │ ├── MIGRATION_1_2.kt
│ │ │ │ ├── MIGRATION_2_3.kt
│ │ │ │ ├── MIGRATION_3_4.kt
│ │ │ │ ├── MIGRATION_4_5.kt
│ │ │ │ └── MIGRATION_5_6.kt
│ │ │ ├── network/
│ │ │ │ └── HttpClientFactory.android.kt
│ │ │ ├── services/
│ │ │ │ ├── AndroidDownloader.kt
│ │ │ │ ├── AndroidFileLocationsProvider.kt
│ │ │ │ ├── AndroidInstaller.kt
│ │ │ │ ├── AndroidInstallerInfoExtractor.kt
│ │ │ │ ├── AndroidLocalizationManager.kt
│ │ │ │ ├── AndroidPackageMonitor.kt
│ │ │ │ ├── AndroidUpdateScheduleManager.kt
│ │ │ │ ├── AutoUpdateWorker.kt
│ │ │ │ ├── BootReceiver.kt
│ │ │ │ ├── PackageEventReceiver.kt
│ │ │ │ ├── UpdateCheckWorker.kt
│ │ │ │ ├── UpdateScheduler.kt
│ │ │ │ └── shizuku/
│ │ │ │ ├── AndroidInstallerStatusProvider.kt
│ │ │ │ ├── ShizukuInstallerServiceImpl.kt
│ │ │ │ ├── ShizukuInstallerWrapper.kt
│ │ │ │ ├── ShizukuServiceManager.kt
│ │ │ │ └── model/
│ │ │ │ └── ShizukuStatus.kt
│ │ │ └── utils/
│ │ │ ├── AndroidAppLauncher.kt
│ │ │ ├── AndroidBrowserHelper.kt
│ │ │ ├── AndroidClipboardHelper.kt
│ │ │ └── AndroidShareManager.kt
│ │ ├── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── core/
│ │ │ └── data/
│ │ │ ├── cache/
│ │ │ │ └── CacheManager.kt
│ │ │ ├── data_source/
│ │ │ │ ├── TokenStore.kt
│ │ │ │ └── impl/
│ │ │ │ └── DefaultTokenStore.kt
│ │ │ ├── di/
│ │ │ │ ├── PlatformModule.kt
│ │ │ │ └── SharedModule.kt
│ │ │ ├── dto/
│ │ │ │ ├── AssetNetwork.kt
│ │ │ │ ├── GitHubStarredResponse.kt
│ │ │ │ ├── GithubDeviceStartDto.kt
│ │ │ │ ├── GithubDeviceTokenErrorDto.kt
│ │ │ │ ├── GithubDeviceTokenSuccessDto.kt
│ │ │ │ ├── GithubOwnerNetworkModel.kt
│ │ │ │ ├── GithubRepoNetworkModel.kt
│ │ │ │ ├── GithubRepoSearchResponse.kt
│ │ │ │ ├── OwnerNetwork.kt
│ │ │ │ ├── ReleaseNetwork.kt
│ │ │ │ ├── RepoByIdNetwork.kt
│ │ │ │ ├── RepoInfoNetwork.kt
│ │ │ │ └── UserProfileNetwork.kt
│ │ │ ├── local/
│ │ │ │ ├── data_store/
│ │ │ │ │ └── createDataStoreCore.kt
│ │ │ │ └── db/
│ │ │ │ ├── AppDatabase.kt
│ │ │ │ ├── dao/
│ │ │ │ │ ├── CacheDao.kt
│ │ │ │ │ ├── FavoriteRepoDao.kt
│ │ │ │ │ ├── InstalledAppDao.kt
│ │ │ │ │ ├── SeenRepoDao.kt
│ │ │ │ │ ├── StarredRepoDao.kt
│ │ │ │ │ └── UpdateHistoryDao.kt
│ │ │ │ └── entities/
│ │ │ │ ├── CacheEntryEntity.kt
│ │ │ │ ├── FavoriteRepoEntity.kt
│ │ │ │ ├── InstalledAppEntity.kt
│ │ │ │ ├── SeenRepoEntity.kt
│ │ │ │ ├── StarredRepositoryEntity.kt
│ │ │ │ └── UpdateHistoryEntity.kt
│ │ │ ├── logging/
│ │ │ │ └── KermitLogger.kt
│ │ │ ├── mappers/
│ │ │ │ ├── AssetNetwork.kt
│ │ │ │ ├── FavouriteRepoMappers.kt
│ │ │ │ ├── GithubAuthMappers.kt
│ │ │ │ ├── GithubRepoMapper.kt
│ │ │ │ ├── InstalledAppsMappers.kt
│ │ │ │ ├── ReleaseNetwork.kt
│ │ │ │ ├── StarredRepoMapper.kt
│ │ │ │ └── UpdateHistoryMapper.kt
│ │ │ ├── network/
│ │ │ │ ├── GitHubClientProvider.kt
│ │ │ │ ├── HttpClientFactory.kt
│ │ │ │ ├── ProxyManager.kt
│ │ │ │ └── interceptor/
│ │ │ │ ├── RateLimitInterceptor.kt
│ │ │ │ └── UnauthorizedInterceptor.kt
│ │ │ ├── repository/
│ │ │ │ ├── AuthenticationStateImpl.kt
│ │ │ │ ├── FavouritesRepositoryImpl.kt
│ │ │ │ ├── InstalledAppsRepositoryImpl.kt
│ │ │ │ ├── ProxyRepositoryImpl.kt
│ │ │ │ ├── RateLimitRepositoryImpl.kt
│ │ │ │ ├── SeenReposRepositoryImpl.kt
│ │ │ │ ├── StarredRepositoryImpl.kt
│ │ │ │ └── TweaksRepositoryImpl.kt
│ │ │ └── services/
│ │ │ ├── FileLocationsProvider.kt
│ │ │ └── LocalizationManager.kt
│ │ └── jvmMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── core/
│ │ └── data/
│ │ ├── di/
│ │ │ └── PlatformModule.jvm.kt
│ │ ├── local/
│ │ │ ├── data_store/
│ │ │ │ └── createDataStore.kt
│ │ │ └── db/
│ │ │ └── initDatabase.kt
│ │ ├── model/
│ │ │ ├── LinuxPackageType.kt
│ │ │ └── LinuxTerminal.kt
│ │ ├── network/
│ │ │ └── HttpClientFactory.jvm.kt
│ │ ├── services/
│ │ │ ├── DesktopDownloader.kt
│ │ │ ├── DesktopFileLocationsProvider.kt
│ │ │ ├── DesktopInstaller.kt
│ │ │ ├── DesktopInstallerInfoExtractor.kt
│ │ │ ├── DesktopInstallerStatusProvider.kt
│ │ │ ├── DesktopLocalizationManager.kt
│ │ │ ├── DesktopPackageMonitor.kt
│ │ │ └── DesktopUpdateScheduleManager.kt
│ │ └── utils/
│ │ ├── DesktopAppLauncher.kt
│ │ ├── DesktopBrowserHelper.kt
│ │ ├── DesktopClipboardHelper.kt
│ │ └── DesktopShareManager.kt
│ ├── domain/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ ├── AndroidManifest.xml
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── core/
│ │ │ └── domain/
│ │ │ └── Platform.android.kt
│ │ ├── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── core/
│ │ │ └── domain/
│ │ │ ├── Platform.kt
│ │ │ ├── logging/
│ │ │ │ └── GitHubStoreLogger.kt
│ │ │ ├── model/
│ │ │ │ ├── ApkPackageInfo.kt
│ │ │ │ ├── AppTheme.kt
│ │ │ │ ├── AssetArchitectureMatcher.kt
│ │ │ │ ├── DeviceApp.kt
│ │ │ │ ├── DiscoveryPlatform.kt
│ │ │ │ ├── DownloadProgress.kt
│ │ │ │ ├── ExportedApp.kt
│ │ │ │ ├── FavoriteRepo.kt
│ │ │ │ ├── FontTheme.kt
│ │ │ │ ├── GithubAsset.kt
│ │ │ │ ├── GithubDeviceStart.kt
│ │ │ │ ├── GithubDeviceTokenError.kt
│ │ │ │ ├── GithubDeviceTokenSuccess.kt
│ │ │ │ ├── GithubRelease.kt
│ │ │ │ ├── GithubRepoSummary.kt
│ │ │ │ ├── GithubUser.kt
│ │ │ │ ├── GithubUserProfile.kt
│ │ │ │ ├── InstallSource.kt
│ │ │ │ ├── InstalledApp.kt
│ │ │ │ ├── InstallerType.kt
│ │ │ │ ├── PackageChangeType.kt
│ │ │ │ ├── PaginatedDiscoveryRepositories.kt
│ │ │ │ ├── Platform.kt
│ │ │ │ ├── ProxyConfig.kt
│ │ │ │ ├── RateLimitException.kt
│ │ │ │ ├── RateLimitInfo.kt
│ │ │ │ ├── ShizukuAvailability.kt
│ │ │ │ ├── StarredRepository.kt
│ │ │ │ ├── SystemArchitecture.kt
│ │ │ │ ├── SystemPackageInfo.kt
│ │ │ │ └── UpdateHistory.kt
│ │ │ ├── network/
│ │ │ │ └── Downloader.kt
│ │ │ ├── repository/
│ │ │ │ ├── AuthenticationState.kt
│ │ │ │ ├── FavouritesRepository.kt
│ │ │ │ ├── InstalledAppsRepository.kt
│ │ │ │ ├── ProxyRepository.kt
│ │ │ │ ├── RateLimitRepository.kt
│ │ │ │ ├── SeenReposRepository.kt
│ │ │ │ ├── StarredRepository.kt
│ │ │ │ └── TweaksRepository.kt
│ │ │ ├── system/
│ │ │ │ ├── Installer.kt
│ │ │ │ ├── InstallerInfoExtractor.kt
│ │ │ │ ├── InstallerStatusProvider.kt
│ │ │ │ ├── PackageMonitor.kt
│ │ │ │ └── UpdateScheduleManager.kt
│ │ │ ├── use_cases/
│ │ │ │ └── SyncInstalledAppsUseCase.kt
│ │ │ └── utils/
│ │ │ ├── AppLauncher.kt
│ │ │ ├── BrowserHelper.kt
│ │ │ ├── ClipboardHelper.kt
│ │ │ └── ShareManager.kt
│ │ └── jvmMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── core/
│ │ └── domain/
│ │ └── Platform.jvm.kt
│ └── presentation/
│ ├── .gitignore
│ ├── build.gradle.kts
│ └── src/
│ ├── androidMain/
│ │ ├── AndroidManifest.xml
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── core/
│ │ └── presentation/
│ │ ├── theme/
│ │ │ └── Theme.android.kt
│ │ └── utils/
│ │ ├── ApplyAndroidSystemBars.android.kt
│ │ └── isLiquidFrostAvailable.android.kt
│ ├── commonMain/
│ │ ├── composeResources/
│ │ │ ├── drawable/
│ │ │ │ ├── ic_github.xml
│ │ │ │ ├── ic_platform_android.xml
│ │ │ │ ├── ic_platform_linux.xml
│ │ │ │ ├── ic_platform_macos.xml
│ │ │ │ └── ic_platform_windows.xml
│ │ │ ├── values/
│ │ │ │ └── strings.xml
│ │ │ ├── values-ar/
│ │ │ │ └── strings-ar.xml
│ │ │ ├── values-bn/
│ │ │ │ └── strings-bn.xml
│ │ │ ├── values-es/
│ │ │ │ └── strings-es.xml
│ │ │ ├── values-fr/
│ │ │ │ └── strings-fr.xml
│ │ │ ├── values-hi/
│ │ │ │ └── strings-hi.xml
│ │ │ ├── values-it/
│ │ │ │ └── strings-it.xml
│ │ │ ├── values-ja/
│ │ │ │ └── strings-ja.xml
│ │ │ ├── values-ko/
│ │ │ │ └── strings-ko.xml
│ │ │ ├── values-pl/
│ │ │ │ └── strings-pl.xml
│ │ │ ├── values-ru/
│ │ │ │ └── strings-ru.xml
│ │ │ ├── values-tr/
│ │ │ │ └── strings-tr.xml
│ │ │ └── values-zh-rCN/
│ │ │ └── strings-zh-rCN.xml
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── core/
│ │ └── presentation/
│ │ ├── components/
│ │ │ ├── ExpressiveCard.kt
│ │ │ ├── GitHubStoreImage.kt
│ │ │ ├── GithubStoreButton.kt
│ │ │ └── RepositoryCard.kt
│ │ ├── locals/
│ │ │ ├── LocalBottomNavigationHeight.kt
│ │ │ └── LocalBottomNavigationLiquid.kt
│ │ ├── model/
│ │ │ ├── DiscoveryRepositoryUi.kt
│ │ │ ├── GithubRepoSummaryUi.kt
│ │ │ └── GithubUserUi.kt
│ │ ├── theme/
│ │ │ ├── Color.kt
│ │ │ ├── Theme.kt
│ │ │ └── Type.kt
│ │ └── utils/
│ │ ├── AppThemeUtil.kt
│ │ ├── ApplyAndroidSystemBars.kt
│ │ ├── CountFormatter.kt
│ │ ├── DiscoveryPlatformUiResources.kt
│ │ ├── GithubRepoSummaryMappers.kt
│ │ ├── GithubUserMappers.kt
│ │ ├── ObserveAsEvents.kt
│ │ ├── TimeFormatters.kt
│ │ └── isLiquidFrostAvailable.kt
│ └── jvmMain/
│ └── kotlin/
│ └── zed/
│ └── rainxch/
│ └── core/
│ └── presentation/
│ ├── theme/
│ │ └── Theme.jvm.kt
│ └── utils/
│ ├── ApplyAndroidSystemBars.jvm.kt
│ └── isLiquidFrostAvailable.jvm.kt
├── docs/
│ ├── README-BN.md
│ ├── README-ES.md
│ ├── README-FR.md
│ ├── README-HI.md
│ ├── README-IT.md
│ ├── README-JA.md
│ ├── README-KR.md
│ ├── README-PL.md
│ ├── README-RU.md
│ ├── README-TR.md
│ └── README-ZH.md
├── fastlane/
│ └── metadata/
│ └── android/
│ └── en-US/
│ ├── full_description.txt
│ ├── short_description.txt
│ └── title.txt
├── feature/
│ ├── apps/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── apps/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ └── repository/
│ │ │ └── AppsRepositoryImpl.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── apps/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ ├── GithubRepoInfo.kt
│ │ │ │ └── ImportResult.kt
│ │ │ └── repository/
│ │ │ └── AppsRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── apps/
│ │ └── presentation/
│ │ ├── AppsAction.kt
│ │ ├── AppsEvent.kt
│ │ ├── AppsRoot.kt
│ │ ├── AppsState.kt
│ │ ├── AppsViewModel.kt
│ │ ├── components/
│ │ │ └── LinkAppBottomSheet.kt
│ │ ├── mappers/
│ │ │ ├── DeviceAppMapper.kt
│ │ │ ├── GithubAssetMapper.kt
│ │ │ ├── GithubRepoInfoMapper.kt
│ │ │ └── InstalledAppMapper.kt
│ │ └── model/
│ │ ├── AppItem.kt
│ │ ├── DeviceAppUi.kt
│ │ ├── GithubAssetUi.kt
│ │ ├── GithubRepoInfoUi.kt
│ │ ├── GithubUserUi.kt
│ │ ├── InstalledAppUi.kt
│ │ ├── UpdateAllProgress.kt
│ │ └── UpdateState.kt
│ ├── auth/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── auth/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── network/
│ │ │ │ └── GitHubAuthApi.kt
│ │ │ └── repository/
│ │ │ └── AuthenticationRepositoryImpl.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── auth/
│ │ │ └── domain/
│ │ │ └── repository/
│ │ │ └── AuthenticationRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── auth/
│ │ └── presentation/
│ │ ├── AuthenticationAction.kt
│ │ ├── AuthenticationEvents.kt
│ │ ├── AuthenticationRoot.kt
│ │ ├── AuthenticationState.kt
│ │ ├── AuthenticationViewModel.kt
│ │ ├── mapper/
│ │ │ └── GithubDeviceStartMapper.kt
│ │ └── model/
│ │ ├── AuthLoginState.kt
│ │ └── GithubDeviceStartUi.kt
│ ├── details/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── details/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── dto/
│ │ │ │ └── AttestationsResponse.kt
│ │ │ ├── model/
│ │ │ │ └── ReadmeAttempt.kt
│ │ │ ├── repository/
│ │ │ │ ├── DetailsRepositoryImpl.kt
│ │ │ │ └── TranslationRepositoryImpl.kt
│ │ │ └── utils/
│ │ │ ├── ReadmeLocalizationHelper.kt
│ │ │ └── preprocessMarkdown.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── details/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ ├── ReleaseCategory.kt
│ │ │ │ ├── RepoStats.kt
│ │ │ │ ├── SupportedLanguage.kt
│ │ │ │ └── TranslationResult.kt
│ │ │ └── repository/
│ │ │ ├── DetailsRepository.kt
│ │ │ └── TranslationRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── details/
│ │ └── presentation/
│ │ ├── DetailsAction.kt
│ │ ├── DetailsEvent.kt
│ │ ├── DetailsRoot.kt
│ │ ├── DetailsState.kt
│ │ ├── DetailsViewModel.kt
│ │ ├── components/
│ │ │ ├── AppHeader.kt
│ │ │ ├── LanguagePicker.kt
│ │ │ ├── ReleaseAssetsPicker.kt
│ │ │ ├── SmartInstallButton.kt
│ │ │ ├── StatItem.kt
│ │ │ ├── TranslationControls.kt
│ │ │ ├── VersionPicker.kt
│ │ │ ├── VersionTypePicker.kt
│ │ │ ├── sections/
│ │ │ │ ├── About.kt
│ │ │ │ ├── Header.kt
│ │ │ │ ├── Logs.kt
│ │ │ │ ├── Owner.kt
│ │ │ │ ├── ReportIssue.kt
│ │ │ │ ├── Stats.kt
│ │ │ │ └── WhatsNew.kt
│ │ │ └── states/
│ │ │ └── ErrorState.kt
│ │ ├── model/
│ │ │ ├── AttestationStatus.kt
│ │ │ ├── DownloadStage.kt
│ │ │ ├── InstallLogItem.kt
│ │ │ ├── LogResult.kt
│ │ │ ├── ShowDowngradeWarning.kt
│ │ │ ├── SigningKeyWarning.kt
│ │ │ ├── SupportedLanguages.kt
│ │ │ ├── TranslationState.kt
│ │ │ └── TranslationTarget.kt
│ │ └── utils/
│ │ ├── LocalTopbarLiquidState.kt
│ │ ├── LogResultAsText.kt
│ │ ├── MarkdownImageTransformer.kt
│ │ ├── MarkdownUtils.kt
│ │ └── SystemArchitecture.kt
│ ├── dev-profile/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── devprofile/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── dto/
│ │ │ │ ├── GitHubRepoResponse.kt
│ │ │ │ └── GitHubUserResponse.kt
│ │ │ ├── mappers/
│ │ │ │ ├── GitHubRepoToDomain.kt
│ │ │ │ └── GitHubUserToDomain.kt
│ │ │ └── repository/
│ │ │ └── DeveloperProfileRepositoryImpl.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── devprofile/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ ├── DeveloperProfile.kt
│ │ │ │ ├── DeveloperRepository.kt
│ │ │ │ ├── RepoFilterType.kt
│ │ │ │ └── RepoSortType.kt
│ │ │ └── repository/
│ │ │ └── DeveloperProfileRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── devprofile/
│ │ └── presentation/
│ │ ├── DeveloperProfileAction.kt
│ │ ├── DeveloperProfileRoot.kt
│ │ ├── DeveloperProfileState.kt
│ │ ├── DeveloperProfileViewModel.kt
│ │ └── components/
│ │ ├── DeveloperRepoItem.kt
│ │ ├── FilterSortControls.kt
│ │ ├── ProfileInfoCard.kt
│ │ └── StatsRow.kt
│ ├── favourites/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ └── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ └── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── favourites/
│ │ └── presentation/
│ │ ├── FavouritesAction.kt
│ │ ├── FavouritesRoot.kt
│ │ ├── FavouritesState.kt
│ │ ├── FavouritesViewModel.kt
│ │ ├── components/
│ │ │ └── FavouriteRepositoryItem.kt
│ │ ├── mappers/
│ │ │ └── FavouriteRepositoryMapper.kt
│ │ └── model/
│ │ └── FavouriteRepository.kt
│ ├── home/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── home/
│ │ │ └── data/
│ │ │ ├── data_source/
│ │ │ │ ├── CachedRepositoriesDataSource.kt
│ │ │ │ └── impl/
│ │ │ │ └── CachedRepositoriesDataSourceImpl.kt
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── dto/
│ │ │ │ ├── CachedGithubOwner.kt
│ │ │ │ ├── CachedGithubRepoSummary.kt
│ │ │ │ └── CachedRepoResponse.kt
│ │ │ ├── mappers/
│ │ │ │ └── CachedGithubRepoSummaryMappers.kt
│ │ │ └── repository/
│ │ │ └── HomeRepositoryImpl.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── home/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ └── HomeCategory.kt
│ │ │ └── repository/
│ │ │ └── HomeRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── home/
│ │ └── presentation/
│ │ ├── HomeAction.kt
│ │ ├── HomeEvent.kt
│ │ ├── HomeRoot.kt
│ │ ├── HomeState.kt
│ │ ├── HomeViewModel.kt
│ │ ├── components/
│ │ │ └── HomeFilterChips.kt
│ │ ├── locals/
│ │ │ └── LocalHomeTopBarLiquid.kt
│ │ └── utils/
│ │ └── HomeCategoryMapper.kt
│ ├── profile/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── profile/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── mappers/
│ │ │ │ └── UserProfileMappers.kt
│ │ │ └── repository/
│ │ │ └── ProfileRepositoryImpl.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── profile/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ └── UserProfile.kt
│ │ │ └── repository/
│ │ │ └── ProfileRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── profile/
│ │ └── presentation/
│ │ ├── ProfileAction.kt
│ │ ├── ProfileEvent.kt
│ │ ├── ProfileRoot.kt
│ │ ├── ProfileState.kt
│ │ ├── ProfileViewModel.kt
│ │ ├── SponsorScreen.kt
│ │ ├── components/
│ │ │ ├── LogoutDialog.kt
│ │ │ ├── SectionText.kt
│ │ │ └── sections/
│ │ │ ├── About.kt
│ │ │ ├── Account.kt
│ │ │ ├── AccountSection.kt
│ │ │ ├── Appearance.kt
│ │ │ ├── Installation.kt
│ │ │ ├── Network.kt
│ │ │ ├── Options.kt
│ │ │ ├── Others.kt
│ │ │ ├── ProfileSection.kt
│ │ │ └── SettingsSection.kt
│ │ └── model/
│ │ └── ProxyType.kt
│ ├── search/
│ │ ├── CLAUDE.md
│ │ ├── data/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── search/
│ │ │ └── data/
│ │ │ ├── di/
│ │ │ │ └── SharedModule.kt
│ │ │ ├── dto/
│ │ │ │ ├── AssetNetworkModel.kt
│ │ │ │ └── GithubReleaseNetworkModel.kt
│ │ │ ├── repository/
│ │ │ │ └── SearchRepositoryImpl.kt
│ │ │ └── utils/
│ │ │ └── LruCache.kt
│ │ ├── domain/
│ │ │ ├── .gitignore
│ │ │ ├── build.gradle.kts
│ │ │ └── src/
│ │ │ ├── androidMain/
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── commonMain/
│ │ │ └── kotlin/
│ │ │ └── zed/
│ │ │ └── rainxch/
│ │ │ └── domain/
│ │ │ ├── model/
│ │ │ │ ├── ProgrammingLanguage.kt
│ │ │ │ ├── SortBy.kt
│ │ │ │ └── SortOrder.kt
│ │ │ └── repository/
│ │ │ └── SearchRepository.kt
│ │ └── presentation/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ ├── androidMain/
│ │ │ └── AndroidManifest.xml
│ │ └── commonMain/
│ │ └── kotlin/
│ │ └── zed/
│ │ └── rainxch/
│ │ └── search/
│ │ └── presentation/
│ │ ├── SearchAction.kt
│ │ ├── SearchEvent.kt
│ │ ├── SearchRoot.kt
│ │ ├── SearchState.kt
│ │ ├── SearchViewModel.kt
│ │ ├── components/
│ │ │ ├── LanguageFilterBottomSheet.kt
│ │ │ └── SortByBottomSheet.kt
│ │ ├── mappers/
│ │ │ ├── PlatformLanguageMappers.kt
│ │ │ ├── SearchPlatformMappers.kt
│ │ │ ├── SortByMappers.kt
│ │ │ └── SortOrderMapper.kt
│ │ ├── model/
│ │ │ ├── ParsedGithubLink.kt
│ │ │ ├── ProgrammingLanguageUi.kt
│ │ │ ├── SearchPlatformUi.kt
│ │ │ ├── SortByUi.kt
│ │ │ └── SortOrderUi.kt
│ │ └── utils/
│ │ ├── GithubUrlParser.kt
│ │ ├── ProgrammingLanguageMapper.kt
│ │ ├── SortByMapper.kt
│ │ └── SortOrderMapper.kt
│ └── starred/
│ ├── CLAUDE.md
│ ├── data/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ └── androidMain/
│ │ └── AndroidManifest.xml
│ ├── domain/
│ │ ├── .gitignore
│ │ ├── build.gradle.kts
│ │ └── src/
│ │ └── androidMain/
│ │ └── AndroidManifest.xml
│ └── presentation/
│ ├── .gitignore
│ ├── build.gradle.kts
│ └── src/
│ ├── androidMain/
│ │ └── AndroidManifest.xml
│ └── commonMain/
│ └── kotlin/
│ └── zed/
│ └── rainxch/
│ └── starred/
│ └── presentation/
│ ├── StarredReposAction.kt
│ ├── StarredReposRoot.kt
│ ├── StarredReposState.kt
│ ├── StarredReposViewModel.kt
│ ├── components/
│ │ └── StarredRepositoryItem.kt
│ ├── mappers/
│ │ └── StarredRepoToUiMapper.kt
│ ├── model/
│ │ └── StarredRepositoryUi.kt
│ └── utils/
│ └── TimeFormatUtils.kt
├── gradle/
│ ├── libs.versions.toml
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── packaging/
│ └── flatpak/
│ ├── README.md
│ ├── disable-android-for-flatpak.sh
│ ├── flatpak-sources.json
│ ├── githubstore.sh
│ ├── zed.rainxch.githubstore.desktop
│ ├── zed.rainxch.githubstore.metainfo.xml
│ └── zed.rainxch.githubstore.yml
└── settings.gradle.kts
================================================
FILE CONTENTS
================================================
================================================
FILE: .claude/memory/feedback_coding_boundaries.md
================================================
---
name: coding_boundaries
description: User wants to write all non-trivial logic themselves — Claude should only review, suggest, and handle boilerplate
type: feedback
---
Never write the "hard parts" — architecture decisions, core business logic, state management patterns, bug fix implementations, algorithm design. Instead, review the user's code, point out issues, suggest approaches, and explain tradeoffs. Let the user implement it.
**Why:** The user noticed their coding instincts and skills declining from over-delegating to Claude. They want to stay sharp by doing the thinking and implementation themselves.
**How to apply:**
- **Hard parts** (user codes): ViewModel logic, repository implementations, state flows, bug fixes, architectural patterns, cache strategies, concurrency handling, UI interaction logic. For these — review, suggest, explain, but don't write the code.
- **Boilerplate** (Claude codes): repetitive refactors, string resources, migration scaffolding, import fixes, build config, copy-paste patterns, test scaffolding, file moves/renames.
- When the user asks to fix a bug or implement a feature, describe what's wrong and suggest an approach — then let them write it.
- If the user explicitly asks "just do it" for something non-trivial, remind them of this agreement first.
================================================
FILE: .coderabbit.yaml
================================================
language: "en-US"
early_access: false
reviews:
profile: "chill"
request_changes_workflow: false
high_level_summary: true
poem: true
review_status: true
collapse_walkthrough: false
auto_review:
enabled: true
drafts: false
================================================
FILE: .editorconfig
================================================
root = true
[*.{kt,kts}]
ktlint_standard_filename = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_function_naming_ignore_when_annotated_with = Composable
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: [rainxchzed]
buy_me_a_coffee: rainxchzed
custom: https://golden-kodee.awardsplatform.com/entry/vote/mNKjQxkX/vnZAamgg?search=8154c88ed0eccba9-70
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
================================================
FILE: .github/ISSUE_TEMPLATE/custom.md
================================================
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''
---
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
================================================
FILE: .github/workflows/build-desktop-platforms.yml
================================================
name: Build Desktop Platform Installers
on:
push:
branches:
- generate-installers
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: '21'
JAVA_DISTRIBUTION: 'temurin'
GRADLE_OPTS: >-
-Dorg.gradle.daemon=false
-Dorg.gradle.parallel=true
-Dorg.gradle.caching=true
-Dorg.gradle.vfs.watch=false
jobs:
build-windows:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
gradle-home-cache-cleanup: true
- name: Grant execute permission for gradlew
run: chmod +x gradlew
shell: bash
- name: Build Windows installers (EXE & MSI)
run: |
set -euo pipefail
retry() {
local n=1 max=3 delay=5
while true; do
echo "Attempt #$n: $*"
"$@" && break
[ $n -ge $max ] && { echo "Failed after $n attempts."; return 1; }
n=$((n+1)); echo "Retrying in ${delay}s..."; sleep $delay; delay=$((delay*2))
done
}
retry ./gradlew :composeApp:packageExe :composeApp:packageMsi
shell: bash
- name: Upload Windows installers
uses: actions/upload-artifact@v4
with:
name: windows-installers
path: |
composeApp/build/compose/binaries/main/exe/*.exe
composeApp/build/compose/binaries/main/msi/*.msi
retention-days: 30
compression-level: 6
build-macos:
strategy:
matrix:
include:
- os: macos-15-intel
arch: x64
- os: macos-latest
arch: arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
gradle-home-cache-cleanup: true
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build macOS installers (DMG & PKG)
run: |
set -euo pipefail
retry() {
local n=1 max=3 delay=5
while true; do
echo "Attempt #$n: $*"
"$@" && break
[ $n -ge $max ] && { echo "Failed after $n attempts."; return 1; }
n=$((n+1)); echo "Retrying in ${delay}s..."; sleep $delay; delay=$((delay*2))
done
}
retry ./gradlew :composeApp:packageDmg :composeApp:packagePkg
shell: bash
- name: Upload macOS installers
uses: actions/upload-artifact@v4
with:
name: macos-installers-${{ matrix.arch }}
path: |
composeApp/build/compose/binaries/main/dmg/*.dmg
composeApp/build/compose/binaries/main/pkg/*.pkg
retention-days: 30
compression-level: 6
build-linux:
strategy:
matrix:
include:
- os: ubuntu-latest
label: modern
gradle-tasks: >-
:composeApp:packageDeb
:composeApp:packageRpm
:composeApp:packageAppImage
- os: ubuntu-22.04
label: debian12-compat
gradle-tasks: >-
:composeApp:packageDeb
:composeApp:packageRpm
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
gradle-home-cache-cleanup: true
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Linux installers
run: |
set -euo pipefail
retry() {
local n=1 max=3 delay=5
while true; do
echo "Attempt #$n: $*"
"$@" && break
[ $n -ge $max ] && { echo "Failed after $n attempts."; return 1; }
n=$((n+1)); echo "Retrying in ${delay}s..."; sleep $delay; delay=$((delay*2))
done
}
retry ./gradlew ${{ matrix.gradle-tasks }}
shell: bash
- name: List AppImage build output
if: matrix.label == 'modern'
run: |
echo "=== Listing build output ==="
find composeApp/build/compose/binaries/main -maxdepth 3 -type d 2>/dev/null || echo "Directory not found"
echo "=== All files ==="
find composeApp/build/compose/binaries/main -maxdepth 4 -type f 2>/dev/null | head -30 || echo "No files found"
shell: bash
- name: Build AppImage with appimagetool
if: matrix.label == 'modern'
run: |
set -euo pipefail
# Find the directory containing the app launcher (bin/GitHub-Store)
APP_ROOT=""
for candidate in \
composeApp/build/compose/binaries/main/app-image/GitHub-Store \
composeApp/build/compose/binaries/main/app/GitHub-Store \
composeApp/build/compose/binaries/main/app-image \
composeApp/build/compose/binaries/main/app; do
if [ -f "$candidate/bin/GitHub-Store" ]; then
APP_ROOT="$candidate"
echo "Found app root at: $candidate"
break
fi
done
if [ -z "$APP_ROOT" ]; then
echo "ERROR: Could not find app launcher (bin/GitHub-Store)"
find composeApp/build/compose/binaries/main -type f -name "GitHub-Store" 2>/dev/null || true
exit 1
fi
# Download appimagetool
wget -q https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x appimagetool-x86_64.AppImage
# Create AppDir from Compose output
APPDIR="GitHub-Store.AppDir"
mv "$APP_ROOT" "$APPDIR"
# Create AppRun entry point
cat > "$APPDIR/AppRun" << 'EOF'
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
exec "${HERE}/bin/GitHub-Store" "$@"
EOF
chmod +x "$APPDIR/AppRun"
# Create .desktop file
cat > "$APPDIR/github-store.desktop" << 'EOF'
[Desktop Entry]
Type=Application
Name=GitHub Store
Exec=GitHub-Store
Icon=github-store
Categories=Development;
Comment=Cross-platform app store for GitHub releases
EOF
# Copy icon to AppDir root (required by appimagetool)
cp "$APPDIR/lib/GitHub-Store.png" "$APPDIR/github-store.png"
# Build .AppImage
OUTPUT="composeApp/build/compose/binaries/main/GitHub-Store-x86_64.AppImage"
UPINFO="gh-releases-zsync|rainxchzed|Github-Store|latest|*x86_64.AppImage.zsync"
ARCH=x86_64 APPIMAGE_EXTRACT_AND_RUN=1 ./appimagetool-x86_64.AppImage -u "$UPINFO" "$APPDIR" "$OUTPUT"
# appimagetool may place .zsync in the working directory; move it next to the AppImage
ZSYNC_NAME="$(basename "$OUTPUT").zsync"
if [ -f "$ZSYNC_NAME" ] && [ ! -f "$OUTPUT.zsync" ]; then
mv "$ZSYNC_NAME" "$OUTPUT.zsync"
fi
echo "Created AppImage and zsync:"
ls -lh "$OUTPUT" "$OUTPUT.zsync"
shell: bash
- name: Upload Linux installers
uses: actions/upload-artifact@v4
with:
name: linux-installers-${{ matrix.label }}
path: |
composeApp/build/compose/binaries/main/deb/*.deb
composeApp/build/compose/binaries/main/rpm/*.rpm
retention-days: 30
compression-level: 6
- name: Upload Linux AppImage
if: matrix.label == 'modern'
uses: actions/upload-artifact@v4
with:
name: linux-appimage
path: |
composeApp/build/compose/binaries/main/GitHub-Store-x86_64.AppImage
composeApp/build/compose/binaries/main/GitHub-Store-x86_64.AppImage.zsync
if-no-files-found: error
retention-days: 30
compression-level: 0
================================================
FILE: .gitignore
================================================
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Log/OS Files
*.log
# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.aab
*.apk
output-metadata.json
# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml
# Keystore files
*.jks
*.keystore
# Google Services (e.g. APIs or Firebase)
google-services.json
# Android Profiling
*.hprof
.kotlin/
composeApp/release/baselineProfiles/
composeApp/kotzilla.json
================================================
FILE: CLAUDE.md
================================================
# CLAUDE.md - GitHub Store
## Project Overview
GitHub Store is a cross-platform app store for GitHub releases, built with **Kotlin Multiplatform (KMP)** and **Compose Multiplatform**. Targets **Android** (min API 26) and **Desktop** (Windows, macOS, Linux via JVM).
Package: `zed.rainxch.githubstore` | Version: 1.6.2 (code 13) | Target SDK: 36
## Build & Run Commands
```bash
# Android
./gradlew :composeApp:assembleDebug
./gradlew :composeApp:assembleRelease
# Desktop (run in dev mode)
./gradlew :composeApp:run
# Desktop installers
./gradlew :composeApp:packageExe :composeApp:packageMsi # Windows
./gradlew :composeApp:packageDmg :composeApp:packagePkg # macOS
./gradlew :composeApp:packageDeb :composeApp:packageRpm # Linux
# Full build check
./gradlew build
```
**Requirements:** JDK 21+ (Temurin recommended), Android SDK for Android builds.
## Project Structure
```
composeApp/ # Main app module (entry points, navigation, DI wiring)
src/commonMain/ # Shared UI & app wiring
src/androidMain/ # Android entry point (MainActivity)
src/jvmMain/ # Desktop entry point (DesktopApp.kt)
core/
domain/ # Shared interfaces, models, use cases (no framework deps)
data/ # Shared repos, networking (Ktor), database (Room), DI
presentation/ # Shared theming (Material 3) & reusable UI components
feature/
apps/ # Installed applications management
auth/ # GitHub OAuth device flow authentication
details/ # Repository details, releases, readme, downloads
dev-profile/ # Developer/user profile display
favourites/ # Saved favorite repositories (presentation-only)
home/ # Main discovery screen (trending, hot, popular)
profile/ # User profile, settings, appearance, proxy, Shizuku installer
search/ # Repository search with filters
starred/ # Starred repositories (presentation-only)
build-logic/convention/ # Custom Gradle convention plugins
```
Each feature has up to 3 sub-modules: `domain/` (interfaces & models), `data/` (implementations & DI), `presentation/` (screens & ViewModels). Some features (favourites, starred) are presentation-only and use core repositories directly.
## Architecture
**Clean Architecture + MVVM** with strict layer separation per feature module:
- **Domain** - Repository interfaces, models, use cases (no framework dependencies)
- **Data** - Repository implementations, Ktor API clients, Room DAOs, DTOs, mappers
- **Presentation** - ViewModels with `StateFlow`/`Channel`, Compose screens
### State Management Pattern
Every screen follows the same State/Action/Event pattern:
```kotlin
class XViewModel : ViewModel() {
private val _state = MutableStateFlow(XState())
val state = _state.asStateFlow() // or .stateIn() with WhileSubscribed
private val _events = Channel()
val events = _events.receiveAsFlow()
fun onAction(action: XAction) { ... }
}
```
- `State` - data class holding all UI state
- `Action` - sealed interface for user input (clicks, refreshes, etc.)
- `Event` - sealed interface for one-off effects (navigation, toasts, scroll)
### Navigation
Type-safe navigation using `@Serializable` sealed interface `GithubStoreGraph`:
```
HomeScreen, SearchScreen, AuthenticationScreen, ProfileScreen,
FavouritesScreen, StarredReposScreen, AppsScreen, SponsorScreen
DetailsScreen(repositoryId, owner, repo, isComingFromUpdate)
DeveloperProfileScreen(username)
```
Routes defined in `composeApp/.../app/navigation/GithubStoreGraph.kt`, wired in `AppNavigation.kt`.
### Dependency Injection
**Koin** - modules defined in each feature's `data/di/SharedModule.kt`, registered in `composeApp/.../app/di/initKoin.kt`. ViewModels injected via `koinViewModel()`.
### Core Modules
| Module | Purpose | Key Contents |
|--------|---------|--------------|
| `core/domain` | Shared contracts | Repository interfaces (`FavouritesRepository`, `StarredRepository`, `InstalledAppsRepository`, `ThemesRepository`, `ProxyRepository`, `RateLimitRepository`), models (`GithubRepoSummary`, `GithubRelease`, `InstalledApp`, `ProxyConfig`, `InstallerType`, `ShizukuAvailability`), system interfaces (`Installer`, `InstallerInfoExtractor`, `InstallerStatusProvider`, `PackageMonitor`) |
| `core/data` | Shared implementations | `HttpClientFactory` (Ktor + interceptors), `AppDatabase` (Room), `ProxyManager`, `TokenStore`, `LocalizationManager`, platform-specific clients (OkHttp for Android, CIO for Desktop), Shizuku integration (Android: `ShizukuServiceManager`, `ShizukuInstallerWrapper`, `ShizukuInstallerServiceImpl`, `AndroidInstallerStatusProvider`; Desktop: `DesktopInstallerStatusProvider`) |
| `core/presentation` | Shared UI | `GithubStoreTheme` (Material 3), reusable components (`RepositoryCard`, `GithubStoreButton`), formatting utils, localized strings (11 languages) |
## Tech Stack
| Area | Library | Version |
|------|---------|---------|
| Language | Kotlin | 2.3.10 |
| UI | Compose Multiplatform | 1.10.1 |
| HTTP | Ktor | 3.4.0 |
| Database | Room | 2.8.4 |
| DI | Koin | 4.1.1 |
| Serialization | Kotlinx Serialization | 1.10.0 |
| Preferences | DataStore | 1.2.0 |
| Image Loading | Landscapist (Coil3) | 2.9.5 |
| Logging | Kermit | 2.0.8 |
| Permissions | MOKO Permissions | 0.20.1 |
| Navigation | Navigation Compose | 2.9.2 |
| Markdown | Multiplatform Markdown Renderer | 0.39.2 |
| Shizuku | Shizuku API | 13.1.5 |
| Background Work | WorkManager | 2.11.1 |
| Date/Time | Kotlinx Datetime | 0.7.1 |
All versions managed in `gradle/libs.versions.toml` (Version Catalog).
## Convention Plugins
Custom Gradle plugins in `build-logic/convention/` standardize module setup:
| Plugin | Use For |
|--------|---------|
| `convention.kmp.library` | KMP shared library modules (domain, data) |
| `convention.cmp.library` | Compose Multiplatform library modules (core/presentation) |
| `convention.cmp.feature` | Feature presentation modules (auto-adds Compose + Koin + core:presentation) |
| `convention.cmp.application` | Main app module |
| `convention.room` | Room database modules |
| `convention.buildkonfig` | Build-time config (API keys from local.properties) |
## Adding a New Feature
1. Create `feature//domain/`, `feature//data/`, `feature//presentation/`
2. Add `build.gradle.kts` in each using the appropriate convention plugin
3. Add `include` entries in `settings.gradle.kts`
4. Define domain interfaces/models in `domain/`
5. Implement repository + Koin DI module in `data/di/SharedModule.kt`
6. Create ViewModel (State/Action/Event pattern) and Screen in `presentation/`
7. Add navigation route to `GithubStoreGraph.kt` and wire in `AppNavigation.kt`
8. Register the Koin module in `initKoin.kt`
## Key Configuration
- **GitHub OAuth:** Set `GITHUB_CLIENT_ID` in `local.properties`. Callback URL: `githubstore://callback`. Deep link: `githubstore://repo`
- **Shizuku (Android):** Optional silent install via `ShizukuProvider` (registered in AndroidManifest). Requires Shizuku app running with ADB or root. AIDL service passes APK via `ParcelFileDescriptor` to `pm install -S`. Falls back to standard installer on failure.
- **Gradle properties:** Config cache enabled, build cache enabled, 4GB Gradle heap, 3GB Kotlin daemon heap
- **Code style:** Official Kotlin style (`kotlin.code.style=official`)
## Coding Conventions
- Packages follow `zed.rainxch.{module}.{layer}` pattern
- Private state properties use underscore prefix: `_state`
- Sealed classes/interfaces for type-safe navigation routes, actions, events
- Repository pattern: interface in `domain/`, implementation in `data/`
- Composition over inheritance via Koin DI
- Source sets: `commonMain` for shared, `androidMain` for Android, `jvmMain` for Desktop
- Feature CLAUDE.md files exist in each `feature/` directory for module-specific guidance
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
rainxchzed@gmail.com.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
================================================
FILE: CONTRIBUTING.md
================================================
## How to contribute
We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
## Preparing a pull request for review
Before opening a pull request, please:
- Make sure the code builds on all supported targets (Android + Desktop).
- Add or update tests where it makes sense.
- Keep changes focused and reasonably small.
If you introduce new dependencies or modules, briefly explain why in the PR description.
## Code reviews
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult
[GitHub Help](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
for more information on using pull requests.
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
# GitHub Store
# 🗺️ Project Overview
GitHub Store is a cross-platform app store for GitHub releases, designed to simplify discovering and installing open-source software. It automatically detects installable binaries (APK, EXE, DMG, AppImage, DEB, RPM), provides one-click installation, tracks updates, and presents repository information in a clean, app-store style interface.
Built with Kotlin Multiplatform and Compose Multiplatform for Android and Desktop platforms.
> [!CAUTION]
> Free and Open-Source Android is under threat. Google will turn Android into a locked-down platform, restricting your essential freedom to install apps of your choice. Make your voice heard – [keepandroidopen.org](https://keepandroidopen.org/).
# 📔 Wiki & Resources
Check out GitHub Store [Wiki](https://github.com/OpenHub-Store/GitHub-Store/wiki) for FAQ and useful information
🌐 **Website:** [github-store.org](https://github-store.org)
💬 **Discord:** [Join the community](https://discord.gg/x9Cvh2Z9qS)
📜 **Privacy Policy:** [github-store.org/privacy-policy](https://github-store.org/privacy-policy/)
---
### 📋 Legal Notice
GitHub Store is an independent, open-source project not affiliated with GitHub, Inc.
The name describes the app's functionality (discovering GitHub releases) and does not imply trademark ownership.
GitHub® is a registered trademark of GitHub, Inc.
---
# 🔃 Download
> [!IMPORTANT]
> **macOS Users:** You may see a warning that Apple cannot verify GitHub Store. This happens because the app is distributed outside the App Store and is not notarized yet. Allow it via System Settings → Privacy & Security → Open Anyway.
---
# 🏆 Featured In
HowToMen: Top 20 Best Android Apps 2026 | Top 12 App Stores that are Better than Google Play Store
HelloGitHub: Featured Project
---
## 🚀 Features
- **Smart discovery**
- Home sections for “Trending”, “Hot Release”, and “Most Popular” projects with time‑based filters.
- Only repos with valid installable assets are shown.
- Platform‑aware topic scoring so Android/desktop users see relevant apps first.
- Overhauled search with improved relevance ranking and performance.
- **Release browser & installs**
- Release picker to browse and install from any release, not just the latest.
- Fetches all releases for each repository.
- Single “Install latest” action, plus an expandable list of all available releases and their installers.
- Manual install option with automatic compatibility checks.
- **Rich details screen**
- App name, version and share action.
- Stars, forks, open issues.
- Rendered README content (“About this app”).
- Release notes with Markdown formatting for any selected release.
- List of installers with platform labels and file sizes.
- Deep linking support — open repository details directly via URL.
- Developer profile screen to explore a developer’s repositories and activity.
- **App management**
- Open, uninstall, and downgrade installed apps directly from GitHub Store.
- Android: APK architecture matching (armv7/armv8), package monitoring, and update tracking.
- Desktop (Windows/macOS/Linux): downloads installers to the user’s Downloads folder and opens them with the default handler.
- **Starred repositories**
- Save and browse your starred GitHub repositories from within the app.
- **Network & performance**
- Dynamic proxy support for configurable network routing.
- Enhanced caching system for faster loading and reduced API usage.
---
## 🔍 How does my app appear in GitHub Store?
GitHub Store does not use any private indexing or manual curation rules.
Your project can appear automatically if it follows these conditions:
1. **Public repository on GitHub**
- Visibility must be `public`.
2. **Installable assets in the latest release**
- The latest release must contain at least one asset file with a supported extension:
- Android: `.apk`
- Windows: `.exe`, `.msi`
- macOS: `.dmg`, `.pkg`
- Linux: `.deb`, `.rpm`, `.AppImage`
- GitHub Store ignores GitHub’s auto‑generated source artifacts (`Source code (zip)` /
`Source code (tar.gz)`).
3. **Discoverable by search / topics**
- Repositories are fetched via the public GitHub Search API.
- Topic, language, and description help the ranking:
- Android apps: topics like `android`, `mobile`, `apk`.
- Desktop apps: topics like `desktop`, `windows`, `linux`, `macos`, `compose-desktop`,
`electron`.
- Having at least a few stars makes it more likely to appear under Trending/Hot Release/Most Popular sections.
If your repo meets these conditions, GitHub Store can find it through search and show it
automatically—no manual submission required.
---
## ✅ Pros / Why use GitHub Store?
- **No more hunting through GitHub releases**
See only repos that actually ship binaries for your platform.
- **Knows what you installed**
Tracks apps installed via GitHub Store (Android) and highlights when new releases are available, so you can update them without hunting through GitHub again.
- **Always up to date**
Installs default to the latest published release, with the option to browse and install from
any previous release via the release picker.
- **Open source & extensible**
Written in KMP with a clear separation between networking, domain logic, and UI—easy to fork,
extend, or adapt.
---
## 🔐 GitHub Store APK Signing Certificate
All official GitHub Store releases are signed with the following certificate fingerprint:
SHA-256:
`B7:F2:8E:19:8E:48:C1:93:B0:38:C6:5D:92:DD:F7:BC:07:7B:0D:B5:9E:BC:9B:25:0A:6D:AC:48:C1:18:03:CA`
---
## 🔑 GitHub OAuth Configuration
**TL;DR**
1. Create a GitHub OAuth App
2. Copy **Client ID**
3. Put it in `local.properties`
Show full setup guide
### 1 - Create a GitHub OAuth App
Go to:
**GitHub → Settings → Developer settings → OAuth Apps → New OAuth App**
| Field | Value |
| ------------------------------ | ------------------------------------------- |
| **Application name** | Anything you like (e.g. *GitHub Store Dev*) |
| **Homepage URL** | `https://github.com/username/repo_name` |
| **Authorization callback URL** | `githubstore://callback` |
Then click **Create application**.
### 2 - Copy Your Client ID
After creating the app, GitHub will show:
- **Client ID** ← you need this
- **Client Secret** ← ❗ NOT required for this project
### 3 - Add It to Your Project
Open your project’s `local.properties` file (root of the project) and add:
```properties
GITHUB_CLIENT_ID=YOUR_CLIENT_ID_HERE
```
### 4 - Sync & Run
Sync the project and run the app. You should now be able to sign in with GitHub.
### ❗ Important Notes
- `local.properties` is **not committed to Git**, so your Client ID stays local.
- This project only needs the **Client ID** (not the Client Secret).
- Each developer should create their own OAuth app for development.
---
## ☕ Support the project
GitHub Store is built and maintained by high school student. Your support helps him:
✅ **Keep the app bug-free** — respond to issues and ship fixes quickly
✅ **Add community-requested features** — implement what users actually need
### 💖 Ways to Support
**Can't sponsor right now?** That's okay! You can still help by:
- ⭐ **Starring this repo** — helps others discover GitHub Store
- 🐛 **Reporting bugs** — makes the app better for everyone
- 📢 **Sharing with friends** — spread the word to other developers and tech and non-tech buddies!
- 💬 **Joining our [Discord](https://discord.gg/x9Cvh2Z9qS)** — your feedback shapes the roadmap
Every bit of support—financial or not—means the world and keeps this project alive. Thank you!
---
## ⚠️ Disclaimer
GitHub Store only helps you discover and download release assets that are already published on
GitHub by third‑party developers.
The contents, safety, and behavior of those downloads are entirely the responsibility of their
respective authors and distributors, not this project.
By using GithubStore, you understand and agree that you install and run any downloaded software at
your own risk.
This project does not review, validate, or guarantee that any installer is safe, free of malware, or
fit for any particular purpose.
---
## Star History

## 📄 License
GitHub Store will be released under the **Apache License, Version 2.0**.
```
Copyright 2025 rainxchzed
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this project except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
================================================
FILE: SECURITY.md
================================================
## Security Policy
## Reporting a Vulnerability
We take the security of this repository seriously. If you discover a security vulnerability, please report it responsibly.
**Please do not open a public GitHub issue for security vulnerabilities.**
Instead, use one of the following methods:
- **GitHub Security Advisories**
Use the "Report a vulnerability" feature available in the repository’s **Security** tab.
- **Email**
Send a detailed report to: [rainxch.dev@gmail.com](mailto:rainxch.dev@gmail.com)
---
## What to Include in Your Report
To help us assess and resolve the issue quickly, please include:
- A clear description of the vulnerability
- Steps to reproduce the issue
- Proof of concept (PoC), if available
- Affected files, endpoints, or components
- Potential impact of the vulnerability
---
## Response Timeline
We aim to follow this general timeline:
- **Acknowledgement:** Within 48 hours
- **Initial assessment:** Within 5 business days
- **Fix or mitigation:** Based on severity and complexity
Timelines may vary depending on the nature of the vulnerability.
---
## Coordinated Disclosure
We kindly request that you practice responsible disclosure and avoid sharing details publicly until the vulnerability has been addressed or a fix has been released.
---
## Security Best Practices
Contributors are encouraged to:
- Follow secure coding practices
- Avoid committing secrets or credentials
- Use dependency scanning and security tools where possible
- Review pull requests for potential security issues
---
## Thank You
We appreciate the efforts of the security community and responsible researchers who help keep this project secure.
================================================
FILE: build-logic/convention/build.gradle.kts
================================================
import org.gradle.kotlin.dsl.compileOnly
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
`kotlin-dsl`
}
group = "zed.rainxch.convention.buildlogic"
dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.android.tools.common)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.androidx.room.gradle.plugin)
implementation(libs.buildkonfig.gradlePlugin)
implementation(libs.buildkonfig.compiler)
implementation(libs.ktlint.gradlePlugin)
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
}
}
tasks {
validatePlugins {
enableStricterValidation = true
failOnWarning = true
}
}
gradlePlugin {
plugins {
register("androidApplication") {
id = "zed.rainxch.convention.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
register("androidComposeApplication") {
id = "zed.rainxch.convention.android.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}
register("cmpApplication") {
id = "zed.rainxch.convention.cmp.application"
implementationClass = "CmpApplicationConventionPlugin"
}
register("kmpLibrary") {
id = "zed.rainxch.convention.kmp.library"
implementationClass = "KmpLibraryConventionPlugin"
}
register("cmpLibrary") {
id = "zed.rainxch.convention.cmp.library"
implementationClass = "CmpLibraryConventionPlugin"
}
register("cmpFeature") {
id = "zed.rainxch.convention.cmp.feature"
implementationClass = "CmpFeatureConventionPlugin"
}
register("buildKonfig") {
id = "zed.rainxch.convention.buildkonfig"
implementationClass = "BuildKonfigConventionPlugin"
}
register("room") {
id = "zed.rainxch.convention.room"
implementationClass = "RoomConventionPlugin"
}
register("ktlint") {
id = "zed.rainxch.convention.ktlint"
implementationClass = "KtlintConventionPlugin"
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt
================================================
import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import zed.rainxch.githubstore.convention.configureAndroidCompose
class AndroidApplicationComposeConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("zed.rainxch.convention.android.application")
apply("org.jetbrains.kotlin.plugin.compose")
apply("zed.rainxch.convention.ktlint")
}
val commonExtension = extensions.getByType()
configureAndroidCompose(commonExtension)
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
================================================
import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import zed.rainxch.githubstore.convention.configureKotlinAndroid
import zed.rainxch.githubstore.convention.libs
class AndroidApplicationConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
}
extensions.configure {
namespace = "zed.rainxch.githubstore"
compileSdk =
libs
.findVersion("projectCompileSdkVersion")
.get()
.toString()
.toInt()
defaultConfig {
applicationId = libs.findVersion("projectApplicationId").get().toString()
minSdk =
libs
.findVersion("projectMinSdkVersion")
.get()
.toString()
.toInt()
targetSdk =
libs
.findVersion("projectTargetSdkVersion")
.get()
.toString()
.toInt()
versionCode =
libs
.findVersion("projectVersionCode")
.get()
.toString()
.toInt()
versionName = libs.findVersion("projectVersionName").get().toString()
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}
configureKotlinAndroid(this)
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/BuildKonfigConventionPlugin.kt
================================================
import com.codingfeline.buildkonfig.compiler.FieldSpec
import com.codingfeline.buildkonfig.gradle.BuildKonfigExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import zed.rainxch.githubstore.convention.libs
import zed.rainxch.githubstore.convention.pathToPackageName
import java.util.Properties
class BuildKonfigConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.codingfeline.buildkonfig")
}
extensions.configure {
packageName = target.pathToPackageName()
defaultConfigs {
val localProps =
Properties().apply {
val file = rootProject.file("local.properties")
if (file.exists()) file.inputStream().use { this.load(it) }
}
val githubClientId =
(
localProps.getProperty("GITHUB_CLIENT_ID")
?: "Ov23linTY28VFpFjFiI9"
).trim()
val versionName = libs.findVersion("projectVersionName").get().toString()
buildConfigField(FieldSpec.Type.STRING, "GITHUB_CLIENT_ID", githubClientId)
buildConfigField(FieldSpec.Type.STRING, "VERSION_NAME", versionName)
}
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt
================================================
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import zed.rainxch.githubstore.convention.configureAndroidTarget
import zed.rainxch.githubstore.convention.configureJvmTarget
import zed.rainxch.githubstore.convention.libs
class CmpApplicationConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("zed.rainxch.convention.android.application.compose")
apply("org.jetbrains.kotlin.multiplatform")
apply("org.jetbrains.compose")
apply("org.jetbrains.kotlin.plugin.compose")
}
configureAndroidTarget()
configureJvmTarget()
dependencies {
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling").get())
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt
================================================
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import zed.rainxch.githubstore.convention.libs
class CmpFeatureConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("zed.rainxch.convention.cmp.library")
}
dependencies {
"commonMainImplementation"(project(":core:presentation"))
"commonMainImplementation"(platform(libs.findLibrary("koin-bom").get()))
"androidMainImplementation"(platform(libs.findLibrary("koin-bom").get()))
"commonMainImplementation"(libs.findLibrary("koin-compose").get())
"commonMainImplementation"(libs.findLibrary("koin-compose-viewmodel").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-runtime").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-viewmodel").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-lifecycle-viewmodel").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-lifecycle-compose").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-lifecycle-viewmodel-savedstate").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-savedstate").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-bundle").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-navigation").get())
"androidMainImplementation"(libs.findLibrary("koin-android").get())
"androidMainImplementation"(libs.findLibrary("koin-androidx-compose").get())
"androidMainImplementation"(libs.findLibrary("koin-androidx-navigation").get())
"androidMainImplementation"(libs.findLibrary("koin-core-viewmodel").get())
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/CmpLibraryConventionPlugin.kt
================================================
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import zed.rainxch.githubstore.convention.libs
import kotlin.text.get
class CmpLibraryConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("zed.rainxch.convention.kmp.library")
apply("org.jetbrains.kotlin.plugin.compose")
apply("org.jetbrains.compose")
}
dependencies {
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-ui").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-foundation").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-material3").get())
"commonMainImplementation"(libs.findLibrary("jetbrains-compose-material-icons-extended").get())
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling").get())
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt
================================================
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import zed.rainxch.githubstore.convention.configureKotlinAndroid
import zed.rainxch.githubstore.convention.configureKotlinMultiplatform
import zed.rainxch.githubstore.convention.libs
import zed.rainxch.githubstore.convention.pathToResourcePrefix
class KmpLibraryConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
apply("org.jetbrains.kotlin.plugin.serialization")
}
configureKotlinMultiplatform()
extensions.configure {
configureKotlinAndroid(this)
resourcePrefix = this@with.pathToResourcePrefix()
experimentalProperties["android.experimental.kmp.enableAndroidResources"] = "true"
}
dependencies {
"commonMainImplementation"(libs.findLibrary("kotlinx-serialization-json").get())
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/KtlintConventionPlugin.kt
================================================
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jlleitschuh.gradle.ktlint.KtlintExtension
class KtlintConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("org.jlleitschuh.gradle.ktlint")
extensions.configure(KtlintExtension::class.java) {
version.set("1.8.0")
outputToConsole.set(true)
ignoreFailures.set(true)
filter {
exclude("**/generated/**")
exclude("**/build/**")
exclude("**/*.g.kt")
exclude("**/schemas/**")
}
reporters {
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.HTML)
}
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/RoomConventionPlugin.kt
================================================
import androidx.room.gradle.RoomExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import zed.rainxch.githubstore.convention.libs
class RoomConventionPlugin : Plugin {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
apply("androidx.room")
}
extensions.configure {
schemaDirectory("$projectDir/schemas")
}
dependencies {
"commonMainApi"(libs.findLibrary("androidx-room-runtime").get())
"commonMainApi"(libs.findLibrary("sqlite-bundled").get())
"kspAndroid"(libs.findLibrary("androidx-room-compiler").get())
"kspJvm"(libs.findLibrary("androidx-room-compiler").get())
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/AndroidCompose.kt
================================================
package zed.rainxch.githubstore.convention
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
fun Project.configureAndroidCompose(commonExtension: CommonExtension<*, *, *, *, *, *>) {
with(commonExtension) {
buildFeatures {
compose = true
}
dependencies {
val composeBom = libs.findLibrary("androidx-compose-bom").get()
"implementation"(platform(composeBom))
"testImplementation"(platform(composeBom))
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling-preview").get())
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling").get())
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/KotlinAndroid.kt
================================================
package zed.rainxch.githubstore.convention
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
internal fun Project.configureKotlinAndroid(commonExtension: CommonExtension<*, *, *, *, *, *>) {
with(commonExtension) {
compileSdk =
libs
.findVersion("projectCompileSdkVersion")
.get()
.toString()
.toInt()
defaultConfig.minSdk =
libs
.findVersion("projectMinSdkVersion")
.get()
.toString()
.toInt()
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}
configureKotlin()
dependencies {
"coreLibraryDesugaring" {
libs.findLibrary("android-desugarJdkLibs").get()
}
}
}
}
internal fun Project.configureKotlin() {
tasks.withType().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
freeCompilerArgs.add(
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/KotlinAndroidTarget.kt
================================================
package zed.rainxch.githubstore.convention
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
internal fun Project.configureAndroidTarget() {
extensions.configure {
androidTarget {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/KotlinJvmTarget.kt
================================================
package zed.rainxch.githubstore.convention
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.util.Properties
internal fun Project.configureJvmTarget() {
extensions.configure {
jvm()
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/KotlinMultiplatform.kt
================================================
package zed.rainxch.githubstore.convention
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
internal fun Project.configureKotlinMultiplatform() {
extensions.configure {
namespace = this@configureKotlinMultiplatform.pathToPackageName()
}
configureAndroidTarget()
configureJvmTarget()
extensions.configure {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
freeCompilerArgs.add("-Xmulti-dollar-interpolation")
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
freeCompilerArgs.add("-opt-in=kotlin.time.ExperimentalTime")
}
}
}
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/PathUtil.kt
================================================
package zed.rainxch.githubstore.convention
import org.gradle.api.Project
import java.util.Locale
fun Project.pathToPackageName(): String {
val relativePackageName =
path
.replace(":", ".")
.replace("-", "_")
.lowercase()
return "zed.rainxch$relativePackageName"
}
fun Project.pathToResourcePrefix(): String =
path
.replace(":", "_ ")
.lowercase()
.drop(1) + "_"
================================================
FILE: build-logic/convention/src/main/kotlin/zed/rainxch/githubstore/convention/ProjectExt.kt
================================================
package zed.rainxch.githubstore.convention
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
val Project.libs: VersionCatalog
get() = extensions.getByType().named("libs")
================================================
FILE: build-logic/gradle.properties
================================================
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
================================================
FILE: build-logic/settings.gradle.kts
================================================
@file:Suppress("UnstableApiUsage")
rootProject.name = "build-logic"
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
include(":convention")
================================================
FILE: build.gradle.kts
================================================
plugins {
id("io.github.jwharm.flatpak-gradle-generator") version "1.7.0"
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.compose.hot.reload) apply false
alias(libs.plugins.compose.multiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.room) apply false
}
tasks.named("flatpakGradleGenerator") {
outputFile.set(layout.buildDirectory.file("flatpak-sources.json"))
}
subprojects {
afterEvaluate {
tasks.configureEach {
when (name) {
"preBuild",
"compileKotlinJvm",
"compileKotlinAndroid",
-> {
val ktlintFormat = tasks.findByName("ktlintFormat")
if (ktlintFormat != null) dependsOn(ktlintFormat)
}
}
}
}
}
================================================
FILE: composeApp/build.gradle.kts
================================================
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
alias(libs.plugins.convention.cmp.application)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.compose.hot.reload)
}
android {
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.core.splashscreen)
implementation(libs.koin.android)
}
commonMain.dependencies {
implementation(projects.core.data)
implementation(projects.core.domain)
implementation(projects.core.presentation)
implementation(projects.feature.apps.domain)
implementation(projects.feature.apps.data)
implementation(projects.feature.apps.presentation)
implementation(projects.feature.auth.domain)
implementation(projects.feature.auth.data)
implementation(projects.feature.auth.presentation)
implementation(projects.feature.details.domain)
implementation(projects.feature.details.data)
implementation(projects.feature.details.presentation)
implementation(projects.feature.devProfile.domain)
implementation(projects.feature.devProfile.data)
implementation(projects.feature.devProfile.presentation)
implementation(projects.feature.favourites.domain)
implementation(projects.feature.favourites.data)
implementation(projects.feature.favourites.presentation)
implementation(projects.feature.home.domain)
implementation(projects.feature.home.data)
implementation(projects.feature.home.presentation)
implementation(projects.feature.search.domain)
implementation(projects.feature.search.data)
implementation(projects.feature.search.presentation)
implementation(projects.feature.profile.domain)
implementation(projects.feature.profile.data)
implementation(projects.feature.profile.presentation)
implementation(projects.feature.starred.domain)
implementation(projects.feature.starred.data)
implementation(projects.feature.starred.presentation)
implementation(libs.jetbrains.compose.navigation)
implementation(libs.bundles.koin.common)
implementation(libs.liquid)
implementation(libs.jetbrains.compose.material.icons.extended)
implementation(libs.touchlab.kermit)
implementation(libs.kotlinx.collections.immutable)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(libs.jetbrains.compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.jetbrains.compose.viewmodel)
implementation(libs.jetbrains.lifecycle.compose)
}
jvmMain {
dependencies {
implementation(projects.core.presentation)
implementation(compose.desktop.currentOs)
implementation(libs.kotlinx.coroutines.swing)
implementation(libs.kotlin.stdlib)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.koin.compose.viewmodel)
implementation(compose.desktop.linux_x64)
implementation(compose.desktop.linux_arm64)
implementation(compose.desktop.macos_x64)
implementation(compose.desktop.macos_arm64)
implementation(compose.desktop.windows_x64)
implementation(compose.desktop.windows_arm64)
implementation(libs.slf4j.simple)
}
}
}
}
compose.desktop {
application {
mainClass = "zed.rainxch.githubstore.DesktopAppKt"
nativeDistributions {
packageName = "GitHub-Store"
packageVersion =
libs.versions.projectVersionName
.get()
.toString()
vendor = "rainxchzed"
includeAllModules = true
val currentOs =
org.gradle.internal.os.OperatingSystem
.current()
targetFormats(
*when {
currentOs.isWindows -> arrayOf(TargetFormat.Exe, TargetFormat.Msi)
currentOs.isMacOsX -> arrayOf(TargetFormat.Dmg, TargetFormat.Pkg)
currentOs.isLinux -> arrayOf(TargetFormat.Deb, TargetFormat.Rpm, TargetFormat.AppImage)
else -> emptyArray()
},
)
windows {
iconFile.set(project.file("src/jvmMain/resources/logo/app_icon.ico"))
menuGroup = "Github Store"
shortcut = true
perUserInstall = true
}
macOS {
iconFile.set(project.file("src/jvmMain/resources/logo/app_icon.icns"))
bundleID = "zed.rainxch.githubstore"
infoPlist {
extraKeysRawXml =
"""
CFBundleURLTypes
CFBundleURLName
GitHub Store Deep Link
CFBundleURLSchemes
githubstore
""".trimIndent()
}
}
linux {
iconFile.set(project.file("src/jvmMain/resources/logo/app_icon.png"))
appRelease =
libs.versions.projectVersionName
.get()
.toString()
debPackageVersion =
libs.versions.projectVersionName
.get()
.toString()
menuGroup = "Development"
appCategory = "Development"
}
}
}
}
================================================
FILE: composeApp/proguard-rules.pro
================================================
# ============================================================================
# ProGuard / R8 Rules for GitHub Store (KMP + Compose Multiplatform)
# ============================================================================
# Used with: proguard-android-optimize.txt (enables optimization passes)
# ============================================================================
# ── General Attributes ──────────────────────────────────────────────────────
-keepattributes Signature
-keepattributes *Annotation*
-keepattributes InnerClasses,EnclosingMethod
-keepattributes SourceFile,LineNumberTable
-keepattributes Exceptions
# ── Kotlin Core ─────────────────────────────────────────────────────────────
# Keep Kotlin metadata for reflection used by serialization & Koin
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.jvm.internal.** { *; }
-dontwarn kotlin.**
-dontwarn kotlinx.**
# ── Kotlin Coroutines ──────────────────────────────────────────────────────
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepclassmembernames class kotlinx.** { volatile ; }
-dontwarn kotlinx.coroutines.**
# ── Kotlinx Serialization ──────────────────────────────────────────────────
# Serialization engine internals
-keep class kotlinx.serialization.** { *; }
-keepclassmembers class kotlinx.serialization.json.** { *** Companion; }
-dontnote kotlinx.serialization.**
# Generated serializers for ALL @Serializable classes
-keep class **$$serializer { *; }
-keepclassmembers @kotlinx.serialization.Serializable class ** {
*** Companion;
*** INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}
# App @Serializable classes (DTOs, models, navigation routes) across all packages
-keep @kotlinx.serialization.Serializable class zed.rainxch.** { *; }
-keep,includedescriptorclasses class zed.rainxch.**$$serializer { *; }
-keepclassmembers @kotlinx.serialization.Serializable class zed.rainxch.** {
*** Companion;
}
# ── Navigation Routes ──────────────────────────────────────────────────────
# Type-safe navigation requires these classes to survive R8
-keep class zed.rainxch.githubstore.app.navigation.GithubStoreGraph { *; }
-keep class zed.rainxch.githubstore.app.navigation.GithubStoreGraph$* { *; }
# ── Network DTOs – Core Module ─────────────────────────────────────────────
-keep class zed.rainxch.core.data.dto.** { *; }
# ── Network DTOs – Feature Modules ─────────────────────────────────────────
-keep class zed.rainxch.search.data.dto.** { *; }
-keep class zed.rainxch.devprofile.data.dto.** { *; }
-keep class zed.rainxch.home.data.dto.** { *; }
# ── Domain Models ──────────────────────────────────────────────────────────
-keep class zed.rainxch.core.domain.model.GithubRepoSummary { *; }
-keep class zed.rainxch.core.domain.model.GithubUser { *; }
# Keep enums used by Room TypeConverters and serialization
-keep class zed.rainxch.core.domain.model.InstallSource { *; }
-keep class zed.rainxch.core.domain.model.AppTheme { *; }
-keep class zed.rainxch.core.domain.model.FontTheme { *; }
-keep class zed.rainxch.core.domain.model.Platform { *; }
-keep class zed.rainxch.core.domain.model.SystemArchitecture { *; }
-keep class zed.rainxch.core.domain.model.PackageChangeType { *; }
# ── Room Database ──────────────────────────────────────────────────────────
# Database class and generated implementation
-keep class zed.rainxch.core.data.local.db.AppDatabase { *; }
-keep class zed.rainxch.core.data.local.db.AppDatabase_Impl { *; }
# Entities
-keep class zed.rainxch.core.data.local.db.entities.** { *; }
# DAOs
-keep interface zed.rainxch.core.data.local.db.dao.** { *; }
-keep class zed.rainxch.core.data.local.db.dao.** { *; }
# Room runtime
-keep class androidx.room.** { *; }
-dontwarn androidx.room.**
# ── Ktor ───────────────────────────────────────────────────────────────────
# Engine discovery, plugin system, and content negotiation use reflection
-keep class io.ktor.client.engine.** { *; }
-keep class io.ktor.client.plugins.** { *; }
-keep class io.ktor.serialization.** { *; }
-keep class io.ktor.utils.io.** { *; }
-keep class io.ktor.http.** { *; }
-keepnames class io.ktor.** { *; }
-dontwarn io.ktor.**
-dontwarn java.lang.management.**
# ── OkHttp (Ktor engine) ──────────────────────────────────────────────────
-keep class okhttp3.internal.platform.** { *; }
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn okhttp3.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
# ── Okio ───────────────────────────────────────────────────────────────────
-dontwarn okio.**
# ── SSL/TLS ────────────────────────────────────────────────────────────────
-keep class org.conscrypt.** { *; }
-dontwarn org.conscrypt.**
# ── Koin DI ────────────────────────────────────────────────────────────────
# Koin uses reflection for constructor injection
-keep class org.koin.** { *; }
-keep interface org.koin.** { *; }
-dontwarn org.koin.**
# Keep ViewModels so Koin can instantiate them
-keep class zed.rainxch.**.presentation.**ViewModel { *; }
-keep class zed.rainxch.**.presentation.**ViewModel$* { *; }
# ── Compose / AndroidX ────────────────────────────────────────────────────
# Compose runtime and navigation (most rules come bundled with the library)
-dontwarn androidx.compose.**
-dontwarn androidx.lifecycle.**
# ── DataStore ──────────────────────────────────────────────────────────────
-keep class androidx.datastore.** { *; }
-keepclassmembers class androidx.datastore.preferences.** { *; }
-dontwarn androidx.datastore.**
# ── Landscapist / Coil3 (Image Loading) ────────────────────────────────────
-keep class com.skydoves.landscapist.** { *; }
-keep interface com.skydoves.landscapist.** { *; }
-keep class coil3.** { *; }
-dontwarn coil3.**
-dontwarn com.skydoves.landscapist.**
# ── Multiplatform Markdown Renderer ────────────────────────────────────────
-keep class com.mikepenz.markdown.** { *; }
-keep class org.intellij.markdown.** { *; }
-dontwarn com.mikepenz.markdown.**
-dontwarn org.intellij.markdown.**
# ── Kermit Logging ─────────────────────────────────────────────────────────
-keep class co.touchlab.kermit.** { *; }
-dontwarn co.touchlab.kermit.**
# ── MOKO Permissions ──────────────────────────────────────────────────────
-keep class dev.icerock.moko.permissions.** { *; }
-dontwarn dev.icerock.moko.**
# ── BuildKonfig (Generated Build Constants) ────────────────────────────────
-keep class zed.rainxch.githubstore.BuildConfig { *; }
-keep class zed.rainxch.**.BuildKonfig { *; }
-keep class **.BuildKonfig { *; }
# ── AndroidX Security / Crypto ─────────────────────────────────────────────
-keep class androidx.security.crypto.** { *; }
-keep class com.google.crypto.tink.** { *; }
-dontwarn com.google.crypto.tink.**
-dontwarn com.google.errorprone.annotations.**
# ── Firebase (if integrated) ──────────────────────────────────────────────
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
# ── Enum safety ────────────────────────────────────────────────────────────
# Keep all enum values and valueOf methods (used by serialization/Room)
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# ── Parcelable ─────────────────────────────────────────────────────────────
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
# ── Java Serializable Compatibility ───────────────────────────────────────
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient ;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# ── Suppress Warnings for Missing Classes ──────────────────────────────────
-dontwarn java.lang.invoke.StringConcatFactory
-dontwarn javax.annotation.**
-dontwarn org.slf4j.**
-dontwarn org.codehaus.mojo.animal_sniffer.**
================================================
FILE: composeApp/src/androidMain/AndroidManifest.xml
================================================
================================================
FILE: composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt
================================================
package zed.rainxch.githubstore
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.util.Consumer
import org.koin.android.ext.android.inject
import zed.rainxch.core.data.utils.AndroidShareManager
import zed.rainxch.core.domain.utils.ShareManager
import zed.rainxch.githubstore.app.deeplink.DeepLinkParser
class MainActivity : ComponentActivity() {
private var deepLinkUri by mutableStateOf(null)
private val shareManager: ShareManager by inject()
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
// Register activity result launcher for file picker (must be before STARTED)
(shareManager as? AndroidShareManager)?.registerActivityResultLauncher(this)
super.onCreate(savedInstanceState)
handleIncomingIntent(intent)
setContent {
DisposableEffect(Unit) {
val listener =
Consumer { newIntent ->
handleIncomingIntent(newIntent)
}
addOnNewIntentListener(listener)
onDispose {
removeOnNewIntentListener(listener)
}
}
App(deepLinkUri = deepLinkUri)
}
}
private fun handleIncomingIntent(intent: Intent?) {
if (intent == null) return
val uriString =
when (intent.action) {
Intent.ACTION_VIEW -> {
intent.data?.toString()
}
Intent.ACTION_SEND -> {
val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT)
sharedText?.let { DeepLinkParser.extractSupportedUrl(it) }
}
else -> {
null
}
}
uriString?.let { deepLinkUri = it }
}
}
@Preview
@Composable
fun AppAndroidPreview() {
App()
}
================================================
FILE: composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/app/GithubStoreApp.kt
================================================
package zed.rainxch.githubstore.app
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Build
import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import zed.rainxch.core.data.services.PackageEventReceiver
import zed.rainxch.core.data.services.UpdateScheduler
import zed.rainxch.core.domain.model.InstallSource
import zed.rainxch.core.domain.model.InstalledApp
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.PackageMonitor
import zed.rainxch.githubstore.app.di.initKoin
class GithubStoreApp : Application() {
private var packageEventReceiver: PackageEventReceiver? = null
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
override fun onCreate() {
super.onCreate()
initKoin {
androidContext(this@GithubStoreApp)
}
createNotificationChannels()
registerPackageEventReceiver()
scheduleBackgroundUpdateChecks()
registerSelfAsInstalledApp()
}
private fun createNotificationChannels() {
val notificationManager = getSystemService(NotificationManager::class.java)
val updatesChannel =
NotificationChannel(
UPDATES_CHANNEL_ID,
"App Updates",
NotificationManager.IMPORTANCE_HIGH,
).apply {
description = "Notifications when app updates are available"
}
notificationManager.createNotificationChannel(updatesChannel)
val serviceChannel =
NotificationChannel(
UPDATE_SERVICE_CHANNEL_ID,
"Update Service",
NotificationManager.IMPORTANCE_LOW,
).apply {
description = "Background update check and auto-update progress"
setShowBadge(false)
}
notificationManager.createNotificationChannel(serviceChannel)
}
private fun registerPackageEventReceiver() {
val receiver =
PackageEventReceiver(
installedAppsRepository = get(),
packageMonitor = get(),
)
val filter = PackageEventReceiver.createIntentFilter()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(receiver, filter, RECEIVER_NOT_EXPORTED)
} else {
registerReceiver(receiver, filter)
}
packageEventReceiver = receiver
}
private fun scheduleBackgroundUpdateChecks() {
appScope.launch {
try {
val intervalHours = get().getUpdateCheckInterval().first()
UpdateScheduler.schedule(
context = this@GithubStoreApp,
intervalHours = intervalHours,
)
} catch (e: Exception) {
Logger.e(e) { "Failed to schedule background update checks" }
}
}
}
private fun registerSelfAsInstalledApp() {
appScope.launch {
try {
val repo = get()
val selfPackageName = packageName
val existing = repo.getAppByPackage(selfPackageName)
if (existing != null) return@launch
val packageMonitor = get()
val systemInfo = packageMonitor.getInstalledPackageInfo(selfPackageName)
if (systemInfo == null) {
Logger.w { "GithubStoreApp: Skip self-registration, package info missing for $selfPackageName" }
return@launch
}
val now = System.currentTimeMillis()
val versionName = systemInfo.versionName
val versionCode = systemInfo.versionCode
val selfApp =
InstalledApp(
packageName = selfPackageName,
repoId = SELF_REPO_ID,
repoName = SELF_REPO_NAME,
repoOwner = SELF_REPO_OWNER,
repoOwnerAvatarUrl = SELF_AVATAR_URL,
repoDescription = "A cross-platform app store for GitHub releases",
primaryLanguage = "Kotlin",
repoUrl = "https://github.com/$SELF_REPO_OWNER/$SELF_REPO_NAME",
installedVersion = versionName,
installedAssetName = null,
installedAssetUrl = null,
latestVersion = null,
latestAssetName = null,
latestAssetUrl = null,
latestAssetSize = null,
appName = "GitHub Store",
installSource = InstallSource.THIS_APP,
installedAt = now,
lastCheckedAt = 0L,
lastUpdatedAt = now,
isUpdateAvailable = false,
updateCheckEnabled = true,
releaseNotes = null,
systemArchitecture = "",
fileExtension = "apk",
isPendingInstall = false,
installedVersionName = versionName,
installedVersionCode = versionCode,
signingFingerprint = SELF_SHA256_FINGERPRINT,
)
repo.saveInstalledApp(selfApp)
Logger.i("GitHub Store App: App added")
} catch (e: Exception) {
Logger.e(e) { "GitHub Store App: Failed to register self as installed app" }
}
}
}
companion object {
private const val SELF_REPO_ID = 1101281251L
private const val SELF_SHA256_FINGERPRINT =
@Suppress("ktlint:standard:max-line-length")
"B7:F2:8E:19:8E:48:C1:93:B0:38:C6:5D:92:DD:F7:BC:07:7B:0D:B5:9E:BC:9B:25:0A:6D:AC:48:C1:18:03:CA"
private const val SELF_REPO_OWNER = "OpenHub-Store"
private const val SELF_REPO_NAME = "GitHub-Store"
private const val SELF_AVATAR_URL =
@Suppress("ktlint:standard:max-line-length")
"https://raw.githubusercontent.com/OpenHub-Store/GitHub-Store/refs/heads/main/media-resources/app_icon.png"
const val UPDATES_CHANNEL_ID = "app_updates"
const val UPDATE_SERVICE_CHANNEL_ID = "update_service"
}
}
================================================
FILE: composeApp/src/androidMain/res/drawable/ic_launcher_monochrome.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/drawable/ic_splash.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/values/colors.xml
================================================
#101010
================================================
FILE: composeApp/src/androidMain/res/values/splash.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/values/strings.xml
================================================
GitHub Store
================================================
FILE: composeApp/src/androidMain/res/xml/filepaths.xml
================================================
================================================
FILE: composeApp/src/androidMain/res/xml/network_security_config.xml
================================================
github.com
api.github.com
================================================
FILE: composeApp/src/commonMain/composeResources/drawable/ic_github.xml
================================================
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/Main.kt
================================================
package zed.rainxch.githubstore
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.koin.compose.viewmodel.koinViewModel
import zed.rainxch.core.presentation.theme.GithubStoreTheme
import zed.rainxch.core.presentation.utils.ApplyAndroidSystemBars
import zed.rainxch.core.presentation.utils.ObserveAsEvents
import zed.rainxch.githubstore.app.components.RateLimitDialog
import zed.rainxch.githubstore.app.components.SessionExpiredDialog
import zed.rainxch.githubstore.app.deeplink.DeepLinkDestination
import zed.rainxch.githubstore.app.deeplink.DeepLinkParser
import zed.rainxch.githubstore.app.desktop.KeyboardNavigation
import zed.rainxch.githubstore.app.desktop.KeyboardNavigationEvent
import zed.rainxch.githubstore.app.navigation.AppNavigation
import zed.rainxch.githubstore.app.navigation.GithubStoreGraph
import zed.rainxch.githubstore.app.navigation.getCurrentScreen
@Composable
fun App(deepLinkUri: String? = null) {
val viewModel: MainViewModel = koinViewModel()
val state by viewModel.state.collectAsStateWithLifecycle()
val navController = rememberNavController()
val currentScreen = navController.currentBackStackEntryAsState().value.getCurrentScreen()
LaunchedEffect(deepLinkUri) {
deepLinkUri?.let { uri ->
when (val destination = DeepLinkParser.parse(uri)) {
is DeepLinkDestination.Repository -> {
navController.navigate(
GithubStoreGraph.DetailsScreen(
owner = destination.owner,
repo = destination.repo,
),
)
}
DeepLinkDestination.None -> {
// ignore unrecognized deep links
}
}
}
}
ObserveAsEvents(KeyboardNavigation.events) { event ->
when (event) {
KeyboardNavigationEvent.OnCtrlFClick -> {
if (currentScreen !is GithubStoreGraph.SearchScreen) {
navController.navigate(GithubStoreGraph.SearchScreen) {
popUpTo(GithubStoreGraph.HomeScreen) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
}
}
}
GithubStoreTheme(
fontTheme = state.currentFontTheme,
appTheme = state.currentColorTheme,
isAmoledTheme = state.isAmoledTheme,
isDarkTheme = state.isDarkTheme ?: isSystemInDarkTheme(),
) {
ApplyAndroidSystemBars(state.isDarkTheme)
if (state.showRateLimitDialog && state.rateLimitInfo != null) {
RateLimitDialog(
rateLimitInfo = state.rateLimitInfo!!,
isAuthenticated = state.isLoggedIn,
onDismiss = {
viewModel.onAction(MainAction.DismissRateLimitDialog)
},
onSignIn = {
viewModel.onAction(MainAction.DismissRateLimitDialog)
navController.navigate(GithubStoreGraph.AuthenticationScreen)
},
)
}
if (state.showSessionExpiredDialog) {
SessionExpiredDialog(
onDismiss = {
viewModel.onAction(MainAction.DismissSessionExpiredDialog)
},
onSignIn = {
viewModel.onAction(MainAction.DismissSessionExpiredDialog)
navController.navigate(GithubStoreGraph.AuthenticationScreen)
},
)
}
AppNavigation(
navController = navController,
isLiquidGlassEnabled = state.isLiquidGlassEnabled,
)
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainAction.kt
================================================
package zed.rainxch.githubstore
sealed interface MainAction {
data object DismissRateLimitDialog : MainAction
data object DismissSessionExpiredDialog : MainAction
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainState.kt
================================================
package zed.rainxch.githubstore
import zed.rainxch.core.domain.model.AppTheme
import zed.rainxch.core.domain.model.FontTheme
import zed.rainxch.core.domain.model.RateLimitInfo
data class MainState(
val isLoggedIn: Boolean = false,
val rateLimitInfo: RateLimitInfo? = null,
val showRateLimitDialog: Boolean = false,
val showSessionExpiredDialog: Boolean = false,
val currentColorTheme: AppTheme = AppTheme.OCEAN,
val isAmoledTheme: Boolean = false,
val isDarkTheme: Boolean? = null,
val currentFontTheme: FontTheme = FontTheme.CUSTOM,
val isLiquidGlassEnabled: Boolean = true,
)
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainViewModel.kt
================================================
package zed.rainxch.githubstore
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import zed.rainxch.core.domain.repository.AuthenticationState
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.RateLimitRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.use_cases.SyncInstalledAppsUseCase
class MainViewModel(
private val tweaksRepository: TweaksRepository,
private val installedAppsRepository: InstalledAppsRepository,
private val authenticationState: AuthenticationState,
private val rateLimitRepository: RateLimitRepository,
private val syncUseCase: SyncInstalledAppsUseCase,
) : ViewModel() {
private val _state = MutableStateFlow(MainState())
val state = _state.asStateFlow()
init {
viewModelScope.launch(Dispatchers.IO) {
authenticationState
.isUserLoggedIn()
.collect { isLoggedIn ->
_state.update { it.copy(isLoggedIn = isLoggedIn) }
if (isLoggedIn) {
rateLimitRepository.clear()
}
}
}
viewModelScope.launch {
tweaksRepository
.getThemeColor()
.collect { theme ->
_state.update {
it.copy(currentColorTheme = theme)
}
}
}
viewModelScope.launch {
tweaksRepository
.getAmoledTheme()
.collect { isAmoled ->
_state.update {
it.copy(isAmoledTheme = isAmoled)
}
}
}
viewModelScope.launch {
tweaksRepository
.getIsDarkTheme()
.collect { isDarkTheme ->
_state.update {
it.copy(isDarkTheme = isDarkTheme)
}
}
}
viewModelScope.launch {
tweaksRepository
.getFontTheme()
.collect { fontTheme ->
_state.update {
it.copy(currentFontTheme = fontTheme)
}
}
}
viewModelScope.launch {
tweaksRepository.getLiquidGlassEnabled().collect { enabled ->
_state.update { it.copy(isLiquidGlassEnabled = enabled) }
}
}
viewModelScope.launch {
rateLimitRepository.rateLimitState.collect { rateLimitInfo ->
_state.update { currentState ->
currentState.copy(rateLimitInfo = rateLimitInfo)
}
}
}
viewModelScope.launch {
rateLimitRepository.rateLimitExhaustedEvent.collect { info ->
_state.update { it.copy(showRateLimitDialog = true, rateLimitInfo = info) }
}
}
viewModelScope.launch {
authenticationState.sessionExpiredEvent.collect {
_state.update { it.copy(showSessionExpiredDialog = true) }
}
}
viewModelScope.launch(Dispatchers.IO) {
syncUseCase().onSuccess {
installedAppsRepository.checkAllForUpdates()
}
}
}
fun onAction(action: MainAction) {
when (action) {
MainAction.DismissRateLimitDialog -> {
_state.update { it.copy(showRateLimitDialog = false) }
}
MainAction.DismissSessionExpiredDialog -> {
_state.update { it.copy(showSessionExpiredDialog = false) }
}
}
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/components/RateLimitDialog.kt
================================================
package zed.rainxch.githubstore.app.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.core.domain.model.RateLimitInfo
import zed.rainxch.core.presentation.theme.GithubStoreTheme
import zed.rainxch.githubstore.core.presentation.res.Res
import zed.rainxch.githubstore.core.presentation.res.rate_limit_close
import zed.rainxch.githubstore.core.presentation.res.rate_limit_exceeded
import zed.rainxch.githubstore.core.presentation.res.rate_limit_ok
import zed.rainxch.githubstore.core.presentation.res.rate_limit_resets_in_minutes
import zed.rainxch.githubstore.core.presentation.res.rate_limit_sign_in
import zed.rainxch.githubstore.core.presentation.res.rate_limit_tip_sign_in
import zed.rainxch.githubstore.core.presentation.res.rate_limit_used_all
import zed.rainxch.githubstore.core.presentation.res.rate_limit_used_all_free
@Composable
fun RateLimitDialog(
rateLimitInfo: RateLimitInfo,
isAuthenticated: Boolean,
onDismiss: () -> Unit,
onSignIn: () -> Unit,
) {
val timeUntilReset =
remember(rateLimitInfo) {
rateLimitInfo.timeUntilReset().inWholeMinutes.toInt()
}
AlertDialog(
onDismissRequest = onDismiss,
icon = {
Icon(
imageVector = Icons.Default.Warning,
contentDescription = null,
tint = MaterialTheme.colorScheme.error,
)
},
title = {
Text(
text = stringResource(Res.string.rate_limit_exceeded),
style = MaterialTheme.typography.headlineSmall,
fontWeight = FontWeight.Black,
color = MaterialTheme.colorScheme.onSurface,
)
},
text = {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text =
if (isAuthenticated) {
stringResource(
Res.string.rate_limit_used_all,
rateLimitInfo.limit,
)
} else {
stringResource(
Res.string.rate_limit_used_all_free,
60,
)
},
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline,
)
Text(
text =
stringResource(
Res.string.rate_limit_resets_in_minutes,
timeUntilReset,
),
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface,
)
if (!isAuthenticated) {
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(Res.string.rate_limit_tip_sign_in),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.primary,
)
}
}
},
confirmButton = {
if (!isAuthenticated) {
Button(onClick = onSignIn) {
Text(
text = stringResource(Res.string.rate_limit_sign_in),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onPrimary,
)
}
} else {
Button(onClick = onDismiss) {
Text(
text = stringResource(Res.string.rate_limit_ok),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
)
}
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(
text = stringResource(Res.string.rate_limit_close),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
)
}
},
)
}
@Preview
@Composable
fun RateLimitDialogPreview() {
GithubStoreTheme {
RateLimitDialog(
rateLimitInfo =
RateLimitInfo(
limit = 1000,
remaining = 2000,
resetTimestamp = 0L,
),
isAuthenticated = false,
onDismiss = {
},
onSignIn = {
},
)
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/components/SessionExpiredDialog.kt
================================================
package zed.rainxch.githubstore.app.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LockOpen
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.githubstore.core.presentation.res.*
@Composable
fun SessionExpiredDialog(
onDismiss: () -> Unit,
onSignIn: () -> Unit,
) {
AlertDialog(
onDismissRequest = onDismiss,
icon = {
Icon(
imageVector = Icons.Default.LockOpen,
contentDescription = null,
tint = MaterialTheme.colorScheme.error,
)
},
title = {
Text(
text = stringResource(Res.string.session_expired_title),
style = MaterialTheme.typography.headlineSmall,
fontWeight = FontWeight.Black,
color = MaterialTheme.colorScheme.onSurface,
)
},
text = {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = stringResource(Res.string.session_expired_message),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline,
)
Text(
text = stringResource(Res.string.session_expired_hint),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.primary,
)
}
},
confirmButton = {
Button(onClick = onSignIn) {
Text(
text = stringResource(Res.string.sign_in_again),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onPrimary,
)
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(
text = stringResource(Res.string.continue_as_guest),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
)
}
},
)
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/deeplink/DeepLinkParser.kt
================================================
package zed.rainxch.githubstore.app.deeplink
sealed interface DeepLinkDestination {
data class Repository(
val owner: String,
val repo: String,
) : DeepLinkDestination
data object None : DeepLinkDestination
}
object DeepLinkParser {
private val INVALID_CHARS = setOf('/', '\\', '?', '#', '@', ':', '*', '"', '<', '>', '|', '%', '&', '=')
private val FORBIDDEN_PATTERNS = listOf("..", "~", "\u0000")
private val EXCLUDED_PATHS =
setOf(
"about",
"account",
"admin",
"api",
"apps",
"articles",
"blog",
"business",
"collections",
"contact",
"dashboard",
"enterprises",
"events",
"explore",
"features",
"home",
"issues",
"marketplace",
"new",
"notifications",
"orgs",
"pricing",
"pulls",
"search",
"security",
"settings",
"showcases",
"site",
"sponsors",
"topics",
"trending",
"team",
)
fun parse(uri: String): DeepLinkDestination {
return when {
uri.startsWith("githubstore://repo/") -> {
val path = uri.removePrefix("githubstore://repo/")
val decoded = urlDecode(path)
parseOwnerRepo(decoded)
}
uri.startsWith("https://github.com/") -> {
val path =
uri
.removePrefix("https://github.com/")
.substringBefore('?')
.substringBefore('#')
val decoded = urlDecode(path)
val parts = decoded.split("/").filter { it.isNotEmpty() }
if (parts.size >= 2) {
val owner = parts[0]
val repo = parts[1]
if (isStrictlyValidOwnerRepo(owner, repo)) {
return DeepLinkDestination.Repository(owner, repo)
}
}
DeepLinkDestination.None
}
uri.startsWith("https://github-store.org/app/") -> {
extractQueryParam(uri, "repo")?.let { encodedRepoParam ->
val decoded = urlDecode(encodedRepoParam)
parseOwnerRepo(decoded)
} ?: DeepLinkDestination.None
}
else -> {
DeepLinkDestination.None
}
}
}
/**
* URL-decode a string, handling percent-encoded characters.
* Returns the original string if decoding fails.
*/
private fun urlDecode(value: String): String =
try {
val result = StringBuilder()
var i = 0
while (i < value.length) {
when (val c = value[i]) {
'%' -> {
if (i + 2 < value.length) {
val hex = value.substring(i + 1, i + 3)
val code = hex.toIntOrNull(16)
if (code != null) {
result.append(code.toChar())
i += 3
continue
}
}
result.append(c)
i++
}
'+' -> {
result.append(' ')
i++
}
else -> {
result.append(c)
i++
}
}
}
result.toString()
} catch (_: Exception) {
value
}
private fun parseOwnerRepo(path: String): DeepLinkDestination {
val parts = path.split("/").filter { it.isNotEmpty() }
return if (parts.size >= 2) {
val owner = parts[0]
val repo = parts[1]
if (isStrictlyValidOwnerRepo(owner, repo)) {
DeepLinkDestination.Repository(owner, repo)
} else {
DeepLinkDestination.None
}
} else {
DeepLinkDestination.None
}
}
/**
* Strictly validate owner and repo names to prevent injection attacks.
* Rejects:
* - Empty strings
* - Special characters that could be used for injection
* - Path traversal patterns
* - Control characters and whitespace
* - Excluded GitHub paths (like 'about', 'settings', etc.)
* - Names that exceed GitHub's length limits
* - Names that don't start with alphanumeric characters
*/
private fun isStrictlyValidOwnerRepo(
owner: String,
repo: String,
): Boolean {
if (owner.isEmpty() || repo.isEmpty()) {
return false
}
if (owner.any { it in INVALID_CHARS } || repo.any { it in INVALID_CHARS }) {
return false
}
if (FORBIDDEN_PATTERNS.any { pattern ->
owner.contains(pattern, ignoreCase = true) ||
repo.contains(pattern, ignoreCase = true)
}
) {
return false
}
if (owner.any { it.isISOControl() } || repo.any { it.isISOControl() }) {
return false
}
if (owner.contains(' ') || repo.contains(' ')) {
return false
}
if (EXCLUDED_PATHS.contains(owner.lowercase())) {
return false
}
if (owner.length > 39 || repo.length > 100) {
return false
}
if (!owner.first().isLetterOrDigit() || !repo.first().isLetterOrDigit()) {
return false
}
return true
}
private fun extractQueryParam(
uri: String,
key: String,
): String? {
val queryStart = uri.indexOf('?')
if (queryStart == -1) return null
val queryString = uri.substring(queryStart + 1)
val params = queryString.split('&')
for (param in params) {
val keyValue = param.split('=', limit = 2)
if (keyValue.size == 2 && keyValue[0] == key) {
return keyValue[1]
}
}
return null
}
fun extractSupportedUrl(text: String): String? {
val regex =
"""https?://(?:www\.)?(?:github\.com|github-store\.org)(?=[/\s?#]|$)[^\s<>"')\],;.!]*""".toRegex(
RegexOption.IGNORE_CASE,
)
return regex.find(text)?.value
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/desktop/KeyboardNavigation.kt
================================================
package zed.rainxch.githubstore.app.desktop
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
object KeyboardNavigation {
private val _events = Channel()
val events = _events.receiveAsFlow()
fun onKeyClicked(event: KeyboardNavigationEvent) {
_events.trySend(event)
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/desktop/KeyboardNavigationEvent.kt
================================================
package zed.rainxch.githubstore.app.desktop
sealed interface KeyboardNavigationEvent {
data object OnCtrlFClick : KeyboardNavigationEvent
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/di/SharedModules.kt
================================================
package zed.rainxch.githubstore.app.di
import org.koin.core.module.Module
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
import zed.rainxch.githubstore.MainViewModel
val mainModule: Module =
module {
viewModel {
MainViewModel(
tweaksRepository = get(),
installedAppsRepository = get(),
rateLimitRepository = get(),
syncUseCase = get(),
authenticationState = get(),
)
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/di/ViewModelsModule.kt
================================================
package zed.rainxch.githubstore.app.di
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module
import zed.rainxch.apps.presentation.AppsViewModel
import zed.rainxch.auth.presentation.AuthenticationViewModel
import zed.rainxch.details.presentation.DetailsViewModel
import zed.rainxch.devprofile.presentation.DeveloperProfileViewModel
import zed.rainxch.favourites.presentation.FavouritesViewModel
import zed.rainxch.home.presentation.HomeViewModel
import zed.rainxch.profile.presentation.ProfileViewModel
import zed.rainxch.search.presentation.SearchViewModel
import zed.rainxch.starred.presentation.StarredReposViewModel
val viewModelsModule =
module {
viewModelOf(::AppsViewModel)
viewModelOf(::AuthenticationViewModel)
viewModelOf(::DetailsViewModel)
viewModelOf(::DeveloperProfileViewModel)
viewModelOf(::FavouritesViewModel)
viewModelOf(::HomeViewModel)
viewModelOf(::SearchViewModel)
viewModelOf(::ProfileViewModel)
viewModelOf(::StarredReposViewModel)
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/di/initKoin.kt
================================================
package zed.rainxch.githubstore.app.di
import org.koin.core.context.startKoin
import org.koin.dsl.KoinAppDeclaration
import zed.rainxch.apps.data.di.appsModule
import zed.rainxch.auth.data.di.authModule
import zed.rainxch.core.data.di.coreModule
import zed.rainxch.core.data.di.corePlatformModule
import zed.rainxch.core.data.di.databaseModule
import zed.rainxch.core.data.di.networkModule
import zed.rainxch.details.data.di.detailsModule
import zed.rainxch.devprofile.data.di.devProfileModule
import zed.rainxch.home.data.di.homeModule
import zed.rainxch.profile.data.di.settingsModule
import zed.rainxch.search.data.di.searchModule
fun initKoin(config: KoinAppDeclaration? = null) {
startKoin {
config?.invoke(this)
modules(
mainModule,
corePlatformModule,
coreModule,
networkModule,
databaseModule,
viewModelsModule,
appsModule,
authModule,
detailsModule,
devProfileModule,
homeModule,
searchModule,
settingsModule,
)
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/AppNavigation.kt
================================================
package zed.rainxch.githubstore.app.navigation
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.toRoute
import io.github.fletchmckee.liquid.rememberLiquidState
import org.koin.compose.viewmodel.koinViewModel
import org.koin.core.parameter.parametersOf
import zed.rainxch.apps.presentation.AppsRoot
import zed.rainxch.apps.presentation.AppsViewModel
import zed.rainxch.auth.presentation.AuthenticationRoot
import zed.rainxch.core.presentation.locals.LocalBottomNavigationHeight
import zed.rainxch.core.presentation.locals.LocalBottomNavigationLiquid
import zed.rainxch.details.presentation.DetailsRoot
import zed.rainxch.devprofile.presentation.DeveloperProfileRoot
import zed.rainxch.favourites.presentation.FavouritesRoot
import zed.rainxch.home.presentation.HomeRoot
import zed.rainxch.profile.presentation.ProfileRoot
import zed.rainxch.search.presentation.SearchRoot
import zed.rainxch.starred.presentation.StarredReposRoot
@Composable
fun AppNavigation(
navController: NavHostController,
isLiquidGlassEnabled: Boolean = true,
) {
val liquidState = rememberLiquidState()
var bottomNavigationHeight by remember { mutableStateOf(0.dp) }
val density = LocalDensity.current
val appsViewModel = koinViewModel()
val appsState by appsViewModel.state.collectAsStateWithLifecycle()
CompositionLocalProvider(
LocalBottomNavigationLiquid provides liquidState,
LocalBottomNavigationHeight provides bottomNavigationHeight,
) {
Box(
modifier = Modifier.fillMaxSize(),
) {
NavHost(
navController = navController,
startDestination = GithubStoreGraph.HomeScreen,
modifier = Modifier.background(MaterialTheme.colorScheme.background),
) {
composable {
HomeRoot(
onNavigateToSearch = {
navController.navigate(GithubStoreGraph.SearchScreen)
},
onNavigateToSettings = {
navController.navigate(GithubStoreGraph.ProfileScreen)
},
onNavigateToApps = {
navController.navigate(GithubStoreGraph.AppsScreen)
},
onNavigateToDetails = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
),
)
},
onNavigateToDeveloperProfile = { username ->
navController.navigate(
GithubStoreGraph.DeveloperProfileScreen(
username = username,
),
)
},
)
}
composable {
SearchRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToDetails = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
),
)
},
onNavigateToDetailsFromLink = { owner, repo ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
owner = owner,
repo = repo,
),
)
},
onNavigateToDeveloperProfile = { username ->
navController.navigate(
GithubStoreGraph.DeveloperProfileScreen(
username = username,
),
)
},
)
}
composable { backStackEntry ->
val args = backStackEntry.toRoute()
DetailsRoot(
onNavigateBack = {
navController.navigateUp()
},
onOpenRepositoryInApp = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
),
)
},
onNavigateToDeveloperProfile = { username ->
navController.navigate(
GithubStoreGraph.DeveloperProfileScreen(
username = username,
),
)
},
viewModel =
koinViewModel {
parametersOf(
args.repositoryId,
args.owner,
args.repo,
args.isComingFromUpdate,
)
},
)
}
composable { backStackEntry ->
val args = backStackEntry.toRoute()
DeveloperProfileRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToDetails = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
),
)
},
viewModel =
koinViewModel {
parametersOf(args.username)
},
)
}
composable {
AuthenticationRoot(
onNavigateToHome = {
navController.navigate(GithubStoreGraph.HomeScreen) {
popUpTo(0) {
inclusive = true
}
}
},
)
}
composable {
FavouritesRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToDetails = {
navController.navigate(GithubStoreGraph.DetailsScreen(it))
},
onNavigateToDeveloperProfile = { username ->
navController.navigate(
GithubStoreGraph.DeveloperProfileScreen(
username = username,
),
)
},
)
}
composable {
StarredReposRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToDetails = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
),
)
},
onNavigateToAuthentication = {
navController.navigate(
GithubStoreGraph.AuthenticationScreen,
)
},
onNavigateToDeveloperProfile = { username ->
navController.navigate(
GithubStoreGraph.DeveloperProfileScreen(
username = username,
),
)
},
)
}
composable {
ProfileRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToAuthentication = {
navController.navigate(GithubStoreGraph.AuthenticationScreen)
},
onNavigateToStarredRepos = {
navController.navigate(GithubStoreGraph.StarredReposScreen)
},
onNavigateToFavouriteRepos = {
navController.navigate(GithubStoreGraph.FavouritesScreen)
},
onNavigateToDevProfile = { username ->
navController.navigate(GithubStoreGraph.DeveloperProfileScreen(username))
},
onNavigateToSponsor = {
navController.navigate(GithubStoreGraph.SponsorScreen)
},
)
}
composable {
zed.rainxch.profile.presentation.SponsorScreen(
onNavigateBack = {
navController.navigateUp()
},
)
}
composable {
AppsRoot(
onNavigateBack = {
navController.navigateUp()
},
onNavigateToRepo = { repoId ->
navController.navigate(
GithubStoreGraph.DetailsScreen(
repositoryId = repoId,
isComingFromUpdate = true,
),
)
},
viewModel = appsViewModel,
state = appsState,
)
}
}
val currentScreen =
navController.currentBackStackEntryAsState().value.getCurrentScreen()
currentScreen?.let {
BottomNavigation(
currentScreen = currentScreen,
onNavigate = {
navController.navigate(it) {
popUpTo(GithubStoreGraph.HomeScreen) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
isUpdateAvailable = appsState.apps.any { it.installedApp.isUpdateAvailable },
isLiquidGlassEnabled = isLiquidGlassEnabled,
modifier =
Modifier
.align(Alignment.BottomCenter)
.navigationBarsPadding()
.padding(bottom = 24.dp)
.onGloballyPositioned { coordinates ->
bottomNavigationHeight =
with(density) { coordinates.size.height.toDp() }
},
)
}
}
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/BottomNavigation.kt
================================================
package zed.rainxch.githubstore.app.navigation
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.github.fletchmckee.liquid.liquid
import io.github.fletchmckee.liquid.rememberLiquidState
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.core.domain.getPlatform
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.presentation.locals.LocalBottomNavigationLiquid
import zed.rainxch.core.presentation.theme.GithubStoreTheme
import zed.rainxch.core.presentation.utils.isLiquidFrostAvailable
@Composable
fun BottomNavigation(
currentScreen: GithubStoreGraph,
onNavigate: (GithubStoreGraph) -> Unit,
isUpdateAvailable: Boolean,
isLiquidGlassEnabled: Boolean = true,
modifier: Modifier = Modifier,
) {
val liquidState = LocalBottomNavigationLiquid.current
if (currentScreen !in BottomNavigationUtils.allowedScreens()) return
val visibleItems =
remember {
BottomNavigationUtils.items().filterNot {
getPlatform() != Platform.ANDROID &&
it.screen == GithubStoreGraph.AppsScreen
}
}
val selectedIndex = visibleItems.indexOfFirst { it.screen == currentScreen }
val itemPositions = remember { mutableMapOf>() }
var selectedItemPos by remember { mutableStateOf?>(null) }
val rowHorizontalPaddingDp = 6.dp
val density = LocalDensity.current
val rowHorizontalPaddingPx = with(density) { rowHorizontalPaddingDp.toPx() }
val indicatorHorizontalInsetPx = with(density) { 4.dp.toPx() }
val indicatorX = remember { Animatable(0f) }
val indicatorWidth = remember { Animatable(0f) }
LaunchedEffect(selectedIndex, selectedItemPos) {
val raw = selectedItemPos ?: itemPositions[selectedIndex] ?: return@LaunchedEffect
val targetX = raw.first + rowHorizontalPaddingPx - indicatorHorizontalInsetPx
val targetW = raw.second + indicatorHorizontalInsetPx * 2f
launch {
indicatorX.animateTo(
targetValue = targetX,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioLowBouncy,
stiffness = Spring.StiffnessLow,
),
)
}
launch {
indicatorWidth.animateTo(
targetValue = targetW,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioNoBouncy,
stiffness = Spring.StiffnessMedium,
),
)
}
}
val isDarkTheme =
!MaterialTheme.colorScheme.background
.luminance()
.let { it > 0.5f }
Box(
modifier = modifier,
contentAlignment = Alignment.Center,
) {
val useLiquid = isLiquidGlassEnabled && isLiquidFrostAvailable()
Box(
modifier =
Modifier
.clip(CircleShape)
.then(
if (useLiquid) {
Modifier
.background(
MaterialTheme.colorScheme.surfaceContainerHighest.copy(
alpha = if (isDarkTheme) .25f else .15f,
),
).liquid(liquidState) {
this.shape = CircleShape
this.frost = if (isDarkTheme) 12.dp else 10.dp
this.curve = if (isDarkTheme) .35f else .45f
this.refraction = if (isDarkTheme) .08f else .12f
this.dispersion = if (isDarkTheme) .18f else .25f
this.saturation = if (isDarkTheme) .40f else .55f
this.contrast = if (isDarkTheme) 1.8f else 1.6f
}
} else {
Modifier
.background(MaterialTheme.colorScheme.surfaceContainer)
.border(
width = 1.dp,
color = MaterialTheme.colorScheme.outlineVariant,
shape = CircleShape,
)
},
).pointerInput(Unit) { },
) {
val glassHighColor =
if (isDarkTheme) {
Color.White.copy(alpha = .12f)
} else {
Color.White.copy(alpha = .30f)
}
val glassLowColor =
if (isDarkTheme) {
Color.White.copy(alpha = .04f)
} else {
Color.White.copy(alpha = .10f)
}
val specularColor =
if (isDarkTheme) {
Color.White.copy(alpha = .18f)
} else {
Color.White.copy(alpha = .45f)
}
val innerGlowColor =
if (isDarkTheme) {
Color.White.copy(alpha = .03f)
} else {
Color.White.copy(alpha = .08f)
}
val borderColor =
if (isDarkTheme) {
Color.White.copy(alpha = .08f)
} else {
Color.Transparent
}
Box(
modifier =
Modifier
.matchParentSize()
.drawBehind {
if (indicatorWidth.value > 0f) {
if (isDarkTheme) {
drawRoundRect(
color = borderColor,
topLeft =
Offset(
indicatorX.value - .5.dp.toPx(),
1.5.dp.toPx(),
),
size =
Size(
indicatorWidth.value + 1.dp.toPx(),
size.height - 3.dp.toPx(),
),
cornerRadius = CornerRadius(size.height / 2f),
style = Stroke(width = 1.dp.toPx()),
)
}
drawRoundRect(
brush =
Brush.verticalGradient(
colors = listOf(glassHighColor, glassLowColor),
),
topLeft = Offset(indicatorX.value, 2.dp.toPx()),
size = Size(indicatorWidth.value, size.height - 4.dp.toPx()),
cornerRadius = CornerRadius(size.height / 2f),
)
drawRoundRect(
brush =
Brush.horizontalGradient(
colors =
listOf(
Color.Transparent,
specularColor,
Color.Transparent,
),
startX = indicatorX.value + indicatorWidth.value * .15f,
endX = indicatorX.value + indicatorWidth.value * .85f,
),
topLeft =
Offset(
indicatorX.value + indicatorWidth.value * .15f,
3.dp.toPx(),
),
size = Size(indicatorWidth.value * .7f, 1.5.dp.toPx()),
cornerRadius = CornerRadius(1.dp.toPx()),
)
drawRoundRect(
brush =
Brush.verticalGradient(
colors = listOf(Color.Transparent, innerGlowColor),
),
topLeft =
Offset(
indicatorX.value + 4.dp.toPx(),
size.height - 8.dp.toPx(),
),
size = Size(indicatorWidth.value - 8.dp.toPx(), 4.dp.toPx()),
cornerRadius = CornerRadius(2.dp.toPx()),
)
}
},
)
Row(
modifier = Modifier.padding(horizontal = rowHorizontalPaddingDp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
visibleItems.forEachIndexed { index, item ->
LiquidGlassTabItem(
item = item,
hasBadge = item.screen == GithubStoreGraph.AppsScreen && isUpdateAvailable,
isSelected = item.screen == currentScreen,
onSelect = { onNavigate(item.screen) },
onPositioned = { x, width ->
itemPositions[index] = x to width
if (index == selectedIndex) {
selectedItemPos = x to width
}
if (index == selectedIndex && indicatorWidth.value == 0f) {
val snapX = x + rowHorizontalPaddingPx - indicatorHorizontalInsetPx
val snapW = width + indicatorHorizontalInsetPx * 2f
indicatorX.snapTo(snapX)
indicatorWidth.snapTo(snapW)
}
},
)
}
}
}
}
}
@Composable
private fun LiquidGlassTabItem(
item: BottomNavigationItem,
isSelected: Boolean,
onSelect: () -> Unit,
hasBadge: Boolean = false,
onPositioned: suspend (x: Float, width: Float) -> Unit,
) {
val scope = rememberCoroutineScope()
val density = LocalDensity.current
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val pressScale by animateFloatAsState(
targetValue = if (isPressed) 0.85f else 1f,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMedium,
),
label = "pressScale",
)
val iconScale by animateFloatAsState(
targetValue = if (isSelected) 1.15f else 1f,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow,
),
label = "iconScale",
)
val iconOffsetY by animateDpAsState(
targetValue = if (isSelected) (-1).dp else 1.dp,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow,
),
label = "iconOffsetY",
)
val iconTint =
if (isSelected) {
MaterialTheme.colorScheme.onPrimaryContainer
} else {
MaterialTheme.colorScheme.onSurface.copy(alpha = .7f)
}
val labelAlpha by animateFloatAsState(
targetValue = if (isSelected) 1f else 0f,
animationSpec =
tween(
durationMillis = if (isSelected) 250 else 150,
easing = FastOutSlowInEasing,
),
label = "labelAlpha",
)
val labelScale by animateFloatAsState(
targetValue = if (isSelected) 1f else 0.6f,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow,
),
label = "labelScale",
)
val horizontalPadding by animateDpAsState(
targetValue = if (isSelected) 20.dp else 14.dp,
animationSpec =
spring(
dampingRatio = Spring.DampingRatioNoBouncy,
stiffness = Spring.StiffnessMediumLow,
),
label = "hPadding",
)
Box(
modifier =
Modifier
.clip(CircleShape)
.clickable(
interactionSource = interactionSource,
indication = null,
) { onSelect() }
.onGloballyPositioned { coordinates ->
val x = coordinates.positionInParent().x
val width = coordinates.size.width.toFloat()
scope.launch { onPositioned(x, width) }
}.graphicsLayer {
scaleX = pressScale
scaleY = pressScale
}.padding(horizontal = horizontalPadding, vertical = 6.dp),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(1.dp),
) {
Icon(
imageVector = if (isSelected) item.iconFilled else item.iconOutlined,
contentDescription = stringResource(item.titleRes),
modifier =
Modifier
.size(22.dp)
.graphicsLayer {
scaleX = iconScale
scaleY = iconScale
translationY = with(density) { iconOffsetY.toPx() }
},
tint = iconTint,
)
Box(
modifier =
Modifier
.height(if (isSelected) 16.dp else 0.dp)
.graphicsLayer {
alpha = labelAlpha
scaleX = labelScale
scaleY = labelScale
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(item.titleRes),
style =
MaterialTheme.typography.labelSmall.copy(
fontSize = 10.sp,
fontWeight = if (isSelected) FontWeight.SemiBold else FontWeight.Normal,
lineHeight = 12.sp,
),
color =
if (isSelected) {
MaterialTheme.colorScheme.onSurface
} else {
MaterialTheme.colorScheme.onSurface.copy(alpha = .7f)
},
maxLines = 1,
)
}
}
if (hasBadge) {
Box(
Modifier
.size(12.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.error)
.align(Alignment.TopEnd),
)
}
}
}
@Preview
@Composable
fun BottomNavigationPreview() {
GithubStoreTheme {
CompositionLocalProvider(
LocalBottomNavigationLiquid provides rememberLiquidState(),
) {
BottomNavigation(
currentScreen = GithubStoreGraph.HomeScreen,
onNavigate = {
},
isUpdateAvailable = true,
)
}
}
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/BottomNavigationUtils.kt
================================================
package zed.rainxch.githubstore.app.navigation
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Apps
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person2
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.outlined.Apps
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Person2
import androidx.compose.material.icons.outlined.Search
import androidx.compose.ui.graphics.vector.ImageVector
import org.jetbrains.compose.resources.StringResource
import zed.rainxch.core.domain.getPlatform
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.githubstore.core.presentation.res.*
data class BottomNavigationItem(
val titleRes: StringResource,
val iconOutlined: ImageVector,
val iconFilled: ImageVector,
val screen: GithubStoreGraph,
)
object BottomNavigationUtils {
fun items(): List =
listOf(
BottomNavigationItem(
titleRes = Res.string.bottom_nav_home_title,
iconOutlined = Icons.Outlined.Home,
iconFilled = Icons.Filled.Home,
screen = GithubStoreGraph.HomeScreen,
),
BottomNavigationItem(
titleRes = Res.string.bottom_nav_search_title,
iconOutlined = Icons.Outlined.Search,
iconFilled = Icons.Filled.Search,
screen = GithubStoreGraph.SearchScreen,
),
BottomNavigationItem(
titleRes = Res.string.bottom_nav_apps_title,
iconOutlined = Icons.Outlined.Apps,
iconFilled = Icons.Filled.Apps,
screen = GithubStoreGraph.AppsScreen,
),
BottomNavigationItem(
titleRes = Res.string.bottom_nav_profile_title,
iconOutlined = Icons.Outlined.Person2,
iconFilled = Icons.Filled.Person2,
screen = GithubStoreGraph.ProfileScreen,
),
)
fun allowedScreens(): List =
items()
.filterNot {
getPlatform() != Platform.ANDROID &&
it.screen == GithubStoreGraph.AppsScreen
}.map { it.screen }
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/GithubStoreGraph.kt
================================================
package zed.rainxch.githubstore.app.navigation
import kotlinx.serialization.Serializable
@Serializable
sealed interface GithubStoreGraph {
@Serializable
data object HomeScreen : GithubStoreGraph
@Serializable
data object SearchScreen : GithubStoreGraph
@Serializable
data object AuthenticationScreen : GithubStoreGraph
@Serializable
data class DetailsScreen(
val repositoryId: Long = -1L,
val owner: String = "",
val repo: String = "",
val isComingFromUpdate: Boolean = false,
) : GithubStoreGraph
@Serializable
data class DeveloperProfileScreen(
val username: String,
) : GithubStoreGraph
@Serializable
data object ProfileScreen : GithubStoreGraph
@Serializable
data object FavouritesScreen : GithubStoreGraph
@Serializable
data object StarredReposScreen : GithubStoreGraph
@Serializable
data object AppsScreen : GithubStoreGraph
@Serializable
data object SponsorScreen : GithubStoreGraph
}
================================================
FILE: composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/NavigationUtils.kt
================================================
package zed.rainxch.githubstore.app.navigation
import androidx.navigation.NavBackStackEntry
import androidx.navigation.toRoute
fun NavBackStackEntry?.getCurrentScreen(): GithubStoreGraph? {
if (this == null) return null
val route = destination.route ?: return null
return when {
route.contains("HomeScreen") -> GithubStoreGraph.HomeScreen
route.contains("SearchScreen") -> GithubStoreGraph.SearchScreen
route.contains("AuthenticationScreen") -> GithubStoreGraph.AuthenticationScreen
route.contains("DetailsScreen") -> toRoute()
route.contains("DeveloperProfileScreen") -> toRoute()
route.contains("ProfileScreen") -> GithubStoreGraph.ProfileScreen
route.contains("FavouritesScreen") -> GithubStoreGraph.FavouritesScreen
route.contains("StarredReposScreen") -> GithubStoreGraph.StarredReposScreen
route.contains("AppsScreen") -> GithubStoreGraph.AppsScreen
else -> null
}
}
================================================
FILE: composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/DesktopApp.kt
================================================
package zed.rainxch.githubstore
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.isCtrlPressed
import androidx.compose.ui.input.key.isMetaPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.type
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import zed.rainxch.githubstore.app.desktop.KeyboardNavigation
import zed.rainxch.githubstore.app.desktop.KeyboardNavigationEvent
import zed.rainxch.githubstore.app.di.initKoin
import zed.rainxch.githubstore.core.presentation.res.Res
import zed.rainxch.githubstore.core.presentation.res.app_icon
import zed.rainxch.githubstore.core.presentation.res.app_name
import java.awt.Desktop
import kotlin.system.exitProcess
fun main(args: Array) {
initKoin()
val deepLinkArg = args.firstOrNull()
if (deepLinkArg != null && DesktopDeepLink.tryForwardToRunningInstance(deepLinkArg)) {
exitProcess(0)
}
DesktopDeepLink.registerUriSchemeIfNeeded()
application {
var deepLinkUri by mutableStateOf(deepLinkArg)
LaunchedEffect(Unit) {
DesktopDeepLink.startInstanceListener { uri ->
deepLinkUri = uri
}
}
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().let { desktop ->
if (desktop.isSupported(Desktop.Action.APP_OPEN_URI)) {
desktop.setOpenURIHandler { event ->
deepLinkUri = event.uri.toString()
}
}
}
}
Window(
onCloseRequest = ::exitApplication,
title = stringResource(Res.string.app_name),
icon = painterResource(Res.drawable.app_icon),
onKeyEvent = { keyEvent ->
if (keyEvent.key == Key.F && keyEvent.type == KeyEventType.KeyDown) {
if (keyEvent.isCtrlPressed || keyEvent.isMetaPressed) {
KeyboardNavigation.onKeyClicked(KeyboardNavigationEvent.OnCtrlFClick)
true
} else {
false
}
} else {
false
}
},
) {
App(deepLinkUri = deepLinkUri)
}
}
}
================================================
FILE: composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/DesktopDeepLink.kt
================================================
package zed.rainxch.githubstore
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.io.PrintWriter
import java.net.InetAddress
import java.net.ServerSocket
import java.net.Socket
object DesktopDeepLink {
private const val SINGLE_INSTANCE_PORT = 47632
private const val SCHEME = "githubstore"
private const val DESKTOP_FILE_NAME = "github-store-deeplink"
/**
* On Windows and Linux, ensure the `githubstore://` protocol is registered.
* - Windows: Writes to HKCU registry.
* - Linux: Creates a `.desktop` file and registers via `xdg-mime`.
* No-op on macOS (handled via Info.plist in the packaged .app).
*/
fun registerUriSchemeIfNeeded() {
when {
isWindows() -> registerWindows()
isLinux() -> registerLinux()
}
}
private fun registerWindows() {
val checkResult =
runCommand(
"reg",
"query",
"HKCU\\SOFTWARE\\Classes\\$SCHEME",
"/ve",
)
if (checkResult != null && checkResult.contains("URL:")) return
val exePath = resolveExePath() ?: return
runCommand(
"reg",
"add",
"HKCU\\SOFTWARE\\Classes\\$SCHEME",
"/ve",
"/d",
"URL:GitHub Store Protocol",
"/f",
)
runCommand(
"reg",
"add",
"HKCU\\SOFTWARE\\Classes\\$SCHEME",
"/v",
"URL Protocol",
"/d",
"",
"/f",
)
runCommand(
"reg",
"add",
"HKCU\\SOFTWARE\\Classes\\$SCHEME\\DefaultIcon",
"/ve",
"/d",
"\"$exePath\",1",
"/f",
)
runCommand(
"reg",
"add",
"HKCU\\SOFTWARE\\Classes\\$SCHEME\\shell\\open\\command",
"/ve",
"/d",
"\"$exePath\" \"%1\"",
"/f",
)
}
private fun registerLinux() {
val appsDir = File(System.getProperty("user.home"), ".local/share/applications")
val desktopFile = File(appsDir, "$DESKTOP_FILE_NAME.desktop")
if (desktopFile.exists()) return
val exePath = resolveExePath() ?: return
appsDir.mkdirs()
desktopFile.writeText(
"""
[Desktop Entry]
Type=Application
Name=GitHub Store
Exec="$exePath" %u
Terminal=false
MimeType=x-scheme-handler/$SCHEME;
NoDisplay=true
""".trimIndent(),
)
runCommand("xdg-mime", "default", "$DESKTOP_FILE_NAME.desktop", "x-scheme-handler/$SCHEME")
}
/**
* Try to forward a deep link URI to an already-running instance.
* @return `true` if the URI was forwarded (this instance should exit),
* `false` if no existing instance is running.
*/
fun tryForwardToRunningInstance(uri: String): Boolean =
try {
Socket("127.0.0.1", SINGLE_INSTANCE_PORT).use { socket ->
PrintWriter(socket.getOutputStream(), true).println(uri)
}
true
} catch (_: Exception) {
false
}
/**
* Start listening for URIs forwarded from new instances.
* Calls [onUri] on the main thread when a URI is received.
*/
fun startInstanceListener(onUri: (String) -> Unit) {
val thread =
Thread({
try {
val server = ServerSocket(SINGLE_INSTANCE_PORT, 50, InetAddress.getLoopbackAddress())
while (true) {
val client = server.accept()
try {
val reader = BufferedReader(InputStreamReader(client.getInputStream()))
val uri = reader.readLine()
if (!uri.isNullOrBlank()) {
onUri(uri.trim())
}
} catch (_: Exception) {
} finally {
client.close()
}
}
} catch (_: Exception) {
}
}, "DeepLinkListener")
thread.isDaemon = true
thread.start()
}
private fun isWindows(): Boolean = System.getProperty("os.name")?.lowercase()?.contains("win") == true
private fun isLinux(): Boolean = System.getProperty("os.name")?.lowercase()?.contains("linux") == true
private fun resolveExePath(): String? =
try {
ProcessHandle
.current()
.info()
.command()
.orElse(null)
} catch (_: Exception) {
null
}
private fun runCommand(vararg cmd: String): String? =
try {
val process =
ProcessBuilder(*cmd)
.redirectErrorStream(true)
.start()
val output = process.inputStream.bufferedReader().readText()
process.waitFor()
output
} catch (_: Exception) {
null
}
}
================================================
FILE: core/data/.gitignore
================================================
/build
================================================
FILE: core/data/build.gradle.kts
================================================
plugins {
alias(libs.plugins.convention.kmp.library)
alias(libs.plugins.convention.room)
alias(libs.plugins.convention.buildkonfig)
}
android {
buildFeatures {
aidl = true
}
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(projects.core.domain)
implementation(libs.bundles.ktor.common)
implementation(libs.bundles.koin.common)
implementation(libs.touchlab.kermit)
implementation(libs.datastore)
implementation(libs.datastore.preferences)
implementation(libs.kotlinx.datetime)
}
}
androidMain {
dependencies {
implementation(libs.ktor.client.okhttp)
implementation(libs.androidx.work.runtime)
implementation(libs.shizuku.api)
implementation(libs.shizuku.provider)
compileOnly(libs.hidden.api.stub)
}
}
jvmMain {
dependencies {
implementation(libs.ktor.client.okhttp)
}
}
}
}
================================================
FILE: core/data/schemas/zed.rainxch.core.data.local.db.AppDatabase/3.json
================================================
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "81a8b0bb930a5c839e0da7a5335e4991",
"entities": [
{
"tableName": "installed_apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`packageName` TEXT NOT NULL, `repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `installedVersion` TEXT NOT NULL, `installedAssetName` TEXT, `installedAssetUrl` TEXT, `latestVersion` TEXT, `latestAssetName` TEXT, `latestAssetUrl` TEXT, `latestAssetSize` INTEGER, `appName` TEXT NOT NULL, `installSource` TEXT NOT NULL, `installedAt` INTEGER NOT NULL, `lastCheckedAt` INTEGER NOT NULL, `lastUpdatedAt` INTEGER NOT NULL, `isUpdateAvailable` INTEGER NOT NULL, `updateCheckEnabled` INTEGER NOT NULL, `releaseNotes` TEXT, `systemArchitecture` TEXT NOT NULL, `fileExtension` TEXT NOT NULL, `isPendingInstall` INTEGER NOT NULL, `installedVersionName` TEXT, `installedVersionCode` INTEGER NOT NULL, `latestVersionName` TEXT, `latestVersionCode` INTEGER, PRIMARY KEY(`packageName`))",
"fields": [
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedVersion",
"columnName": "installedVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAssetName",
"columnName": "installedAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "installedAssetUrl",
"columnName": "installedAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetName",
"columnName": "latestAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetUrl",
"columnName": "latestAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetSize",
"columnName": "latestAssetSize",
"affinity": "INTEGER"
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installSource",
"columnName": "installSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAt",
"columnName": "installedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastCheckedAt",
"columnName": "lastCheckedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdatedAt",
"columnName": "lastUpdatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isUpdateAvailable",
"columnName": "isUpdateAvailable",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateCheckEnabled",
"columnName": "updateCheckEnabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "releaseNotes",
"columnName": "releaseNotes",
"affinity": "TEXT"
},
{
"fieldPath": "systemArchitecture",
"columnName": "systemArchitecture",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fileExtension",
"columnName": "fileExtension",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPendingInstall",
"columnName": "isPendingInstall",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedVersionName",
"columnName": "installedVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "installedVersionCode",
"columnName": "installedVersionCode",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "latestVersionName",
"columnName": "latestVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersionCode",
"columnName": "latestVersionCode",
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"packageName"
]
}
},
{
"tableName": "favorite_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "update_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `packageName` TEXT NOT NULL, `appName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoName` TEXT NOT NULL, `fromVersion` TEXT NOT NULL, `toVersion` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL, `updateSource` TEXT NOT NULL, `success` INTEGER NOT NULL, `errorMessage` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fromVersion",
"columnName": "fromVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "toVersion",
"columnName": "toVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedAt",
"columnName": "updatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateSource",
"columnName": "updateSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "errorMessage",
"columnName": "errorMessage",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
},
{
"tableName": "starred_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `stargazersCount` INTEGER NOT NULL, `forksCount` INTEGER NOT NULL, `openIssuesCount` INTEGER NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `starredAt` INTEGER, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "stargazersCount",
"columnName": "stargazersCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "forksCount",
"columnName": "forksCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "openIssuesCount",
"columnName": "openIssuesCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "starredAt",
"columnName": "starredAt",
"affinity": "INTEGER"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '81a8b0bb930a5c839e0da7a5335e4991')"
]
}
}
================================================
FILE: core/data/schemas/zed.rainxch.core.data.local.db.AppDatabase/4.json
================================================
{
"formatVersion": 1,
"database": {
"version": 4,
"identityHash": "7d8cd14625a6c8b570092980957d57ce",
"entities": [
{
"tableName": "installed_apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`packageName` TEXT NOT NULL, `repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `installedVersion` TEXT NOT NULL, `installedAssetName` TEXT, `installedAssetUrl` TEXT, `latestVersion` TEXT, `latestAssetName` TEXT, `latestAssetUrl` TEXT, `latestAssetSize` INTEGER, `appName` TEXT NOT NULL, `installSource` TEXT NOT NULL, `installedAt` INTEGER NOT NULL, `lastCheckedAt` INTEGER NOT NULL, `lastUpdatedAt` INTEGER NOT NULL, `isUpdateAvailable` INTEGER NOT NULL, `updateCheckEnabled` INTEGER NOT NULL, `releaseNotes` TEXT, `systemArchitecture` TEXT NOT NULL, `fileExtension` TEXT NOT NULL, `isPendingInstall` INTEGER NOT NULL, `installedVersionName` TEXT, `installedVersionCode` INTEGER NOT NULL, `latestVersionName` TEXT, `latestVersionCode` INTEGER, PRIMARY KEY(`packageName`))",
"fields": [
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedVersion",
"columnName": "installedVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAssetName",
"columnName": "installedAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "installedAssetUrl",
"columnName": "installedAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetName",
"columnName": "latestAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetUrl",
"columnName": "latestAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetSize",
"columnName": "latestAssetSize",
"affinity": "INTEGER"
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installSource",
"columnName": "installSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAt",
"columnName": "installedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastCheckedAt",
"columnName": "lastCheckedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdatedAt",
"columnName": "lastUpdatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isUpdateAvailable",
"columnName": "isUpdateAvailable",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateCheckEnabled",
"columnName": "updateCheckEnabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "releaseNotes",
"columnName": "releaseNotes",
"affinity": "TEXT"
},
{
"fieldPath": "systemArchitecture",
"columnName": "systemArchitecture",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fileExtension",
"columnName": "fileExtension",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPendingInstall",
"columnName": "isPendingInstall",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedVersionName",
"columnName": "installedVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "installedVersionCode",
"columnName": "installedVersionCode",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "latestVersionName",
"columnName": "latestVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersionCode",
"columnName": "latestVersionCode",
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"packageName"
]
}
},
{
"tableName": "favorite_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "update_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `packageName` TEXT NOT NULL, `appName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoName` TEXT NOT NULL, `fromVersion` TEXT NOT NULL, `toVersion` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL, `updateSource` TEXT NOT NULL, `success` INTEGER NOT NULL, `errorMessage` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fromVersion",
"columnName": "fromVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "toVersion",
"columnName": "toVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedAt",
"columnName": "updatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateSource",
"columnName": "updateSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "errorMessage",
"columnName": "errorMessage",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
},
{
"tableName": "starred_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `stargazersCount` INTEGER NOT NULL, `forksCount` INTEGER NOT NULL, `openIssuesCount` INTEGER NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `starredAt` INTEGER, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "stargazersCount",
"columnName": "stargazersCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "forksCount",
"columnName": "forksCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "openIssuesCount",
"columnName": "openIssuesCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "starredAt",
"columnName": "starredAt",
"affinity": "INTEGER"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "cache_entries",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `jsonData` TEXT NOT NULL, `cachedAt` INTEGER NOT NULL, `expiresAt` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "jsonData",
"columnName": "jsonData",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "cachedAt",
"columnName": "cachedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "expiresAt",
"columnName": "expiresAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7d8cd14625a6c8b570092980957d57ce')"
]
}
}
================================================
FILE: core/data/schemas/zed.rainxch.core.data.local.db.AppDatabase/5.json
================================================
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "9d5111af6d583511c868ab59557e4ea8",
"entities": [
{
"tableName": "installed_apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`packageName` TEXT NOT NULL, `repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `installedVersion` TEXT NOT NULL, `installedAssetName` TEXT, `installedAssetUrl` TEXT, `latestVersion` TEXT, `latestAssetName` TEXT, `latestAssetUrl` TEXT, `latestAssetSize` INTEGER, `appName` TEXT NOT NULL, `installSource` TEXT NOT NULL, `signingFingerprint` TEXT, `installedAt` INTEGER NOT NULL, `lastCheckedAt` INTEGER NOT NULL, `lastUpdatedAt` INTEGER NOT NULL, `isUpdateAvailable` INTEGER NOT NULL, `updateCheckEnabled` INTEGER NOT NULL, `releaseNotes` TEXT, `systemArchitecture` TEXT NOT NULL, `fileExtension` TEXT NOT NULL, `isPendingInstall` INTEGER NOT NULL, `installedVersionName` TEXT, `installedVersionCode` INTEGER NOT NULL, `latestVersionName` TEXT, `latestVersionCode` INTEGER, PRIMARY KEY(`packageName`))",
"fields": [
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedVersion",
"columnName": "installedVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAssetName",
"columnName": "installedAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "installedAssetUrl",
"columnName": "installedAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetName",
"columnName": "latestAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetUrl",
"columnName": "latestAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetSize",
"columnName": "latestAssetSize",
"affinity": "INTEGER"
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installSource",
"columnName": "installSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "signingFingerprint",
"columnName": "signingFingerprint",
"affinity": "TEXT"
},
{
"fieldPath": "installedAt",
"columnName": "installedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastCheckedAt",
"columnName": "lastCheckedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdatedAt",
"columnName": "lastUpdatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isUpdateAvailable",
"columnName": "isUpdateAvailable",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateCheckEnabled",
"columnName": "updateCheckEnabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "releaseNotes",
"columnName": "releaseNotes",
"affinity": "TEXT"
},
{
"fieldPath": "systemArchitecture",
"columnName": "systemArchitecture",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fileExtension",
"columnName": "fileExtension",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPendingInstall",
"columnName": "isPendingInstall",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedVersionName",
"columnName": "installedVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "installedVersionCode",
"columnName": "installedVersionCode",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "latestVersionName",
"columnName": "latestVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersionCode",
"columnName": "latestVersionCode",
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"packageName"
]
}
},
{
"tableName": "favorite_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "update_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `packageName` TEXT NOT NULL, `appName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoName` TEXT NOT NULL, `fromVersion` TEXT NOT NULL, `toVersion` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL, `updateSource` TEXT NOT NULL, `success` INTEGER NOT NULL, `errorMessage` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fromVersion",
"columnName": "fromVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "toVersion",
"columnName": "toVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedAt",
"columnName": "updatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateSource",
"columnName": "updateSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "errorMessage",
"columnName": "errorMessage",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
},
{
"tableName": "starred_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `stargazersCount` INTEGER NOT NULL, `forksCount` INTEGER NOT NULL, `openIssuesCount` INTEGER NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `starredAt` INTEGER, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "stargazersCount",
"columnName": "stargazersCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "forksCount",
"columnName": "forksCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "openIssuesCount",
"columnName": "openIssuesCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "starredAt",
"columnName": "starredAt",
"affinity": "INTEGER"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "cache_entries",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `jsonData` TEXT NOT NULL, `cachedAt` INTEGER NOT NULL, `expiresAt` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "jsonData",
"columnName": "jsonData",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "cachedAt",
"columnName": "cachedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "expiresAt",
"columnName": "expiresAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9d5111af6d583511c868ab59557e4ea8')"
]
}
}
================================================
FILE: core/data/schemas/zed.rainxch.core.data.local.db.AppDatabase/6.json
================================================
{
"formatVersion": 1,
"database": {
"version": 6,
"identityHash": "ce64b232de8d6ab9d95e3adabf7c7c43",
"entities": [
{
"tableName": "installed_apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`packageName` TEXT NOT NULL, `repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `installedVersion` TEXT NOT NULL, `installedAssetName` TEXT, `installedAssetUrl` TEXT, `latestVersion` TEXT, `latestAssetName` TEXT, `latestAssetUrl` TEXT, `latestAssetSize` INTEGER, `appName` TEXT NOT NULL, `installSource` TEXT NOT NULL, `signingFingerprint` TEXT, `installedAt` INTEGER NOT NULL, `lastCheckedAt` INTEGER NOT NULL, `lastUpdatedAt` INTEGER NOT NULL, `isUpdateAvailable` INTEGER NOT NULL, `updateCheckEnabled` INTEGER NOT NULL, `releaseNotes` TEXT, `systemArchitecture` TEXT NOT NULL, `fileExtension` TEXT NOT NULL, `isPendingInstall` INTEGER NOT NULL, `installedVersionName` TEXT, `installedVersionCode` INTEGER NOT NULL, `latestVersionName` TEXT, `latestVersionCode` INTEGER, PRIMARY KEY(`packageName`))",
"fields": [
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedVersion",
"columnName": "installedVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installedAssetName",
"columnName": "installedAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "installedAssetUrl",
"columnName": "installedAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetName",
"columnName": "latestAssetName",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetUrl",
"columnName": "latestAssetUrl",
"affinity": "TEXT"
},
{
"fieldPath": "latestAssetSize",
"columnName": "latestAssetSize",
"affinity": "INTEGER"
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "installSource",
"columnName": "installSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "signingFingerprint",
"columnName": "signingFingerprint",
"affinity": "TEXT"
},
{
"fieldPath": "installedAt",
"columnName": "installedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastCheckedAt",
"columnName": "lastCheckedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdatedAt",
"columnName": "lastUpdatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isUpdateAvailable",
"columnName": "isUpdateAvailable",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateCheckEnabled",
"columnName": "updateCheckEnabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "releaseNotes",
"columnName": "releaseNotes",
"affinity": "TEXT"
},
{
"fieldPath": "systemArchitecture",
"columnName": "systemArchitecture",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fileExtension",
"columnName": "fileExtension",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPendingInstall",
"columnName": "isPendingInstall",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedVersionName",
"columnName": "installedVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "installedVersionCode",
"columnName": "installedVersionCode",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "latestVersionName",
"columnName": "latestVersionName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersionCode",
"columnName": "latestVersionCode",
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"packageName"
]
}
},
{
"tableName": "favorite_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "update_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `packageName` TEXT NOT NULL, `appName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoName` TEXT NOT NULL, `fromVersion` TEXT NOT NULL, `toVersion` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL, `updateSource` TEXT NOT NULL, `success` INTEGER NOT NULL, `errorMessage` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "packageName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "appName",
"columnName": "appName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fromVersion",
"columnName": "fromVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "toVersion",
"columnName": "toVersion",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedAt",
"columnName": "updatedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updateSource",
"columnName": "updateSource",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "errorMessage",
"columnName": "errorMessage",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
},
{
"tableName": "starred_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `repoName` TEXT NOT NULL, `repoOwner` TEXT NOT NULL, `repoOwnerAvatarUrl` TEXT NOT NULL, `repoDescription` TEXT, `primaryLanguage` TEXT, `repoUrl` TEXT NOT NULL, `stargazersCount` INTEGER NOT NULL, `forksCount` INTEGER NOT NULL, `openIssuesCount` INTEGER NOT NULL, `isInstalled` INTEGER NOT NULL, `installedPackageName` TEXT, `latestVersion` TEXT, `latestReleaseUrl` TEXT, `starredAt` INTEGER, `addedAt` INTEGER NOT NULL, `lastSyncedAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "repoName",
"columnName": "repoName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwner",
"columnName": "repoOwner",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoOwnerAvatarUrl",
"columnName": "repoOwnerAvatarUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "repoDescription",
"columnName": "repoDescription",
"affinity": "TEXT"
},
{
"fieldPath": "primaryLanguage",
"columnName": "primaryLanguage",
"affinity": "TEXT"
},
{
"fieldPath": "repoUrl",
"columnName": "repoUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "stargazersCount",
"columnName": "stargazersCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "forksCount",
"columnName": "forksCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "openIssuesCount",
"columnName": "openIssuesCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isInstalled",
"columnName": "isInstalled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "installedPackageName",
"columnName": "installedPackageName",
"affinity": "TEXT"
},
{
"fieldPath": "latestVersion",
"columnName": "latestVersion",
"affinity": "TEXT"
},
{
"fieldPath": "latestReleaseUrl",
"columnName": "latestReleaseUrl",
"affinity": "TEXT"
},
{
"fieldPath": "starredAt",
"columnName": "starredAt",
"affinity": "INTEGER"
},
{
"fieldPath": "addedAt",
"columnName": "addedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastSyncedAt",
"columnName": "lastSyncedAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
},
{
"tableName": "cache_entries",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `jsonData` TEXT NOT NULL, `cachedAt` INTEGER NOT NULL, `expiresAt` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "jsonData",
"columnName": "jsonData",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "cachedAt",
"columnName": "cachedAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "expiresAt",
"columnName": "expiresAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
}
},
{
"tableName": "seen_repos",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repoId` INTEGER NOT NULL, `seenAt` INTEGER NOT NULL, PRIMARY KEY(`repoId`))",
"fields": [
{
"fieldPath": "repoId",
"columnName": "repoId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "seenAt",
"columnName": "seenAt",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"repoId"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ce64b232de8d6ab9d95e3adabf7c7c43')"
]
}
}
================================================
FILE: core/data/src/androidMain/AndroidManifest.xml
================================================
================================================
FILE: core/data/src/androidMain/aidl/zed/rainxch/core/data/services/shizuku/IShizukuInstallerService.aidl
================================================
package zed.rainxch.core.data.services.shizuku;
interface IShizukuInstallerService {
int installPackage(in ParcelFileDescriptor pfd, long fileSize);
int uninstallPackage(String packageName);
void destroy();
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/di/PlatformModule.android.kt
================================================
package zed.rainxch.core.data.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import kotlinx.coroutines.CoroutineScope
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
import zed.rainxch.core.data.local.data_store.createDataStore
import zed.rainxch.core.data.local.db.AppDatabase
import zed.rainxch.core.data.local.db.initDatabase
import zed.rainxch.core.data.services.AndroidDownloader
import zed.rainxch.core.data.services.AndroidFileLocationsProvider
import zed.rainxch.core.data.services.AndroidInstaller
import zed.rainxch.core.data.services.AndroidInstallerInfoExtractor
import zed.rainxch.core.data.services.AndroidLocalizationManager
import zed.rainxch.core.data.services.AndroidPackageMonitor
import zed.rainxch.core.data.services.AndroidUpdateScheduleManager
import zed.rainxch.core.data.services.FileLocationsProvider
import zed.rainxch.core.data.services.LocalizationManager
import zed.rainxch.core.data.services.shizuku.AndroidInstallerStatusProvider
import zed.rainxch.core.data.services.shizuku.ShizukuInstallerWrapper
import zed.rainxch.core.data.services.shizuku.ShizukuServiceManager
import zed.rainxch.core.data.utils.AndroidAppLauncher
import zed.rainxch.core.data.utils.AndroidBrowserHelper
import zed.rainxch.core.data.utils.AndroidClipboardHelper
import zed.rainxch.core.data.utils.AndroidShareManager
import zed.rainxch.core.domain.network.Downloader
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerStatusProvider
import zed.rainxch.core.domain.system.PackageMonitor
import zed.rainxch.core.domain.system.UpdateScheduleManager
import zed.rainxch.core.domain.utils.AppLauncher
import zed.rainxch.core.domain.utils.BrowserHelper
import zed.rainxch.core.domain.utils.ClipboardHelper
import zed.rainxch.core.domain.utils.ShareManager
actual val corePlatformModule =
module {
// Core
single {
AndroidDownloader(
files = get(),
)
}
// AndroidInstaller — registered by class so the wrapper can inject it
single {
AndroidInstaller(
context = get(),
installerInfoExtractor = AndroidInstallerInfoExtractor(androidContext()),
)
}
// ShizukuServiceManager — manages Shizuku lifecycle, permissions, service binding
single {
ShizukuServiceManager(
context = androidContext(),
).also { it.initialize() }
}
// Installer — the ShizukuInstallerWrapper is the public Installer singleton.
// It delegates to AndroidInstaller by default, intercepting with Shizuku when enabled.
single {
ShizukuInstallerWrapper(
androidInstaller = get(),
shizukuServiceManager = get(),
tweaksRepository = get(),
).also { wrapper ->
wrapper.observeInstallerPreference(get())
}
}
// InstallerStatusProvider — exposes Shizuku availability to the UI layer
single {
AndroidInstallerStatusProvider(
shizukuServiceManager = get(),
scope = get(),
)
}
single {
AndroidFileLocationsProvider(context = get())
}
single {
AndroidPackageMonitor(androidContext())
}
single {
AndroidLocalizationManager()
}
// Locals
single {
initDatabase(androidContext())
}
single> {
createDataStore(androidContext())
}
// Utils
single {
AndroidBrowserHelper(androidContext())
}
single {
AndroidClipboardHelper(androidContext())
}
single {
AndroidAppLauncher(
context = androidContext(),
logger = get(),
)
}
single {
AndroidShareManager(
context = androidContext(),
)
}
single {
AndroidUpdateScheduleManager(
context = androidContext(),
)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/data_store/createDataStore.kt
================================================
package zed.rainxch.core.data.local.data_store
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
fun createDataStore(context: Context): DataStore =
createDataStore(
producePath = {
context.filesDir.resolve(_root_ide_package_.zed.rainxch.core.data.local.data_store.dataStoreFileName).absolutePath
},
)
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/initDatabase.kt
================================================
package zed.rainxch.core.data.local.db
import android.content.Context
import androidx.room.Room
import kotlinx.coroutines.Dispatchers
import zed.rainxch.core.data.local.db.migrations.MIGRATION_1_2
import zed.rainxch.core.data.local.db.migrations.MIGRATION_2_3
import zed.rainxch.core.data.local.db.migrations.MIGRATION_3_4
import zed.rainxch.core.data.local.db.migrations.MIGRATION_4_5
import zed.rainxch.core.data.local.db.migrations.MIGRATION_5_6
fun initDatabase(context: Context): AppDatabase {
val appContext = context.applicationContext
val dbFile = appContext.getDatabasePath("github_store.db")
return Room
.databaseBuilder(
context = appContext,
name = dbFile.absolutePath,
).setQueryCoroutineContext(Dispatchers.IO)
.addMigrations(
MIGRATION_1_2,
MIGRATION_2_3,
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6,
).build()
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/MIGRATION_1_2.kt
================================================
package zed.rainxch.core.data.local.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_1_2 =
object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE installed_apps ADD COLUMN installedVersionName TEXT")
db.execSQL("ALTER TABLE installed_apps ADD COLUMN installedVersionCode INTEGER NOT NULL DEFAULT 0")
db.execSQL("ALTER TABLE installed_apps ADD COLUMN latestVersionName TEXT")
db.execSQL("ALTER TABLE installed_apps ADD COLUMN latestVersionCode INTEGER")
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/MIGRATION_2_3.kt
================================================
package zed.rainxch.core.data.local.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_2_3 =
object : Migration(2, 3) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""
CREATE TABLE starred_repos (
repoId INTEGER NOT NULL,
repoName TEXT NOT NULL,
repoOwner TEXT NOT NULL,
repoOwnerAvatarUrl TEXT NOT NULL,
repoDescription TEXT,
primaryLanguage TEXT,
repoUrl TEXT NOT NULL,
stargazersCount INTEGER NOT NULL,
forksCount INTEGER NOT NULL,
openIssuesCount INTEGER NOT NULL,
isInstalled INTEGER NOT NULL DEFAULT 0,
installedPackageName TEXT,
latestVersion TEXT,
latestReleaseUrl TEXT,
starredAt INTEGER,
addedAt INTEGER NOT NULL,
lastSyncedAt INTEGER NOT NULL,
PRIMARY KEY(repoId)
)
""".trimIndent(),
)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/MIGRATION_3_4.kt
================================================
package zed.rainxch.core.data.local.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_3_4 =
object : Migration(3, 4) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""
CREATE TABLE IF NOT EXISTS cache_entries (
`key` TEXT NOT NULL,
jsonData TEXT NOT NULL,
cachedAt INTEGER NOT NULL,
expiresAt INTEGER NOT NULL,
PRIMARY KEY(`key`)
)
""".trimIndent(),
)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/MIGRATION_4_5.kt
================================================
package zed.rainxch.core.data.local.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_4_5 =
object : Migration(4, 5) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE installed_apps ADD COLUMN signingFingerprint TEXT")
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/MIGRATION_5_6.kt
================================================
package zed.rainxch.core.data.local.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
val MIGRATION_5_6 =
object : Migration(5, 6) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""
CREATE TABLE IF NOT EXISTS seen_repos (
repoId INTEGER NOT NULL PRIMARY KEY,
seenAt INTEGER NOT NULL
)
""".trimIndent(),
)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/network/HttpClientFactory.android.kt
================================================
package zed.rainxch.core.data.network
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import okhttp3.Credentials
import zed.rainxch.core.domain.model.ProxyConfig
import java.net.Authenticator
import java.net.InetSocketAddress
import java.net.PasswordAuthentication
import java.net.Proxy
import java.net.ProxySelector
actual fun createPlatformHttpClient(proxyConfig: ProxyConfig): HttpClient {
Authenticator.setDefault(null)
return HttpClient(OkHttp) {
engine {
when (proxyConfig) {
is ProxyConfig.None -> {
proxy = Proxy.NO_PROXY
}
is ProxyConfig.System -> {
config {
proxySelector(ProxySelector.getDefault())
}
}
is ProxyConfig.Http -> {
proxy =
Proxy(
Proxy.Type.HTTP,
InetSocketAddress(proxyConfig.host, proxyConfig.port),
)
if (proxyConfig.username != null) {
config {
proxyAuthenticator { _, response ->
response.request
.newBuilder()
.header(
"Proxy-Authorization",
Credentials.basic(
proxyConfig.username!!,
proxyConfig.password.orEmpty(),
),
).build()
}
}
}
}
is ProxyConfig.Socks -> {
proxy =
Proxy(
Proxy.Type.SOCKS,
InetSocketAddress(proxyConfig.host, proxyConfig.port),
)
if (proxyConfig.username != null) {
Authenticator.setDefault(
object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication? {
if (requestingHost == proxyConfig.host &&
requestingPort == proxyConfig.port
) {
return PasswordAuthentication(
proxyConfig.username,
proxyConfig.password.orEmpty().toCharArray(),
)
}
return null
}
},
)
}
}
}
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidDownloader.kt
================================================
package zed.rainxch.core.data.services
import co.touchlab.kermit.Logger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.withContext
import okhttp3.Call
import okhttp3.Credentials
import okhttp3.OkHttpClient
import okhttp3.Request
import zed.rainxch.core.data.network.ProxyManager
import zed.rainxch.core.domain.model.DownloadProgress
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.network.Downloader
import java.io.File
import java.net.Authenticator
import java.net.InetSocketAddress
import java.net.PasswordAuthentication
import java.net.Proxy
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
class AndroidDownloader(
private val files: FileLocationsProvider,
private val proxyManager: ProxyManager = ProxyManager,
) : Downloader {
private val activeDownloads = ConcurrentHashMap()
private val activeFileNames = ConcurrentHashMap()
private fun buildClient(): OkHttpClient {
Authenticator.setDefault(null)
return OkHttpClient
.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.apply {
when (val config = proxyManager.currentProxyConfig.value) {
is ProxyConfig.None -> {
proxy(Proxy.NO_PROXY)
}
is ProxyConfig.System -> {}
is ProxyConfig.Http -> {
proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(config.host, config.port)))
if (config.username != null && config.password != null) {
proxyAuthenticator { _, response ->
response.request
.newBuilder()
.header(
"Proxy-Authorization",
Credentials.basic(config.username!!, config.password!!),
).build()
}
}
}
is ProxyConfig.Socks -> {
proxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress(config.host, config.port)))
if (config.username != null && config.password != null) {
Authenticator.setDefault(
object : Authenticator() {
override fun getPasswordAuthentication() =
PasswordAuthentication(
config.username,
config.password!!.toCharArray(),
)
},
)
}
}
}
}.build()
}
override fun download(
url: String,
suggestedFileName: String?,
): Flow =
flow {
val client = buildClient()
val dirPath = files.appDownloadsDir()
val dir = File(dirPath)
if (!dir.exists()) dir.mkdirs()
val rawName =
suggestedFileName?.takeIf { it.isNotBlank() }
?: url
.substringAfterLast('/')
.substringBefore('?')
.substringBefore('#')
.ifBlank { "asset-${UUID.randomUUID()}.apk" }
val safeName = rawName.substringAfterLast('/').substringAfterLast('\\')
require(safeName.isNotBlank() && safeName != "." && safeName != "..") {
"Invalid file name: $rawName"
}
check(!activeFileNames.containsKey(safeName)) {
"A download for '$safeName' is already in progress"
}
val downloadId = UUID.randomUUID().toString()
val destination = File(dir, safeName)
if (destination.exists()) {
Logger.d { "Deleting existing file before download: ${destination.absolutePath}" }
destination.delete()
}
Logger.d { "Starting download: $url (id=$downloadId)" }
val request = Request.Builder().url(url).build()
val call = client.newCall(request)
activeDownloads[downloadId] = call
activeFileNames[safeName] = downloadId
try {
call.execute().use { response ->
if (!response.isSuccessful) {
throw kotlinx.io.IOException("Unexpected code ${response.code}")
}
val body = response.body
val contentLength = body.contentLength()
val total = if (contentLength > 0) contentLength else null
body.byteStream().use { input ->
destination.outputStream().use { output ->
val buffer = ByteArray(8192)
var downloaded: Long = 0
var bytesRead: Int
while (input.read(buffer).also { bytesRead = it } != -1) {
output.write(buffer, 0, bytesRead)
downloaded += bytesRead
val percent =
if (total != null) ((downloaded * 100L) / total).toInt() else null
emit(DownloadProgress(downloaded, total, percent))
}
}
}
if (destination.exists() && destination.length() > 0) {
Logger.d { "Download complete: ${destination.absolutePath}" }
val finalDownloaded = destination.length()
val finalPercent =
if (total != null) ((finalDownloaded * 100L) / total).toInt() else 100
emit(DownloadProgress(finalDownloaded, total, finalPercent))
} else {
throw IllegalStateException("File not ready after download: ${destination.absolutePath}")
}
}
} catch (e: Exception) {
destination.delete()
Logger.e(e) { "Download failed" }
throw e
} finally {
activeDownloads.remove(downloadId)
activeFileNames.remove(safeName)
}
}.flowOn(Dispatchers.IO)
override suspend fun saveToFile(
url: String,
suggestedFileName: String?,
): String =
withContext(Dispatchers.IO) {
val rawName =
suggestedFileName?.takeIf { it.isNotBlank() }
?: url
.substringAfterLast('/')
.substringBefore('?')
.substringBefore('#')
.ifBlank { "asset-${UUID.randomUUID()}.apk" }
val safeName = rawName.substringAfterLast('/').substringAfterLast('\\')
require(safeName.isNotBlank() && safeName != "." && safeName != "..") {
"Invalid file name: $rawName"
}
val file = File(files.appDownloadsDir(), safeName)
if (file.exists()) {
Logger.d { "Deleting existing file before download: ${file.absolutePath}" }
file.delete()
}
Logger.d { "saveToFile downloading file..." }
download(url, suggestedFileName).collect { }
file.absolutePath
}
override suspend fun getDownloadedFilePath(fileName: String): String? =
withContext(Dispatchers.IO) {
val file = File(files.appDownloadsDir(), fileName)
if (file.exists() && file.length() > 0) {
file.absolutePath
} else {
null
}
}
override suspend fun cancelDownload(fileName: String): Boolean =
withContext(Dispatchers.IO) {
var cancelled = false
var deleted = false
val downloadId = activeFileNames[fileName]
if (downloadId != null) {
activeDownloads[downloadId]?.let { call: Call ->
if (!call.isCanceled()) {
call.cancel()
cancelled = true
}
activeDownloads.remove(downloadId)
}
activeFileNames.remove(fileName)
}
val file = File(files.appDownloadsDir(), fileName)
if (file.exists()) {
deleted = file.delete()
}
cancelled || deleted
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidFileLocationsProvider.kt
================================================
package zed.rainxch.core.data.services
import android.content.Context
import java.io.File
class AndroidFileLocationsProvider(
private val context: Context,
) : zed.rainxch.core.data.services.FileLocationsProvider {
override fun appDownloadsDir(): String {
val externalFilesRoot = context.getExternalFilesDir(null)
val dir = File(externalFilesRoot, "ghs_downloads")
if (!dir.exists()) dir.mkdirs()
return dir.absolutePath
}
override fun userDownloadsDir(): String {
return "" // No-op
}
override fun setExecutableIfNeeded(path: String) {
// No-op on Android
}
override fun getCacheSizeBytes(): Long {
val dir = File(appDownloadsDir())
return calculateDirSize(dir)
}
override fun clearCacheFiles(): Boolean {
val dir = File(appDownloadsDir())
return deleteDirectoryContents(dir)
}
private fun calculateDirSize(dir: File): Long {
if (!dir.exists()) return 0L
var size = 0L
dir.listFiles()?.forEach { file ->
size += if (file.isDirectory) calculateDirSize(file) else file.length()
}
return size
}
private fun deleteDirectoryContents(dir: File): Boolean {
if (!dir.exists()) return true
var allDeleted = true
dir.listFiles()?.forEach { file ->
if (file.isDirectory) {
if (!deleteDirectoryContents(file)) allDeleted = false
if (!file.delete()) allDeleted = false
} else {
if (!file.delete()) allDeleted = false
}
}
return allDeleted
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidInstaller.kt
================================================
package zed.rainxch.core.data.services
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.core.content.FileProvider
import androidx.core.net.toUri
import co.touchlab.kermit.Logger
import zed.rainxch.core.domain.model.AssetArchitectureMatcher
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor
import java.io.File
class AndroidInstaller(
private val context: Context,
private val installerInfoExtractor: InstallerInfoExtractor,
) : Installer {
override fun getApkInfoExtractor(): InstallerInfoExtractor = installerInfoExtractor
override fun detectSystemArchitecture(): SystemArchitecture {
val arch = Build.SUPPORTED_ABIS.firstOrNull() ?: return SystemArchitecture.UNKNOWN
return when {
arch.contains("arm64") || arch.contains("aarch64") -> SystemArchitecture.AARCH64
arch.contains("armeabi") -> SystemArchitecture.ARM
arch.contains("x86_64") -> SystemArchitecture.X86_64
arch.contains("x86") -> SystemArchitecture.X86
else -> SystemArchitecture.UNKNOWN
}
}
override fun isAssetInstallable(assetName: String): Boolean {
val name = assetName.lowercase()
if (!name.endsWith(".apk")) return false
val systemArch = detectSystemArchitecture()
return isArchitectureCompatible(name, systemArch)
}
private fun isArchitectureCompatible(
assetName: String,
systemArch: SystemArchitecture,
): Boolean = AssetArchitectureMatcher.isCompatible(assetName, systemArch)
override fun choosePrimaryAsset(assets: List): GithubAsset? {
if (assets.isEmpty()) return null
val systemArch = detectSystemArchitecture()
val compatibleAssets =
assets.filter { asset ->
isArchitectureCompatible(asset.name.lowercase(), systemArch)
}
val assetsToConsider = compatibleAssets.ifEmpty { assets }
return assetsToConsider.maxByOrNull { asset ->
val name = asset.name.lowercase()
val archBoost =
when (systemArch) {
SystemArchitecture.X86_64 -> {
if (AssetArchitectureMatcher.isExactMatch(
name,
SystemArchitecture.X86_64,
)
) {
10000
} else {
0
}
}
SystemArchitecture.AARCH64 -> {
if (AssetArchitectureMatcher.isExactMatch(
name,
SystemArchitecture.AARCH64,
)
) {
10000
} else {
0
}
}
SystemArchitecture.X86 -> {
if (AssetArchitectureMatcher.isExactMatch(
name,
SystemArchitecture.X86,
)
) {
10000
} else {
0
}
}
SystemArchitecture.ARM -> {
if (AssetArchitectureMatcher.isExactMatch(
name,
SystemArchitecture.ARM,
)
) {
10000
} else {
0
}
}
SystemArchitecture.UNKNOWN -> {
0
}
}
archBoost + asset.size
}
}
override suspend fun isSupported(extOrMime: String): Boolean {
val ext = extOrMime.lowercase().removePrefix(".")
return ext == "apk"
}
override suspend fun ensurePermissionsOrThrow(extOrMime: String) {
val pm = context.packageManager
if (!pm.canRequestPackageInstalls()) {
val intent =
Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).apply {
data = "package:${context.packageName}".toUri()
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
throw IllegalStateException("Please enable 'Install unknown apps' for this app in Settings and try again.")
}
}
override suspend fun install(
filePath: String,
extOrMime: String,
) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("APK file not found: $filePath")
}
Logger.d { "Installing APK: $filePath" }
val authority = "${context.packageName}.fileprovider"
val fileUri: Uri = FileProvider.getUriForFile(context, authority, file)
val intent =
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(fileUri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
if (intent.resolveActivity(context.packageManager) != null) {
context.startActivity(intent)
Logger.d { "APK installation intent launched" }
} else {
throw IllegalStateException("No installer available on this device")
}
}
override fun uninstall(packageName: String) {
Logger.d { "Requesting uninstall for: $packageName" }
val intent =
Intent(Intent.ACTION_DELETE).apply {
data = "package:$packageName".toUri()
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
} catch (e: Exception) {
Logger.w { "Failed to start uninstall for $packageName: ${e.message}" }
}
}
override fun isObtainiumInstalled(): Boolean =
try {
context.packageManager.getPackageInfo("dev.imranr.obtainium.fdroid", 0)
true
} catch (e: Exception) {
try {
context.packageManager.getPackageInfo("dev.imranr.obtainium", 0)
true
} catch (e: Exception) {
false
}
}
override fun openInObtainium(
repoOwner: String,
repoName: String,
onOpenInstaller: () -> Unit,
) {
val obtainiumUrl = "obtainium://add/https://github.com/$repoOwner/$repoName"
val intent =
Intent(Intent.ACTION_VIEW).apply {
data = obtainiumUrl.toUri()
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
} catch (_: ActivityNotFoundException) {
onOpenInstaller()
}
}
override fun isAppManagerInstalled(): Boolean =
try {
context.packageManager.getPackageInfo("io.github.muntashirakon.AppManager", 0)
true
} catch (e: Exception) {
false
}
override fun openApp(packageName: String): Boolean {
val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
return if (launchIntent != null) {
try {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(launchIntent)
true
} catch (e: ActivityNotFoundException) {
Logger.w { "Failed to launch $packageName: ${e.message}" }
false
}
} else {
Logger.w { "No launch intent found for $packageName" }
false
}
}
override fun openWithExternalInstaller(filePath: String) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("APK file not found: $filePath")
}
Logger.d { "Opening APK with external installer: $filePath" }
val authority = "${context.packageName}.fileprovider"
val fileUri: Uri = FileProvider.getUriForFile(context, authority, file)
val intent =
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(fileUri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
val chooser =
Intent.createChooser(intent, null).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(chooser)
}
override fun openInAppManager(
filePath: String,
onOpenInstaller: () -> Unit,
) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("APK file not found: $filePath")
}
Logger.d { "Opening APK in AppManager: $filePath" }
val authority = "${context.packageName}.fileprovider"
val fileUri: Uri = FileProvider.getUriForFile(context, authority, file)
val intent =
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(fileUri, "application/vnd.android.package-archive")
setPackage("io.github.muntashirakon.AppManager")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
Logger.d { "APK opened in AppManager" }
} catch (_: ActivityNotFoundException) {
onOpenInstaller()
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidInstallerInfoExtractor.kt
================================================
package zed.rainxch.core.data.services
import android.content.Context
import android.content.pm.PackageManager
import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
import android.os.Build
import co.touchlab.kermit.Logger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import zed.rainxch.core.domain.model.ApkPackageInfo
import zed.rainxch.core.domain.system.InstallerInfoExtractor
import java.io.File
import java.security.MessageDigest
class AndroidInstallerInfoExtractor(
private val context: Context,
) : InstallerInfoExtractor {
override suspend fun extractPackageInfo(filePath: String): ApkPackageInfo? =
withContext(Dispatchers.IO) {
try {
val packageManager = context.packageManager
val flags =
PackageManager.GET_META_DATA or
PackageManager.GET_ACTIVITIES or
GET_SIGNING_CERTIFICATES
val packageInfo =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageArchiveInfo(
filePath,
PackageManager.PackageInfoFlags.of(flags.toLong()),
)
} else {
@Suppress("DEPRECATION")
packageManager.getPackageArchiveInfo(filePath, flags)
}
if (packageInfo == null) {
Logger.e {
"Failed to parse APK at $filePath, file exists: ${
File(
filePath,
).exists()
}, size: ${File(filePath).length()}"
}
return@withContext null
}
val appInfo = packageInfo.applicationInfo
appInfo?.sourceDir = filePath
appInfo?.publicSourceDir = filePath
val appName = appInfo?.let { packageManager.getApplicationLabel(it) }.toString()
val versionCode =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
@Suppress("DEPRECATION")
packageInfo.versionCode.toLong()
}
val fingerprint: String? =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val sigInfo = packageInfo.signingInfo
val certs =
if (sigInfo?.hasMultipleSigners() == true) {
sigInfo.apkContentsSigners
} else {
sigInfo?.signingCertificateHistory
}
certs?.firstOrNull()?.toByteArray()?.let { certBytes ->
MessageDigest
.getInstance("SHA-256")
.digest(certBytes)
.joinToString(":") { "%02X".format(it) }
}
} else {
@Suppress("DEPRECATION")
val legacyInfo =
packageManager.getPackageArchiveInfo(
filePath,
PackageManager.GET_SIGNATURES,
)
@Suppress("DEPRECATION")
legacyInfo?.signatures?.firstOrNull()?.toByteArray()?.let { certBytes ->
MessageDigest
.getInstance("SHA-256")
.digest(certBytes)
.joinToString(":") { "%02X".format(it) }
}
}
ApkPackageInfo(
appName = appName,
packageName = packageInfo.packageName,
versionName = packageInfo.versionName ?: "unknown",
versionCode = versionCode,
signingFingerprint = fingerprint,
)
} catch (e: Exception) {
Logger.e { "Failed to extract APK info: ${e.message}, file: $filePath" }
null
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidLocalizationManager.kt
================================================
package zed.rainxch.core.data.services
import java.util.Locale
class AndroidLocalizationManager : zed.rainxch.core.data.services.LocalizationManager {
override fun getCurrentLanguageCode(): String {
val locale = Locale.getDefault()
val language = locale.language
val country = locale.country
return if (country.isNotEmpty()) {
"$language-$country"
} else {
language
}
}
override fun getPrimaryLanguageCode(): String = Locale.getDefault().language
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidPackageMonitor.kt
================================================
package zed.rainxch.core.data.services
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
import android.os.Build
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import zed.rainxch.core.domain.model.DeviceApp
import zed.rainxch.core.domain.model.SystemPackageInfo
import zed.rainxch.core.domain.system.PackageMonitor
import java.security.MessageDigest
class AndroidPackageMonitor(
context: Context,
) : PackageMonitor {
private val packageManager: PackageManager = context.packageManager
override suspend fun isPackageInstalled(packageName: String): Boolean = getInstalledPackageInfo(packageName) != null
override suspend fun getInstalledPackageInfo(packageName: String): SystemPackageInfo? =
withContext(Dispatchers.IO) {
runCatching {
val flags =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
GET_SIGNING_CERTIFICATES.toLong()
} else {
@Suppress("DEPRECATION")
PackageManager.GET_SIGNATURES.toLong()
}
val packageInfo =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(
packageName,
PackageManager.PackageInfoFlags.of(flags),
)
} else {
@Suppress("DEPRECATION")
packageManager.getPackageInfo(packageName, flags.toInt())
}
val versionCode =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
@Suppress("DEPRECATION")
packageInfo.versionCode.toLong()
}
val signingFingerprint: String? =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val sigInfo = packageInfo.signingInfo
val certs =
if (sigInfo?.hasMultipleSigners() == true) {
sigInfo.apkContentsSigners
} else {
sigInfo?.signingCertificateHistory
}
certs?.firstOrNull()?.toByteArray()?.let { certBytes ->
MessageDigest
.getInstance("SHA-256")
.digest(certBytes)
.joinToString(":") { "%02X".format(it) }
}
} else {
@Suppress("DEPRECATION")
packageInfo.signatures?.firstOrNull()?.toByteArray()?.let { certBytes ->
MessageDigest
.getInstance("SHA-256")
.digest(certBytes)
.joinToString(":") { "%02X".format(it) }
}
}
SystemPackageInfo(
packageName = packageInfo.packageName,
versionName = packageInfo.versionName ?: "unknown",
versionCode = versionCode,
isInstalled = true,
signingFingerprint = signingFingerprint,
)
}.getOrNull()
}
override suspend fun getAllInstalledPackageNames(): Set =
withContext(Dispatchers.IO) {
val packages =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getInstalledPackages(PackageManager.PackageInfoFlags.of(0L))
} else {
@Suppress("DEPRECATION")
packageManager.getInstalledPackages(0)
}
packages.map { it.packageName }.toSet()
}
override suspend fun getAllInstalledApps(): List =
withContext(Dispatchers.IO) {
val packages =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getInstalledPackages(PackageManager.PackageInfoFlags.of(0L))
} else {
@Suppress("DEPRECATION")
packageManager.getInstalledPackages(0)
}
packages
.filter { pkg ->
val isSystemApp = (pkg.applicationInfo?.flags ?: 0) and ApplicationInfo.FLAG_SYSTEM != 0
val isUpdatedSystem = (pkg.applicationInfo?.flags ?: 0) and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0
!isSystemApp || isUpdatedSystem
}.map { pkg ->
val versionCode =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
pkg.longVersionCode
} else {
@Suppress("DEPRECATION")
pkg.versionCode.toLong()
}
DeviceApp(
packageName = pkg.packageName,
appName = pkg.applicationInfo?.loadLabel(packageManager)?.toString() ?: pkg.packageName,
versionName = pkg.versionName,
versionCode = versionCode,
signingFingerprint = null,
)
}.sortedBy { it.appName.lowercase() }
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidUpdateScheduleManager.kt
================================================
package zed.rainxch.core.data.services
import android.content.Context
import zed.rainxch.core.domain.system.UpdateScheduleManager
class AndroidUpdateScheduleManager(
private val context: Context,
) : UpdateScheduleManager {
override fun reschedule(intervalHours: Long) {
UpdateScheduler.reschedule(context, intervalHours)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AutoUpdateWorker.kt
================================================
package zed.rainxch.core.data.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.first
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import zed.rainxch.core.data.services.shizuku.ShizukuServiceManager
import zed.rainxch.core.data.services.shizuku.model.ShizukuStatus
import zed.rainxch.core.domain.model.InstalledApp
import zed.rainxch.core.domain.model.InstallerType
import zed.rainxch.core.domain.network.Downloader
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.Installer
/**
* Background worker that automatically downloads and silently installs
* available updates via Shizuku.
*
* Only runs when auto-update is enabled AND Shizuku installer is selected and READY.
* Falls back gracefully: if Shizuku becomes unavailable mid-update, remaining apps
* are skipped and a notification is shown for manual update.
*/
class AutoUpdateWorker(
context: Context,
params: WorkerParameters,
) : CoroutineWorker(context, params),
KoinComponent {
private val installedAppsRepository: InstalledAppsRepository by inject()
private val installer: Installer by inject()
private val downloader: Downloader by inject()
private val tweaksRepository: TweaksRepository by inject()
private val shizukuServiceManager: ShizukuServiceManager by inject()
override suspend fun doWork(): Result {
return try {
Logger.i { "AutoUpdateWorker: Starting auto-update" }
val autoUpdateEnabled = tweaksRepository.getAutoUpdateEnabled().first()
val installerType = tweaksRepository.getInstallerType().first()
shizukuServiceManager.refreshStatus()
val shizukuReady = shizukuServiceManager.status.value == ShizukuStatus.READY
if (!autoUpdateEnabled || installerType != InstallerType.SHIZUKU || !shizukuReady) {
Logger.i {
"AutoUpdateWorker: Conditions not met (autoUpdate=$autoUpdateEnabled, installer=$installerType, shizuku=$shizukuReady), skipping"
}
return Result.success()
}
val appsWithUpdates = installedAppsRepository.getAppsWithUpdates().first()
if (appsWithUpdates.isEmpty()) {
Logger.d { "AutoUpdateWorker: No apps need updating" }
return Result.success()
}
setForeground(createForegroundInfo("Updating apps...", 0, appsWithUpdates.size))
val successfulApps = mutableListOf()
val failedApps = mutableListOf()
appsWithUpdates.forEachIndexed { index, app ->
setForeground(
createForegroundInfo(
"Updating ${app.appName}...",
index + 1,
appsWithUpdates.size,
),
)
try {
updateApp(app)
successfulApps.add(app.appName)
Logger.i { "AutoUpdateWorker: Successfully updated ${app.appName}" }
} catch (e: Exception) {
failedApps.add(app.appName)
Logger.e { "AutoUpdateWorker: Failed to update ${app.appName}: ${e.message}" }
try {
installedAppsRepository.updatePendingStatus(app.packageName, false)
} catch (clearEx: Exception) {
Logger.e { "AutoUpdateWorker: Failed to clear pending status: ${clearEx.message}" }
}
}
}
showSummaryNotification(successfulApps, failedApps)
Logger.i { "AutoUpdateWorker: Completed. Success: ${successfulApps.size}, Failed: ${failedApps.size}" }
Result.success()
} catch (e: Exception) {
Logger.e { "AutoUpdateWorker: Fatal error: ${e.message}" }
if (runAttemptCount < 2) {
Result.retry()
} else {
Result.failure()
}
}
}
private suspend fun updateApp(app: InstalledApp) {
val assetUrl =
app.latestAssetUrl
?: throw IllegalStateException("No asset URL for ${app.appName}")
val assetName =
app.latestAssetName
?: throw IllegalStateException("No asset name for ${app.appName}")
val latestVersion =
app.latestVersion
?: throw IllegalStateException("No latest version for ${app.appName}")
val ext = assetName.substringAfterLast('.', "").lowercase()
val existingPath = downloader.getDownloadedFilePath(assetName)
if (existingPath != null) {
val file = java.io.File(existingPath)
try {
val apkInfo = installer.getApkInfoExtractor().extractPackageInfo(existingPath)
val normalizedExisting =
apkInfo?.versionName?.removePrefix("v")?.removePrefix("V") ?: ""
val normalizedLatest = latestVersion.removePrefix("v").removePrefix("V")
if (normalizedExisting != normalizedLatest) {
file.delete()
Logger.d { "AutoUpdateWorker: Deleted mismatched existing file for ${app.appName}" }
}
} catch (_: Exception) {
file.delete()
Logger.d { "AutoUpdateWorker: Deleted unextractable existing file for ${app.appName}" }
}
}
Logger.d { "AutoUpdateWorker: Downloading $assetName for ${app.appName}" }
downloader.download(assetUrl, assetName).collect { /* consume flow to completion */ }
val filePath =
downloader.getDownloadedFilePath(assetName)
?: throw IllegalStateException("Downloaded file not found for ${app.appName}")
val apkInfo =
installer.getApkInfoExtractor().extractPackageInfo(filePath)
?: throw IllegalStateException("Failed to extract APK info for ${app.appName}")
// Validate package name matches
if (apkInfo.packageName != app.packageName) {
Logger.e {
"AutoUpdateWorker: Package name mismatch for ${app.appName}! " +
"Expected: ${app.packageName}, got: ${apkInfo.packageName}. " +
"Skipping auto-update."
}
throw IllegalStateException(
"Package name mismatch for ${app.appName}: expected ${app.packageName}, got ${apkInfo.packageName}",
)
}
val currentApp = installedAppsRepository.getAppByPackage(app.packageName)
if (currentApp?.signingFingerprint != null) {
val expected = currentApp.signingFingerprint!!.trim().uppercase()
val actual = apkInfo.signingFingerprint?.trim()?.uppercase()
if (actual == null || expected != actual) {
Logger.e {
"AutoUpdateWorker: Signing key mismatch for ${app.appName}! " +
"Expected: ${currentApp.signingFingerprint}, got: ${apkInfo.signingFingerprint}. " +
"Skipping auto-update."
}
throw IllegalStateException(
"Signing fingerprint verification failed for ${app.appName}, blocking auto-update",
)
}
installedAppsRepository.updateApp(
currentApp.copy(
isPendingInstall = true,
latestVersion = latestVersion,
latestAssetName = assetName,
latestAssetUrl = assetUrl,
latestVersionName = apkInfo.versionName,
latestVersionCode = apkInfo.versionCode,
),
)
Logger.d { "AutoUpdateWorker: Installing ${app.appName} via Shizuku" }
try {
installer.install(filePath, ext)
} catch (e: Exception) {
installedAppsRepository.updatePendingStatus(app.packageName, false)
throw e
}
Logger.d { "AutoUpdateWorker: Install command completed for ${app.appName}, waiting for system confirmation via broadcast" }
}
}
private fun createForegroundInfo(
message: String,
current: Int,
total: Int,
): ForegroundInfo {
val builder =
NotificationCompat
.Builder(applicationContext, UPDATE_SERVICE_CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle("GitHub Store")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true)
.setSilent(true)
if (total > 0) {
builder.setProgress(total, current, false)
}
val notification = builder.build()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(
FOREGROUND_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,
)
} else {
ForegroundInfo(FOREGROUND_NOTIFICATION_ID, notification)
}
}
@SuppressLint("MissingPermission")
private fun showSummaryNotification(
successfulApps: List,
failedApps: List,
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val granted =
ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.POST_NOTIFICATIONS,
) == PackageManager.PERMISSION_GRANTED
if (!granted) return
}
if (successfulApps.isEmpty() && failedApps.isEmpty()) return
val title =
when {
failedApps.isEmpty() -> "${successfulApps.size} app${if (successfulApps.size > 1) "s" else ""} updated"
successfulApps.isEmpty() -> "Failed to update ${failedApps.size} app${if (failedApps.size > 1) "s" else ""}"
else -> "${successfulApps.size} updated, ${failedApps.size} failed"
}
val text =
when {
failedApps.isEmpty() -> successfulApps.joinToString(", ")
successfulApps.isEmpty() -> failedApps.joinToString(", ")
else -> "Updated: ${successfulApps.joinToString(", ")}. Failed: ${
failedApps.joinToString(
", ",
)
}"
}
val launchIntent =
applicationContext.packageManager
.getLaunchIntentForPackage(applicationContext.packageName)
?.apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntent =
launchIntent?.let {
PendingIntent.getActivity(
applicationContext,
0,
it,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
}
val notification =
NotificationCompat
.Builder(applicationContext, UPDATES_CHANNEL_ID)
.setSmallIcon(
if (failedApps.isEmpty()) {
android.R.drawable.stat_sys_download_done
} else {
android.R.drawable.stat_notify_error
},
).setContentTitle(title)
.setContentText(text)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build()
NotificationManagerCompat
.from(applicationContext)
.notify(SUMMARY_NOTIFICATION_ID, notification)
}
companion object {
const val WORK_NAME = "github_store_auto_update"
private const val UPDATES_CHANNEL_ID = "app_updates"
private const val UPDATE_SERVICE_CHANNEL_ID = "update_service"
private const val FOREGROUND_NOTIFICATION_ID = 1004
private const val SUMMARY_NOTIFICATION_ID = 1005
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/BootReceiver.kt
================================================
package zed.rainxch.core.data.services
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import co.touchlab.kermit.Logger
/**
* Reschedules periodic update checks after device reboot.
* Registered statically in AndroidManifest.xml.
*/
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
if (intent?.action == Intent.ACTION_BOOT_COMPLETED) {
Logger.i { "BootReceiver: Device booted, scheduling update checks" }
UpdateScheduler.schedule(context)
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/PackageEventReceiver.kt
================================================
package zed.rainxch.core.data.services
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.system.PackageMonitor
/**
* Listens for package install/replace/remove broadcasts to update tracked app state.
*
* Registered both statically (manifest — works when process is dead, e.g. after
* Shizuku silent install) and dynamically (GithubStoreApp — immediate in-process delivery).
*
* Uses [KoinComponent] for the no-arg constructor path (manifest-registered).
* The constructor with explicit dependencies is used for dynamic registration.
*/
class PackageEventReceiver() :
BroadcastReceiver(),
KoinComponent {
private val installedAppsRepositoryKoin: InstalledAppsRepository by inject()
private val packageMonitorKoin: PackageMonitor by inject()
// Explicitly provided dependencies (dynamic registration path)
private var explicitRepository: InstalledAppsRepository? = null
private var explicitMonitor: PackageMonitor? = null
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
constructor(
installedAppsRepository: InstalledAppsRepository,
packageMonitor: PackageMonitor,
) : this() {
this.explicitRepository = installedAppsRepository
this.explicitMonitor = packageMonitor
}
private fun getRepository(): InstalledAppsRepository = explicitRepository ?: installedAppsRepositoryKoin
private fun getMonitor(): PackageMonitor = explicitMonitor ?: packageMonitorKoin
override fun onReceive(
context: Context?,
intent: Intent?,
) {
val packageName = intent?.data?.schemeSpecificPart ?: return
Logger.d { "PackageEventReceiver: ${intent.action} for $packageName" }
try {
when (intent.action) {
Intent.ACTION_PACKAGE_ADDED,
Intent.ACTION_PACKAGE_REPLACED,
-> {
scope.launch { onPackageInstalled(packageName) }
}
Intent.ACTION_PACKAGE_FULLY_REMOVED -> {
scope.launch { onPackageRemoved(packageName) }
}
}
} catch (e: Exception) {
Logger.e { "PackageEventReceiver: Failed to handle ${intent.action}: ${e.message}" }
}
}
private suspend fun onPackageInstalled(packageName: String) {
try {
val repo = getRepository()
val monitor = getMonitor()
val app = repo.getAppByPackage(packageName) ?: return
if (app.isPendingInstall) {
val systemInfo = monitor.getInstalledPackageInfo(packageName)
if (systemInfo != null) {
val expectedVersionCode = app.latestVersionCode ?: 0L
val wasActuallyUpdated =
expectedVersionCode > 0L &&
systemInfo.versionCode >= expectedVersionCode
if (wasActuallyUpdated) {
repo.updateAppVersion(
packageName = packageName,
newTag = app.latestVersion ?: systemInfo.versionName,
newAssetName = app.latestAssetName ?: "",
newAssetUrl = app.latestAssetUrl ?: "",
newVersionName = systemInfo.versionName,
newVersionCode = systemInfo.versionCode,
signingFingerprint = app.signingFingerprint,
)
repo.updatePendingStatus(packageName, false)
Logger.i { "Update confirmed via broadcast: $packageName (v${systemInfo.versionName})" }
} else {
repo.updateApp(
app.copy(
isPendingInstall = false,
installedVersionName = systemInfo.versionName,
installedVersionCode = systemInfo.versionCode,
isUpdateAvailable =
(
app.latestVersionCode
?: 0L
) > systemInfo.versionCode,
),
)
Logger.i {
"Package replaced but not updated to target: $packageName " +
"(system: v${systemInfo.versionName}/${systemInfo.versionCode}, " +
"target: v${app.latestVersionName}/${app.latestVersionCode})"
}
}
} else {
repo.updatePendingStatus(packageName, false)
Logger.i { "Resolved pending install via broadcast (no system info): $packageName" }
}
} else {
val systemInfo = monitor.getInstalledPackageInfo(packageName)
if (systemInfo != null) {
repo.updateApp(
app.copy(
installedVersionName = systemInfo.versionName,
installedVersionCode = systemInfo.versionCode,
),
)
Logger.d { "Updated version info via broadcast: $packageName (v${systemInfo.versionName})" }
}
}
} catch (e: Exception) {
Logger.e { "PackageEventReceiver error for $packageName: ${e.message}" }
}
}
private suspend fun onPackageRemoved(packageName: String) {
try {
getRepository().deleteInstalledApp(packageName)
Logger.i { "Removed uninstalled app via broadcast: $packageName" }
} catch (e: Exception) {
Logger.e { "PackageEventReceiver remove error for $packageName: ${e.message}" }
}
}
companion object {
fun createIntentFilter(): IntentFilter =
IntentFilter().apply {
addAction(Intent.ACTION_PACKAGE_ADDED)
addAction(Intent.ACTION_PACKAGE_REPLACED)
addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
addDataScheme("package")
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/UpdateCheckWorker.kt
================================================
package zed.rainxch.core.data.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.first
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import zed.rainxch.core.domain.model.InstallerType
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.use_cases.SyncInstalledAppsUseCase
/**
* Periodic background worker that checks all tracked installed apps for available updates.
*
* Runs via WorkManager on a configurable schedule (default: every 6 hours).
* First syncs app state with the system package manager, then checks each
* tracked app's GitHub repository for new releases.
* Shows a notification when updates are found, or triggers auto-update
* if Shizuku silent install is enabled and auto-update preference is on.
*/
class UpdateCheckWorker(
context: Context,
params: WorkerParameters,
) : CoroutineWorker(context, params),
KoinComponent {
private val installedAppsRepository: InstalledAppsRepository by inject()
private val syncInstalledAppsUseCase: SyncInstalledAppsUseCase by inject()
private val tweaksRepository: TweaksRepository by inject()
override suspend fun doWork(): Result =
try {
Logger.i { "UpdateCheckWorker: Starting periodic update check" }
// Run as foreground service to prevent OS from killing the worker
setForeground(createForegroundInfo("Checking for updates..."))
// First sync installed apps state with system
val syncResult = syncInstalledAppsUseCase()
if (syncResult.isFailure) {
Logger.w { "UpdateCheckWorker: Sync had issues: ${syncResult.exceptionOrNull()?.message}" }
}
// Check all tracked apps for updates
installedAppsRepository.checkAllForUpdates()
val appsWithUpdates = installedAppsRepository.getAppsWithUpdates().first()
if (appsWithUpdates.isNotEmpty()) {
// Check if auto-update via Shizuku is enabled
val autoUpdateEnabled = tweaksRepository.getAutoUpdateEnabled().first()
val installerType = tweaksRepository.getInstallerType().first()
if (autoUpdateEnabled && installerType == InstallerType.SHIZUKU) {
Logger.i {
"UpdateCheckWorker: Auto-update enabled with Shizuku, scheduling AutoUpdateWorker for ${appsWithUpdates.size} apps"
}
UpdateScheduler.scheduleAutoUpdate(applicationContext)
} else {
// Show notification for manual update
showUpdateNotification(appsWithUpdates)
}
} else {
Logger.d { "UpdateCheckWorker: No updates available" }
}
Logger.i { "UpdateCheckWorker: Periodic update check completed successfully" }
Result.success()
} catch (e: Exception) {
Logger.e { "UpdateCheckWorker: Update check failed: ${e.message}" }
if (runAttemptCount < 3) {
Result.retry()
} else {
Result.failure()
}
}
private fun createForegroundInfo(message: String): ForegroundInfo {
val notification =
NotificationCompat
.Builder(applicationContext, UPDATE_SERVICE_CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_notify_sync)
.setContentTitle("GitHub Store")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true)
.setSilent(true)
.build()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(
FOREGROUND_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,
)
} else {
ForegroundInfo(FOREGROUND_NOTIFICATION_ID, notification)
}
}
@SuppressLint("MissingPermission") // Permission checked at runtime before notify()
private suspend fun showUpdateNotification(appsWithUpdates: List) {
// Check notification permission for API 33+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val granted =
ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.POST_NOTIFICATIONS,
) == PackageManager.PERMISSION_GRANTED
if (!granted) {
Logger.w { "UpdateCheckWorker: POST_NOTIFICATIONS permission not granted, skipping notification" }
return
}
}
val title =
if (appsWithUpdates.size == 1) {
"${appsWithUpdates.first().appName} update available"
} else {
"${appsWithUpdates.size} app updates available"
}
val text =
if (appsWithUpdates.size == 1) {
val app = appsWithUpdates.first()
"${app.installedVersion} → ${app.latestVersion}"
} else {
appsWithUpdates.joinToString(", ") { it.appName }
}
val launchIntent =
applicationContext.packageManager
.getLaunchIntentForPackage(applicationContext.packageName)
?.apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val pendingIntent =
launchIntent?.let {
PendingIntent.getActivity(
applicationContext,
0,
it,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
}
val notification =
NotificationCompat
.Builder(applicationContext, UPDATES_CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_download_done)
.setContentTitle(title)
.setContentText(text)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build()
NotificationManagerCompat.from(applicationContext).notify(NOTIFICATION_ID, notification)
Logger.i { "UpdateCheckWorker: Showed notification for ${appsWithUpdates.size} updates" }
}
companion object {
const val WORK_NAME = "github_store_update_check"
private const val UPDATES_CHANNEL_ID = "app_updates"
private const val UPDATE_SERVICE_CHANNEL_ID = "update_service"
private const val NOTIFICATION_ID = 1001
private const val FOREGROUND_NOTIFICATION_ID = 1003
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/UpdateScheduler.kt
================================================
package zed.rainxch.core.data.services
import android.content.Context
import androidx.work.BackoffPolicy
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExistingWorkPolicy
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import co.touchlab.kermit.Logger
import java.util.concurrent.TimeUnit
object UpdateScheduler {
private const val DEFAULT_INTERVAL_HOURS = 6L
private const val IMMEDIATE_CHECK_WORK_NAME = "github_store_immediate_update_check"
fun schedule(
context: Context,
intervalHours: Long = DEFAULT_INTERVAL_HOURS,
) {
val constraints =
Constraints
.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val request =
PeriodicWorkRequestBuilder(
repeatInterval = intervalHours,
repeatIntervalTimeUnit = TimeUnit.HOURS,
).setConstraints(constraints)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
30,
TimeUnit.MINUTES,
).build()
WorkManager
.getInstance(context)
.enqueueUniquePeriodicWork(
uniqueWorkName = UpdateCheckWorker.WORK_NAME,
existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP,
request = request,
)
val immediateRequest =
OneTimeWorkRequestBuilder()
.setConstraints(constraints)
.setInitialDelay(1, TimeUnit.MINUTES)
.build()
WorkManager
.getInstance(context)
.enqueueUniqueWork(
IMMEDIATE_CHECK_WORK_NAME,
ExistingWorkPolicy.REPLACE,
immediateRequest,
)
Logger.i { "UpdateScheduler: Scheduled periodic update check every ${intervalHours}h + immediate check" }
}
fun reschedule(
context: Context,
intervalHours: Long,
) {
val constraints =
Constraints
.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val request =
PeriodicWorkRequestBuilder(
repeatInterval = intervalHours,
repeatIntervalTimeUnit = TimeUnit.HOURS,
).setConstraints(constraints)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
30,
TimeUnit.MINUTES,
).build()
WorkManager
.getInstance(context)
.enqueueUniquePeriodicWork(
uniqueWorkName = UpdateCheckWorker.WORK_NAME,
existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.UPDATE,
request = request,
)
Logger.i { "UpdateScheduler: Rescheduled periodic update check to every ${intervalHours}h" }
}
fun scheduleAutoUpdate(context: Context) {
val constraints =
Constraints
.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val request =
OneTimeWorkRequestBuilder()
.setConstraints(constraints)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
15,
TimeUnit.MINUTES,
).build()
WorkManager
.getInstance(context)
.enqueueUniqueWork(
AutoUpdateWorker.WORK_NAME,
ExistingWorkPolicy.KEEP,
request,
)
Logger.i { "UpdateScheduler: Scheduled auto-update worker" }
}
fun cancel(context: Context) {
WorkManager
.getInstance(context)
.cancelUniqueWork(UpdateCheckWorker.WORK_NAME)
WorkManager
.getInstance(context)
.cancelUniqueWork(IMMEDIATE_CHECK_WORK_NAME)
WorkManager
.getInstance(context)
.cancelUniqueWork(AutoUpdateWorker.WORK_NAME)
Logger.i { "UpdateScheduler: Cancelled all update work" }
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/shizuku/AndroidInstallerStatusProvider.kt
================================================
package zed.rainxch.core.data.services.shizuku
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import zed.rainxch.core.data.services.shizuku.model.ShizukuStatus
import zed.rainxch.core.domain.model.ShizukuAvailability
import zed.rainxch.core.domain.system.InstallerStatusProvider
/**
* Android implementation of [InstallerStatusProvider].
* Maps [ShizukuServiceManager.status] to the platform-agnostic [ShizukuAvailability] enum.
*/
class AndroidInstallerStatusProvider(
private val shizukuServiceManager: ShizukuServiceManager,
scope: CoroutineScope,
) : InstallerStatusProvider {
override val shizukuAvailability: StateFlow =
shizukuServiceManager.status
.map { status ->
when (status) {
ShizukuStatus.NOT_INSTALLED -> ShizukuAvailability.UNAVAILABLE
ShizukuStatus.NOT_RUNNING -> ShizukuAvailability.NOT_RUNNING
ShizukuStatus.PERMISSION_NEEDED -> ShizukuAvailability.PERMISSION_NEEDED
ShizukuStatus.READY -> ShizukuAvailability.READY
}
}.stateIn(
scope = scope,
started = SharingStarted.Eagerly,
initialValue = ShizukuAvailability.UNAVAILABLE,
)
override fun requestShizukuPermission() {
shizukuServiceManager.requestPermission()
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/shizuku/ShizukuInstallerServiceImpl.kt
================================================
package zed.rainxch.core.data.services.shizuku
import android.os.ParcelFileDescriptor
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.concurrent.TimeUnit
/**
* Shizuku UserService implementation that runs in a privileged process (shell/root).
* Provides silent package install/uninstall via `pm` shell commands.
*
* This class runs in Shizuku's process, NOT in the app's process.
* It has shell-level (UID 2000) or root-level (UID 0) privileges.
*
* Uses `pm install` with stdin pipe for install, `pm uninstall` for uninstall.
* This is the most reliable approach — avoids fragile reflection on hidden
* IPackageInstaller/IPackageInstallerSession/IIntentSender APIs.
*
* MUST have a default no-arg constructor for Shizuku's UserService framework.
*/
class ShizukuInstallerServiceImpl() : IShizukuInstallerService.Stub() {
companion object {
private const val TAG = "ShizukuService"
private const val STATUS_SUCCESS = 0
private const val STATUS_FAILURE = -1
private const val INSTALL_TIMEOUT_SECONDS = 120L
private const val UNINSTALL_TIMEOUT_SECONDS = 30L
private fun log(msg: String) = android.util.Log.d(TAG, msg)
private fun logW(msg: String) = android.util.Log.w(TAG, msg)
private fun logE(msg: String, e: Throwable? = null) = android.util.Log.e(TAG, msg, e)
}
override fun installPackage(pfd: ParcelFileDescriptor, fileSize: Long): Int {
log("installPackage() called — fileSize=$fileSize")
log("Process UID: ${android.os.Process.myUid()}, PID: ${android.os.Process.myPid()}")
return try {
// Use "pm install -S " which reads the APK from stdin
val command = arrayOf("pm", "install", "-S", fileSize.toString())
log("Executing: ${command.joinToString(" ")}")
val process = Runtime.getRuntime().exec(command)
// Pipe the APK from the ParcelFileDescriptor to pm's stdin
val writeThread = Thread {
try {
ParcelFileDescriptor.AutoCloseInputStream(pfd).use { input ->
process.outputStream.use { output ->
val buffer = ByteArray(65536)
var bytesWritten = 0L
var read: Int
while (input.read(buffer).also { read = it } != -1) {
output.write(buffer, 0, read)
bytesWritten += read
}
output.flush()
log("APK piped to pm stdin: $bytesWritten bytes (expected: $fileSize)")
}
}
} catch (e: Exception) {
logE("Error piping APK to pm stdin", e)
}
}
writeThread.start()
// Read stdout/stderr for result
val stdout = BufferedReader(InputStreamReader(process.inputStream)).readText().trim()
val stderr = BufferedReader(InputStreamReader(process.errorStream)).readText().trim()
writeThread.join(INSTALL_TIMEOUT_SECONDS * 1000)
if (writeThread.isAlive) {
logE("Write thread timed out after ${INSTALL_TIMEOUT_SECONDS}s, aborting install")
writeThread.interrupt()
process.destroyForcibly()
return STATUS_FAILURE
}
val finished = process.waitFor(INSTALL_TIMEOUT_SECONDS, TimeUnit.SECONDS)
if (!finished) {
logE("pm install timed out after ${INSTALL_TIMEOUT_SECONDS}s, aborting")
process.destroyForcibly()
return STATUS_FAILURE
}
val exitCode = process.exitValue()
log("pm install — exitCode=$exitCode, stdout='$stdout', stderr='$stderr'")
if (exitCode == 0 && stdout.contains("Success")) {
log("Install SUCCESS")
STATUS_SUCCESS
} else {
logE("Install FAILED — exitCode=$exitCode, stdout='$stdout', stderr='$stderr'")
STATUS_FAILURE
}
} catch (e: Exception) {
logE("installPackage() exception", e)
STATUS_FAILURE
}
}
override fun uninstallPackage(packageName: String): Int {
log("uninstallPackage() called for: $packageName")
return try {
val command = arrayOf("pm", "uninstall", packageName)
log("Executing: ${command.joinToString(" ")}")
val process = Runtime.getRuntime().exec(command)
val stdout = BufferedReader(InputStreamReader(process.inputStream)).readText().trim()
val stderr = BufferedReader(InputStreamReader(process.errorStream)).readText().trim()
val finished = process.waitFor(UNINSTALL_TIMEOUT_SECONDS, TimeUnit.SECONDS)
if (!finished) {
logE("pm uninstall timed out after ${UNINSTALL_TIMEOUT_SECONDS}s, aborting")
process.destroyForcibly()
return STATUS_FAILURE
}
val exitCode = process.exitValue()
log("pm uninstall — exitCode=$exitCode, stdout='$stdout', stderr='$stderr'")
if (exitCode == 0 && stdout.contains("Success")) {
log("Uninstall SUCCESS")
STATUS_SUCCESS
} else {
logE("Uninstall FAILED — exitCode=$exitCode, stdout='$stdout', stderr='$stderr'")
STATUS_FAILURE
}
} catch (e: Exception) {
logE("uninstallPackage() exception", e)
STATUS_FAILURE
}
}
override fun destroy() {
log("destroy() — service being unbound")
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/shizuku/ShizukuInstallerWrapper.kt
================================================
package zed.rainxch.core.data.services.shizuku
import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import zed.rainxch.core.data.services.shizuku.model.ShizukuStatus
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.InstallerType
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor
/**
* Wrapper around [Installer] that transparently intercepts `install()` and `uninstall()`
* calls to use Shizuku when available and enabled by the user.
*
* All other methods (asset selection, architecture detection, Obtainium/AppManager support)
* delegate directly to the underlying [androidInstaller] unchanged.
*
* Fallback behavior: if Shizuku install/uninstall fails for any reason, falls back
* to the standard [androidInstaller] implementation silently.
*/
class ShizukuInstallerWrapper(
private val androidInstaller: Installer,
private val shizukuServiceManager: ShizukuServiceManager,
private val tweaksRepository: TweaksRepository,
) : Installer {
companion object {
private const val TAG = "ShizukuInstaller"
}
/**
* Cached installer type preference, updated by flow collection.
* Defaults to DEFAULT so Shizuku is never used unless explicitly opted in.
*/
@Volatile
private var cachedInstallerType: InstallerType = InstallerType.DEFAULT
/**
* Start observing the installer type preference from DataStore.
* Call once after construction (from DI setup).
*/
fun observeInstallerPreference(scope: CoroutineScope) {
scope.launch {
tweaksRepository.getInstallerType().collect { type ->
cachedInstallerType = type
Logger.d(TAG) { "Installer type changed to: $type" }
}
}
}
override suspend fun isSupported(extOrMime: String): Boolean = androidInstaller.isSupported(extOrMime)
override fun isAssetInstallable(assetName: String): Boolean = androidInstaller.isAssetInstallable(assetName)
override fun choosePrimaryAsset(assets: List): GithubAsset? = androidInstaller.choosePrimaryAsset(assets)
override fun detectSystemArchitecture(): SystemArchitecture = androidInstaller.detectSystemArchitecture()
override fun isObtainiumInstalled(): Boolean = androidInstaller.isObtainiumInstalled()
override fun openInObtainium(
repoOwner: String,
repoName: String,
onOpenInstaller: () -> Unit,
) = androidInstaller.openInObtainium(repoOwner, repoName, onOpenInstaller)
override fun isAppManagerInstalled(): Boolean = androidInstaller.isAppManagerInstalled()
override fun openInAppManager(
filePath: String,
onOpenInstaller: () -> Unit,
) = androidInstaller.openInAppManager(filePath, onOpenInstaller)
override fun getApkInfoExtractor(): InstallerInfoExtractor = androidInstaller.getApkInfoExtractor()
override fun openApp(packageName: String): Boolean = androidInstaller.openApp(packageName)
override fun openWithExternalInstaller(filePath: String) = androidInstaller.openWithExternalInstaller(filePath)
override suspend fun ensurePermissionsOrThrow(extOrMime: String) {
Logger.d(TAG) {
"ensurePermissionsOrThrow() — extOrMime=$extOrMime, cachedType=$cachedInstallerType, status=${shizukuServiceManager.status.value}"
}
if (shouldUseShizuku()) {
Logger.d(TAG) { "Shizuku active — skipping unknown sources permission check" }
return
}
Logger.d(TAG) { "Delegating ensurePermissionsOrThrow to AndroidInstaller" }
androidInstaller.ensurePermissionsOrThrow(extOrMime)
}
override suspend fun install(
filePath: String,
extOrMime: String,
) {
Logger.d(TAG) { "install() called — filePath=$filePath, extOrMime=$extOrMime" }
Logger.d(TAG) { "cachedInstallerType=$cachedInstallerType, shizukuStatus=${shizukuServiceManager.status.value}" }
if (shouldUseShizuku()) {
Logger.d(TAG) { "Shizuku is enabled and READY — attempting Shizuku install" }
try {
val service = shizukuServiceManager.getService()
if (service != null) {
val result =
withContext(Dispatchers.IO) {
val file = java.io.File(filePath)
val pfd =
android.os.ParcelFileDescriptor.open(
file,
android.os.ParcelFileDescriptor.MODE_READ_ONLY,
)
pfd.use {
Logger.d(TAG) { "Got Shizuku service, calling installPackage($filePath, size=${file.length()})..." }
service.installPackage(it, file.length())
}
}
Logger.d(TAG) { "Shizuku installPackage() returned: $result" }
if (result == 0) {
Logger.d(TAG) { "Shizuku install SUCCEEDED for: $filePath" }
return
}
Logger.w(TAG) { "Shizuku install FAILED with code: $result, falling back to standard installer" }
} else {
Logger.w(TAG) { "Shizuku service is NULL, falling back to standard installer" }
}
} catch (e: Exception) {
Logger.e(TAG) { "Shizuku install exception, falling back: ${e.javaClass.simpleName}: ${e.message}" }
}
} else {
Logger.d(TAG) { "Not using Shizuku (enabled=${isShizukuEnabled()}, status=${shizukuServiceManager.status.value})" }
}
Logger.d(TAG) { "Using standard AndroidInstaller for: $filePath" }
androidInstaller.ensurePermissionsOrThrow(extOrMime)
androidInstaller.install(filePath, extOrMime)
}
override fun uninstall(packageName: String) {
Logger.d(TAG) { "uninstall() called — packageName=$packageName" }
Logger.d(TAG) { "cachedInstallerType=$cachedInstallerType, shizukuStatus=${shizukuServiceManager.status.value}" }
if (isShizukuEnabled() && shizukuServiceManager.status.value == ShizukuStatus.READY) {
Logger.d(TAG) { "Attempting Shizuku uninstall..." }
Thread {
try {
val service = runBlocking { shizukuServiceManager.getService() }
if (service != null) {
Logger.d(TAG) { "Got service, calling uninstallPackage($packageName)..." }
val result = service.uninstallPackage(packageName)
Logger.d(TAG) { "Shizuku uninstallPackage() returned: $result" }
if (result == 0) {
Logger.d(TAG) { "Shizuku uninstall SUCCEEDED for: $packageName" }
} else {
Logger.w(TAG) { "Shizuku uninstall FAILED with code: $result, falling back" }
androidInstaller.uninstall(packageName)
}
} else {
Logger.w(TAG) { "Shizuku service is NULL, falling back" }
androidInstaller.uninstall(packageName)
}
} catch (e: Exception) {
Logger.e(TAG) { "Shizuku uninstall exception, falling back: ${e.message}" }
androidInstaller.uninstall(packageName)
}
}.start()
return
}
Logger.d(TAG) { "Using standard AndroidInstaller uninstall for: $packageName" }
androidInstaller.uninstall(packageName)
}
private suspend fun shouldUseShizuku(): Boolean = isShizukuEnabled() && shizukuServiceManager.status.value == ShizukuStatus.READY
private fun isShizukuEnabled(): Boolean = cachedInstallerType == InstallerType.SHIZUKU
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/shizuku/ShizukuServiceManager.kt
================================================
package zed.rainxch.core.data.services.shizuku
import android.content.ComponentName
import android.content.Context
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.os.IBinder
import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withTimeoutOrNull
import rikka.shizuku.Shizuku
import zed.rainxch.core.data.services.shizuku.model.ShizukuStatus
import kotlin.coroutines.resume
class ShizukuServiceManager(
private val context: Context,
) {
private val _status = MutableStateFlow(ShizukuStatus.NOT_INSTALLED)
val status: StateFlow = _status.asStateFlow()
private val bindMutex = Mutex()
private var serviceConnection: ServiceConnection? = null
private var boundUserServiceArgs: Shizuku.UserServiceArgs? = null
@Volatile
var installerService: IShizukuInstallerService? = null
private set
private val binderReceivedListener =
Shizuku.OnBinderReceivedListener {
Logger.d(TAG) { "Shizuku binder received" }
refreshStatus()
}
private val binderDeadListener =
Shizuku.OnBinderDeadListener {
Logger.d(TAG) { "Shizuku binder dead" }
installerService = null
refreshStatus()
}
private val permissionResultListener =
Shizuku.OnRequestPermissionResultListener { requestCode, grantResult ->
Logger.d(TAG) {
"Shizuku permission result: requestCode=$requestCode," +
" granted=${grantResult == PackageManager.PERMISSION_GRANTED}"
}
refreshStatus()
}
fun initialize() {
try {
Shizuku.addBinderReceivedListenerSticky(binderReceivedListener)
Shizuku.addBinderDeadListener(binderDeadListener)
Shizuku.addRequestPermissionResultListener(permissionResultListener)
} catch (e: Exception) {
Logger.w(TAG) { "Failed to register Shizuku listeners: ${e.message}" }
}
refreshStatus()
}
fun refreshStatus() {
_status.value = computeStatus()
}
private fun computeStatus(): ShizukuStatus {
val installed = isShizukuInstalled()
Logger.d(TAG) { "computeStatus() — shizukuInstalled=$installed" }
if (!installed) return ShizukuStatus.NOT_INSTALLED
return try {
val binderAlive = Shizuku.pingBinder()
Logger.d(TAG) { "computeStatus() — pingBinder=$binderAlive" }
if (!binderAlive) return ShizukuStatus.NOT_RUNNING
val permResult = Shizuku.checkSelfPermission()
Logger.d(TAG) { "computeStatus() — checkSelfPermission=$permResult (GRANTED=${PackageManager.PERMISSION_GRANTED})" }
if (permResult != PackageManager.PERMISSION_GRANTED) {
return ShizukuStatus.PERMISSION_NEEDED
}
Logger.d(TAG) { "computeStatus() — READY" }
ShizukuStatus.READY
} catch (e: Exception) {
Logger.w(TAG) { "Error checking Shizuku status: ${e.javaClass.simpleName}: ${e.message}" }
ShizukuStatus.NOT_RUNNING
}
}
private fun isShizukuInstalled(): Boolean =
try {
context.packageManager.getPackageInfo(SHIZUKU_PACKAGE, 0)
true
} catch (_: PackageManager.NameNotFoundException) {
false
} catch (_: Exception) {
false
}
fun requestPermission() {
try {
if (Shizuku.pingBinder()) {
Shizuku.requestPermission(SHIZUKU_PERMISSION_REQUEST_CODE)
}
} catch (e: Exception) {
Logger.w(TAG) { "Failed to request Shizuku permission: ${e.message}" }
}
}
suspend fun getService(): IShizukuInstallerService? {
Logger.d(TAG) { "getService() — current status=${_status.value}" }
if (_status.value != ShizukuStatus.READY) {
Logger.w(TAG) { "getService() — Shizuku not READY (status=${_status.value}), returning null" }
return null
}
return bindMutex.withLock {
installerService?.let { service ->
try {
val alive = service.asBinder().pingBinder()
Logger.d(TAG) { "getService() — cached service ping=$alive" }
if (alive) return@withLock service
Logger.w(TAG) { "getService() — cached service binder dead, rebinding..." }
installerService = null
} catch (e: Exception) {
Logger.w(TAG) { "getService() — cached service error: ${e.message}, rebinding..." }
installerService = null
}
} ?: run {
Logger.d(TAG) { "getService() — no cached service, binding..." }
}
bindService()
}
}
private suspend fun bindService(): IShizukuInstallerService? {
Logger.d(TAG) { "bindService() — attempting to bind Shizuku UserService..." }
return try {
withTimeoutOrNull(BIND_TIMEOUT_MS) {
suspendCancellableCoroutine { continuation ->
val componentName =
ComponentName(
context.packageName,
ShizukuInstallerServiceImpl::class.java.name,
)
Logger.d(TAG) { "bindService() — component: $componentName" }
val args =
Shizuku
.UserServiceArgs(componentName)
.daemon(false)
.processNameSuffix("installer")
.version(1)
val connection =
object : ServiceConnection {
override fun onServiceConnected(
name: ComponentName?,
binder: IBinder?,
) {
Logger.d(
TAG,
) {
"onServiceConnected() — name=$name, binder=${binder?.javaClass?.name}, binderAlive=${binder?.pingBinder()}"
}
val service = IShizukuInstallerService.Stub.asInterface(binder)
installerService = service
Logger.d(TAG) { "Shizuku installer service connected and cached" }
if (continuation.isActive) {
continuation.resume(service)
}
}
override fun onServiceDisconnected(name: ComponentName?) {
installerService = null
Logger.d(TAG) { "Shizuku installer service disconnected: $name" }
}
}
serviceConnection = connection
boundUserServiceArgs = args
Logger.d(TAG) { "Calling Shizuku.bindUserService()..." }
Shizuku.bindUserService(args, connection)
Logger.d(TAG) { "Shizuku.bindUserService() called, waiting for callback..." }
continuation.invokeOnCancellation {
Logger.d(TAG) { "bindService() coroutine cancelled, unbinding..." }
try {
Shizuku.unbindUserService(args, connection, true)
} catch (_: Exception) {
}
}
}
}.also { service ->
if (service == null) {
Logger.w(TAG) { "bindService() timed out after ${BIND_TIMEOUT_MS}ms" }
}
}
} catch (e: Exception) {
Logger.e(TAG) { "Failed to bind Shizuku service: ${e.javaClass.simpleName}: ${e.message}" }
Logger.e(TAG) { e.stackTraceToString() }
null
}
}
companion object {
private const val TAG = "ShizukuServiceManager"
private const val SHIZUKU_PACKAGE = "moe.shizuku.privileged.api"
private const val BIND_TIMEOUT_MS = 15_000L
const val SHIZUKU_PERMISSION_REQUEST_CODE = 1001
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/shizuku/model/ShizukuStatus.kt
================================================
package zed.rainxch.core.data.services.shizuku.model
enum class ShizukuStatus {
NOT_INSTALLED,
NOT_RUNNING,
PERMISSION_NEEDED,
READY,
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/utils/AndroidAppLauncher.kt
================================================
package zed.rainxch.core.data.utils
import android.content.Context
import android.content.Intent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import zed.rainxch.core.domain.logging.GitHubStoreLogger
import zed.rainxch.core.domain.model.InstalledApp
import zed.rainxch.core.domain.utils.AppLauncher
class AndroidAppLauncher(
private val context: Context,
private val logger: GitHubStoreLogger,
) : AppLauncher {
override suspend fun launchApp(installedApp: InstalledApp): Result =
withContext(Dispatchers.Main) {
runCatching {
val packageManager = context.packageManager
val launchIntent = packageManager.getLaunchIntentForPackage(installedApp.packageName)
if (launchIntent != null) {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(launchIntent)
logger.debug("Launched app: ${installedApp.packageName}")
} else {
throw Exception("No launch intent found for ${installedApp.packageName}")
}
}.onFailure { error ->
logger.error("Failed to launch app ${installedApp.packageName}: ${error.message}")
}
}
override suspend fun canLaunchApp(installedApp: InstalledApp): Boolean =
withContext(Dispatchers.IO) {
try {
val packageManager = context.packageManager
packageManager.getLaunchIntentForPackage(installedApp.packageName) != null
} catch (e: Exception) {
false
}
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/utils/AndroidBrowserHelper.kt
================================================
package zed.rainxch.core.data.utils
import android.content.Context
import android.content.Intent
import androidx.core.net.toUri
import zed.rainxch.core.domain.utils.BrowserHelper
class AndroidBrowserHelper(
private val context: Context,
) : BrowserHelper {
override fun openUrl(
url: String,
onFailure: (error: String) -> Unit,
) {
val intent =
Intent(Intent.ACTION_VIEW, url.toUri()).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/utils/AndroidClipboardHelper.kt
================================================
package zed.rainxch.core.data.utils
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import zed.rainxch.core.domain.utils.ClipboardHelper
class AndroidClipboardHelper(
private val context: Context,
) : ClipboardHelper {
override fun copy(
label: String,
text: String,
) {
val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
cm.setPrimaryClip(ClipData.newPlainText(label, text))
}
override fun getText(): String? {
val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = cm.primaryClip ?: return null
if (clip.itemCount == 0) return null
return clip.getItemAt(0).text?.toString()
}
}
================================================
FILE: core/data/src/androidMain/kotlin/zed/rainxch/core/data/utils/AndroidShareManager.kt
================================================
package zed.rainxch.core.data.utils
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.FileProvider
import zed.rainxch.core.domain.utils.ShareManager
import java.io.File
class AndroidShareManager(
private val context: Context,
) : ShareManager {
private var filePickerCallback: ((String?) -> Unit)? = null
private var filePickerLauncher: ActivityResultLauncher? = null
fun registerActivityResultLauncher(activity: ComponentActivity) {
filePickerLauncher = activity.registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
val callback = filePickerCallback
filePickerCallback = null
if (result.resultCode == Activity.RESULT_OK) {
val uri = result.data?.data
if (uri != null) {
try {
val content = context.contentResolver.openInputStream(uri)
?.bufferedReader()
?.use { it.readText() }
callback?.invoke(content)
} catch (e: Exception) {
callback?.invoke(null)
}
} else {
callback?.invoke(null)
}
} else {
callback?.invoke(null)
}
}
}
override fun shareText(text: String) {
val intent =
Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, text)
}
val chooser =
Intent.createChooser(intent, null).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(chooser)
}
override fun shareFile(fileName: String, content: String, mimeType: String) {
val cacheDir = File(context.cacheDir, "exports")
cacheDir.mkdirs()
val file = File(cacheDir, fileName)
file.writeText(content)
val uri: Uri = FileProvider.getUriForFile(
context,
"${context.packageName}.fileprovider",
file
)
val intent = Intent(Intent.ACTION_SEND).apply {
type = mimeType
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
val chooser = Intent.createChooser(intent, null).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(chooser)
}
override fun pickFile(mimeType: String, onResult: (String?) -> Unit) {
filePickerCallback = onResult
val launcher = filePickerLauncher
if (launcher != null) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = mimeType
}
launcher.launch(intent)
} else {
// Fallback: try with ACTION_GET_CONTENT
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = mimeType
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(Intent.createChooser(intent, null).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
// Note: fallback won't deliver result without launcher
onResult(null)
} catch (e: Exception) {
onResult(null)
}
}
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/cache/CacheManager.kt
================================================
package zed.rainxch.core.data.cache
import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer
import zed.rainxch.core.data.local.db.dao.CacheDao
import zed.rainxch.core.data.local.db.entities.CacheEntryEntity
import kotlin.time.Clock
import kotlin.time.Duration.Companion.hours
class CacheManager(
val cacheDao: CacheDao,
) {
val json =
Json {
ignoreUnknownKeys = true
isLenient = true
encodeDefaults = true
}
val memoryCache = HashMap>()
fun now(): Long = Clock.System.now().toEpochMilliseconds()
suspend inline fun get(key: String): T? {
val currentTime = now()
memoryCache[key]?.let { (expiresAt, jsonData) ->
if (expiresAt > currentTime) {
return try {
json.decodeFromString(serializer(), jsonData)
} catch (_: Exception) {
memoryCache.remove(key)
null
}
} else {
memoryCache.remove(key)
}
}
val entry = cacheDao.getValid(key, currentTime) ?: return null
memoryCache[key] = entry.expiresAt to entry.jsonData
return try {
json.decodeFromString(serializer(), entry.jsonData)
} catch (_: Exception) {
cacheDao.delete(key)
memoryCache.remove(key)
null
}
}
suspend inline fun getStale(key: String): T? {
val entry = cacheDao.getAny(key) ?: return null
return try {
json.decodeFromString(serializer(), entry.jsonData)
} catch (_: Exception) {
null
}
}
suspend inline fun put(
key: String,
value: T,
ttlMillis: Long,
) {
val currentTime = now()
val jsonData = json.encodeToString(serializer(), value)
val expiresAt = currentTime + ttlMillis
memoryCache[key] = expiresAt to jsonData
cacheDao.put(
CacheEntryEntity(
key = key,
jsonData = jsonData,
cachedAt = currentTime,
expiresAt = expiresAt,
),
)
}
suspend fun invalidate(key: String) {
memoryCache.remove(key)
cacheDao.delete(key)
}
suspend fun invalidateByPrefix(prefix: String) {
val keysToRemove = memoryCache.keys.filter { it.startsWith(prefix) }
keysToRemove.forEach { memoryCache.remove(it) }
cacheDao.deleteByPrefix(prefix)
}
suspend fun clearAll() {
memoryCache.clear()
cacheDao.deleteAll()
}
suspend fun cleanupExpired() {
val currentTime = now()
val expiredKeys =
memoryCache.entries
.filter { it.value.first <= currentTime }
.map { it.key }
expiredKeys.forEach { memoryCache.remove(it) }
cacheDao.deleteExpired(currentTime)
}
companion object CacheTtl {
val HOME_REPOS = 12.hours.inWholeMilliseconds
val REPO_DETAILS = 6.hours.inWholeMilliseconds
val RELEASES = 6.hours.inWholeMilliseconds
val README = 12.hours.inWholeMilliseconds
val USER_PROFILE = 6.hours.inWholeMilliseconds
val SEARCH_RESULTS = 1.hours.inWholeMilliseconds
val REPO_STATS = 6.hours.inWholeMilliseconds
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/data_source/TokenStore.kt
================================================
package zed.rainxch.core.data.data_source
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.dto.GithubDeviceTokenSuccessDto
interface TokenStore {
fun tokenFlow(): Flow
suspend fun currentToken(): GithubDeviceTokenSuccessDto?
fun blockingCurrentToken(): GithubDeviceTokenSuccessDto?
suspend fun save(token: GithubDeviceTokenSuccessDto)
suspend fun clear()
suspend fun isTokenExpired(): Boolean
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/data_source/impl/DefaultTokenStore.kt
================================================
package zed.rainxch.core.data.data_source.impl
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import zed.rainxch.core.data.data_source.TokenStore
import zed.rainxch.core.data.dto.GithubDeviceTokenSuccessDto
import kotlin.time.Clock
class DefaultTokenStore(
private val dataStore: DataStore,
) : TokenStore {
private val TOKEN_KEY = stringPreferencesKey("token")
private val json = Json { ignoreUnknownKeys = true }
override suspend fun save(token: GithubDeviceTokenSuccessDto) {
val stamped =
token.copy(
savedAtEpochMillis = token.savedAtEpochMillis ?: Clock.System.now().toEpochMilliseconds(),
)
val jsonString = json.encodeToString(GithubDeviceTokenSuccessDto.serializer(), stamped)
dataStore.edit { preferences ->
preferences[TOKEN_KEY] = jsonString
}
}
override fun tokenFlow(): Flow {
return dataStore.data.map { preferences ->
val raw = preferences[TOKEN_KEY] ?: return@map null
runCatching {
json.decodeFromString(GithubDeviceTokenSuccessDto.serializer(), raw)
}.getOrNull()
}
}
override suspend fun currentToken(): GithubDeviceTokenSuccessDto? {
val preferences = dataStore.data.first()
val raw = preferences[TOKEN_KEY] ?: return null
return runCatching {
json.decodeFromString(GithubDeviceTokenSuccessDto.serializer(), raw)
}.getOrNull()
}
override fun blockingCurrentToken(): GithubDeviceTokenSuccessDto? =
runBlocking {
val preferences = dataStore.data.first()
val raw = preferences[TOKEN_KEY] ?: return@runBlocking null
runCatching {
json.decodeFromString(GithubDeviceTokenSuccessDto.serializer(), raw)
}.getOrNull()
}
override suspend fun clear() {
dataStore.edit { it.remove(TOKEN_KEY) }
}
override suspend fun isTokenExpired(): Boolean {
val token = currentToken() ?: return true
val savedAt = token.savedAtEpochMillis ?: return false
val expiresIn = token.expiresIn ?: return false
val expiresAtMillis = savedAt + (expiresIn * 1000L)
return Clock.System.now().toEpochMilliseconds() > expiresAtMillis
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/PlatformModule.kt
================================================
package zed.rainxch.core.data.di
import org.koin.core.module.Module
expect val corePlatformModule: Module
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/SharedModule.kt
================================================
package zed.rainxch.core.data.di
import io.ktor.client.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.koin.dsl.module
import zed.rainxch.core.data.cache.CacheManager
import zed.rainxch.core.data.data_source.TokenStore
import zed.rainxch.core.data.data_source.impl.DefaultTokenStore
import zed.rainxch.core.data.local.db.AppDatabase
import zed.rainxch.core.data.local.db.dao.CacheDao
import zed.rainxch.core.data.local.db.dao.FavoriteRepoDao
import zed.rainxch.core.data.local.db.dao.InstalledAppDao
import zed.rainxch.core.data.local.db.dao.SeenRepoDao
import zed.rainxch.core.data.local.db.dao.StarredRepoDao
import zed.rainxch.core.data.local.db.dao.UpdateHistoryDao
import zed.rainxch.core.data.logging.KermitLogger
import zed.rainxch.core.data.network.GitHubClientProvider
import zed.rainxch.core.data.network.ProxyManager
import zed.rainxch.core.data.network.createGitHubHttpClient
import zed.rainxch.core.data.repository.AuthenticationStateImpl
import zed.rainxch.core.data.repository.FavouritesRepositoryImpl
import zed.rainxch.core.data.repository.InstalledAppsRepositoryImpl
import zed.rainxch.core.data.repository.ProxyRepositoryImpl
import zed.rainxch.core.data.repository.RateLimitRepositoryImpl
import zed.rainxch.core.data.repository.SeenReposRepositoryImpl
import zed.rainxch.core.data.repository.StarredRepositoryImpl
import zed.rainxch.core.data.repository.TweaksRepositoryImpl
import zed.rainxch.core.domain.getPlatform
import zed.rainxch.core.domain.logging.GitHubStoreLogger
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.repository.AuthenticationState
import zed.rainxch.core.domain.repository.FavouritesRepository
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.ProxyRepository
import zed.rainxch.core.domain.repository.RateLimitRepository
import zed.rainxch.core.domain.repository.SeenReposRepository
import zed.rainxch.core.domain.repository.StarredRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.use_cases.SyncInstalledAppsUseCase
val coreModule =
module {
single {
CoroutineScope(Dispatchers.IO + SupervisorJob())
}
single {
KermitLogger
}
single {
getPlatform()
}
single {
AuthenticationStateImpl(
tokenStore = get(),
)
}
single {
FavouritesRepositoryImpl(
favoriteRepoDao = get(),
installedAppsDao = get(),
)
}
single {
InstalledAppsRepositoryImpl(
database = get(),
installedAppsDao = get(),
historyDao = get(),
installer = get(),
httpClient = get(),
tweaksRepository = get(),
)
}
single {
StarredRepositoryImpl(
installedAppsDao = get(),
starredRepoDao = get(),
platform = get(),
httpClient = get(),
)
}
single {
TweaksRepositoryImpl(
preferences = get(),
)
}
single {
SeenReposRepositoryImpl(
seenRepoDao = get(),
)
}
single {
ProxyRepositoryImpl(
preferences = get(),
)
}
single {
SyncInstalledAppsUseCase(
packageMonitor = get(),
installedAppsRepository = get(),
platform = get(),
logger = get(),
)
}
single {
CacheManager(cacheDao = get())
}
}
val networkModule =
module {
single {
val config =
runBlocking {
runCatching {
withTimeout(1_500L) {
get().getProxyConfig().first()
}
}.getOrDefault(ProxyConfig.None)
}
when (config) {
is ProxyConfig.None -> {
ProxyManager.setNoProxy()
}
is ProxyConfig.System -> {
ProxyManager.setSystemProxy()
}
is ProxyConfig.Http -> {
ProxyManager.setHttpProxy(
host = config.host,
port = config.port,
username = config.username,
password = config.password,
)
}
is ProxyConfig.Socks -> {
ProxyManager.setSocksProxy(
host = config.host,
port = config.port,
username = config.username,
password = config.password,
)
}
}
GitHubClientProvider(
tokenStore = get(),
rateLimitRepository = get(),
authenticationState = get(),
proxyConfigFlow = ProxyManager.currentProxyConfig,
)
}
single {
createGitHubHttpClient(
tokenStore = get(),
rateLimitRepository = get(),
authenticationState = get(),
scope = get(),
)
}
single {
DefaultTokenStore(
dataStore = get(),
)
}
single {
RateLimitRepositoryImpl()
}
}
val databaseModule =
module {
single {
get().favoriteRepoDao
}
single {
get().installedAppDao
}
single {
get().starredReposDao
}
single {
get().updateHistoryDao
}
single {
get().cacheDao
}
single {
get().seenRepoDao
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/AssetNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class AssetNetwork(
@SerialName("id") val id: Long,
@SerialName("name") val name: String,
@SerialName("content_type") val contentType: String,
@SerialName("size") val size: Long,
@SerialName("browser_download_url") val downloadUrl: String,
@SerialName("uploader") val uploader: OwnerNetwork,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GitHubStarredResponse.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GitHubStarredResponse(
val id: Long,
val name: String,
val owner: Owner,
val description: String?,
val language: String?,
@SerialName("html_url") val htmlUrl: String,
@SerialName("stargazers_count") val stargazersCount: Int,
@SerialName("forks_count") val forksCount: Int,
@SerialName("open_issues_count") val openIssuesCount: Int,
@SerialName("starred_at") val starredAt: String? = null,
) {
@Serializable
data class Owner(
val login: String,
@SerialName("avatar_url") val avatarUrl: String,
)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubDeviceStartDto.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubDeviceStartDto(
@SerialName("device_code") val deviceCode: String,
@SerialName("user_code") val userCode: String,
@SerialName("verification_uri") val verificationUri: String,
@SerialName("verification_uri_complete") val verificationUriComplete: String? = null,
@SerialName("interval") val intervalSec: Int = 5,
@SerialName("expires_in") val expiresInSec: Int,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubDeviceTokenErrorDto.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubDeviceTokenErrorDto(
@SerialName("error") val error: String,
@SerialName("error_description") val errorDescription: String? = null,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubDeviceTokenSuccessDto.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubDeviceTokenSuccessDto(
@SerialName("access_token") val accessToken: String,
@SerialName("token_type") val tokenType: String,
@SerialName("expires_in") val expiresIn: Long? = null,
@SerialName("scope") val scope: String? = null,
@SerialName("refresh_token") val refreshToken: String? = null,
@SerialName("refresh_token_expires_in") val refreshTokenExpiresIn: Long? = null,
@SerialName("saved_at") val savedAtEpochMillis: Long? = null,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubOwnerNetworkModel.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubOwnerNetworkModel(
@SerialName("id") val id: Long,
@SerialName("login") val login: String,
@SerialName("avatar_url") val avatarUrl: String,
@SerialName("html_url") val htmlUrl: String,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubRepoNetworkModel.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubRepoNetworkModel(
@SerialName("id") val id: Long,
@SerialName("name") val name: String,
@SerialName("full_name") val fullName: String,
@SerialName("owner") val owner: GithubOwnerNetworkModel,
@SerialName("description") val description: String? = null,
@SerialName("default_branch") val defaultBranch: String,
@SerialName("html_url") val htmlUrl: String,
@SerialName("stargazers_count") val stargazersCount: Int,
@SerialName("forks_count") val forksCount: Int,
@SerialName("language") val language: String? = null,
@SerialName("topics") val topics: List? = null,
@SerialName("releases_url") val releasesUrl: String,
@SerialName("updated_at") val updatedAt: String,
@SerialName("fork") val fork: Boolean = false,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubRepoSearchResponse.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class GithubRepoSearchResponse(
@SerialName("total_count") val totalCount: Int,
@SerialName("items") val items: List,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/OwnerNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class OwnerNetwork(
@SerialName("id") val id: Long,
@SerialName("login") val login: String,
@SerialName("avatar_url") val avatarUrl: String,
@SerialName("html_url") val htmlUrl: String,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/ReleaseNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ReleaseNetwork(
@SerialName("id") val id: Long,
@SerialName("tag_name") val tagName: String,
@SerialName("name") val name: String? = null,
@SerialName("draft") val draft: Boolean? = null,
@SerialName("prerelease") val prerelease: Boolean? = null,
@SerialName("author") val author: OwnerNetwork,
@SerialName("published_at") val publishedAt: String? = null,
@SerialName("created_at") val createdAt: String? = null,
@SerialName("body") val body: String? = null,
@SerialName("tarball_url") val tarballUrl: String,
@SerialName("zipball_url") val zipballUrl: String,
@SerialName("html_url") val htmlUrl: String,
@SerialName("assets") val assets: List,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/RepoByIdNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class RepoByIdNetwork(
@SerialName("id") val id: Long,
@SerialName("name") val name: String,
@SerialName("full_name") val fullName: String,
@SerialName("owner") val owner: OwnerNetwork,
@SerialName("description") val description: String? = null,
@SerialName("default_branch") val defaultBranch: String,
@SerialName("html_url") val htmlUrl: String,
@SerialName("stargazers_count") val stars: Int,
@SerialName("forks_count") val forks: Int,
@SerialName("language") val language: String? = null,
@SerialName("topics") val topics: List? = null,
@SerialName("updated_at") val updatedAt: String,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/RepoInfoNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class RepoInfoNetwork(
@SerialName("stargazers_count") val stars: Int,
@SerialName("forks_count") val forks: Int,
@SerialName("open_issues_count") val openIssues: Int,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/UserProfileNetwork.kt
================================================
package zed.rainxch.core.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class UserProfileNetwork(
@SerialName("id") val id: Long,
@SerialName("login") val login: String,
@SerialName("name") val name: String? = null,
@SerialName("bio") val bio: String? = null,
@SerialName("avatar_url") val avatarUrl: String,
@SerialName("html_url") val htmlUrl: String,
@SerialName("followers") val followers: Int,
@SerialName("following") val following: Int,
@SerialName("public_repos") val publicRepos: Int,
@SerialName("location") val location: String? = null,
@SerialName("company") val company: String? = null,
@SerialName("blog") val blog: String? = null,
@SerialName("twitter_username") val twitterUsername: String? = null,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/data_store/createDataStoreCore.kt
================================================
package zed.rainxch.core.data.local.data_store
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import okio.Path.Companion.toPath
fun createDataStore(producePath: () -> String): DataStore =
PreferenceDataStoreFactory.createWithPath(
produceFile = { producePath().toPath() },
)
internal const val dataStoreFileName = "github_store.preferences_pb"
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/AppDatabase.kt
================================================
package zed.rainxch.core.data.local.db
import androidx.room.Database
import androidx.room.RoomDatabase
import zed.rainxch.core.data.local.db.dao.CacheDao
import zed.rainxch.core.data.local.db.dao.FavoriteRepoDao
import zed.rainxch.core.data.local.db.dao.InstalledAppDao
import zed.rainxch.core.data.local.db.dao.SeenRepoDao
import zed.rainxch.core.data.local.db.dao.StarredRepoDao
import zed.rainxch.core.data.local.db.dao.UpdateHistoryDao
import zed.rainxch.core.data.local.db.entities.CacheEntryEntity
import zed.rainxch.core.data.local.db.entities.FavoriteRepoEntity
import zed.rainxch.core.data.local.db.entities.InstalledAppEntity
import zed.rainxch.core.data.local.db.entities.SeenRepoEntity
import zed.rainxch.core.data.local.db.entities.StarredRepositoryEntity
import zed.rainxch.core.data.local.db.entities.UpdateHistoryEntity
@Database(
entities = [
InstalledAppEntity::class,
FavoriteRepoEntity::class,
UpdateHistoryEntity::class,
StarredRepositoryEntity::class,
CacheEntryEntity::class,
SeenRepoEntity::class,
],
version = 6,
exportSchema = true,
)
abstract class AppDatabase : RoomDatabase() {
abstract val installedAppDao: InstalledAppDao
abstract val favoriteRepoDao: FavoriteRepoDao
abstract val updateHistoryDao: UpdateHistoryDao
abstract val starredReposDao: StarredRepoDao
abstract val cacheDao: CacheDao
abstract val seenRepoDao: SeenRepoDao
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/CacheDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import zed.rainxch.core.data.local.db.entities.CacheEntryEntity
@Dao
interface CacheDao {
@Query("SELECT * FROM cache_entries WHERE `key` = :key AND expiresAt > :now LIMIT 1")
suspend fun getValid(
key: String,
now: Long,
): CacheEntryEntity?
@Query("SELECT * FROM cache_entries WHERE `key` = :key LIMIT 1")
suspend fun getAny(key: String): CacheEntryEntity?
@Query("SELECT * FROM cache_entries WHERE `key` LIKE :prefix || '%' AND expiresAt > :now")
suspend fun getValidByPrefix(
prefix: String,
now: Long,
): List
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun put(entry: CacheEntryEntity)
@Query("DELETE FROM cache_entries WHERE `key` = :key")
suspend fun delete(key: String)
@Query("DELETE FROM cache_entries WHERE `key` LIKE :prefix || '%'")
suspend fun deleteByPrefix(prefix: String)
@Query("DELETE FROM cache_entries WHERE expiresAt <= :now")
suspend fun deleteExpired(now: Long)
@Query("DELETE FROM cache_entries")
suspend fun deleteAll()
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/FavoriteRepoDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.local.db.entities.FavoriteRepoEntity
@Dao
interface FavoriteRepoDao {
@Query("SELECT * FROM favorite_repos ORDER BY addedAt DESC")
fun getAllFavorites(): Flow>
@Query("SELECT * FROM favorite_repos WHERE repoId = :repoId")
suspend fun getFavoriteById(repoId: Long): FavoriteRepoEntity?
@Query("SELECT EXISTS(SELECT 1 FROM favorite_repos WHERE repoId = :repoId)")
fun isFavorite(repoId: Long): Flow
@Query("SELECT EXISTS(SELECT 1 FROM favorite_repos WHERE repoId = :repoId)")
suspend fun isFavoriteSync(repoId: Long): Boolean
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertFavorite(repo: FavoriteRepoEntity)
@Delete
suspend fun deleteFavorite(repo: FavoriteRepoEntity)
@Query("DELETE FROM favorite_repos WHERE repoId = :repoId")
suspend fun deleteFavoriteById(repoId: Long)
@Query(
"""
UPDATE favorite_repos
SET isInstalled = :installed,
installedPackageName = :packageName
WHERE repoId = :repoId
""",
)
suspend fun updateInstallStatus(
repoId: Long,
installed: Boolean,
packageName: String?,
)
@Query(
"""
UPDATE favorite_repos
SET latestVersion = :version,
latestReleaseUrl = :releaseUrl,
lastSyncedAt = :timestamp
WHERE repoId = :repoId
""",
)
suspend fun updateLatestVersion(
repoId: Long,
version: String?,
releaseUrl: String?,
timestamp: Long,
)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/InstalledAppDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.local.db.entities.InstalledAppEntity
@Dao
interface InstalledAppDao {
@Query("SELECT * FROM installed_apps ORDER BY installedAt DESC")
fun getAllInstalledApps(): Flow>
@Query("SELECT * FROM installed_apps WHERE isUpdateAvailable = 1 ORDER BY lastCheckedAt DESC")
fun getAppsWithUpdates(): Flow>
@Query("SELECT * FROM installed_apps WHERE packageName = :packageName")
suspend fun getAppByPackage(packageName: String): InstalledAppEntity?
@Query("SELECT * FROM installed_apps WHERE repoId = :repoId")
suspend fun getAppByRepoId(repoId: Long): InstalledAppEntity?
@Query("SELECT * FROM installed_apps WHERE repoId = :repoId")
fun getAppByRepoIdAsFlow(repoId: Long): Flow
@Query("SELECT COUNT(*) FROM installed_apps WHERE isUpdateAvailable = 1")
fun getUpdateCount(): Flow
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertApp(app: InstalledAppEntity)
@Update
suspend fun updateApp(app: InstalledAppEntity)
@Delete
suspend fun deleteApp(app: InstalledAppEntity)
@Query("DELETE FROM installed_apps WHERE packageName = :packageName")
suspend fun deleteByPackageName(packageName: String)
@Query(
"""
UPDATE installed_apps
SET isUpdateAvailable = :available,
latestVersion = :version,
latestAssetName = :assetName,
latestAssetUrl = :assetUrl,
latestAssetSize = :assetSize,
releaseNotes = :releaseNotes,
lastCheckedAt = :timestamp,
latestVersionName = :latestVersionName,
latestVersionCode = :latestVersionCode
WHERE packageName = :packageName
""",
)
suspend fun updateVersionInfo(
packageName: String,
available: Boolean,
version: String?,
assetName: String?,
assetUrl: String?,
assetSize: Long?,
releaseNotes: String?,
timestamp: Long,
latestVersionName: String?,
latestVersionCode: Long?,
)
@Query("UPDATE installed_apps SET lastCheckedAt = :timestamp WHERE packageName = :packageName")
suspend fun updateLastChecked(
packageName: String,
timestamp: Long,
)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/SeenRepoDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.local.db.entities.SeenRepoEntity
@Dao
interface SeenRepoDao {
@Query("SELECT repoId FROM seen_repos")
fun getAllSeenRepoIds(): Flow>
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(entity: SeenRepoEntity)
@Query("DELETE FROM seen_repos")
suspend fun clearAll()
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/StarredRepoDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.local.db.entities.StarredRepositoryEntity
@Dao
interface StarredRepoDao {
@Query("SELECT * FROM starred_repos ORDER BY starredAt DESC")
fun getAllStarred(): Flow>
@Query("SELECT * FROM starred_repos WHERE repoId = :repoId")
suspend fun getStarredById(repoId: Long): StarredRepositoryEntity?
@Query("SELECT EXISTS(SELECT 1 FROM starred_repos WHERE repoId = :repoId)")
suspend fun isStarred(repoId: Long): Boolean
@Query("SELECT EXISTS(SELECT 1 FROM starred_repos WHERE repoId = :repoId)")
fun isStarredFlow(repoId: Long): Flow
@Query("SELECT EXISTS(SELECT 1 FROM starred_repos WHERE repoId = :repoId)")
suspend fun isStarredSync(repoId: Long): Boolean
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertStarred(repo: StarredRepositoryEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAllStarred(repos: List)
@Query("DELETE FROM starred_repos WHERE repoId = :repoId")
suspend fun deleteStarredById(repoId: Long)
@Query("DELETE FROM starred_repos")
suspend fun clearAll()
@Query(
"""
UPDATE starred_repos
SET isInstalled = :installed,
installedPackageName = :packageName
WHERE repoId = :repoId
""",
)
suspend fun updateInstallStatus(
repoId: Long,
installed: Boolean,
packageName: String?,
)
@Query(
"""
UPDATE starred_repos
SET latestVersion = :version,
latestReleaseUrl = :releaseUrl,
lastSyncedAt = :timestamp
WHERE repoId = :repoId
""",
)
suspend fun updateLatestVersion(
repoId: Long,
version: String?,
releaseUrl: String?,
timestamp: Long,
)
@Query("SELECT COUNT(*) FROM starred_repos")
suspend fun getCount(): Int
@Query("SELECT MAX(lastSyncedAt) FROM starred_repos")
suspend fun getLastSyncTime(): Long?
@Transaction
suspend fun replaceAllStarred(repos: List) {
clearAll()
insertAllStarred(repos)
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/dao/UpdateHistoryDao.kt
================================================
package zed.rainxch.core.data.local.db.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.data.local.db.entities.UpdateHistoryEntity
@Dao
interface UpdateHistoryDao {
@Query("SELECT * FROM update_history ORDER BY updatedAt DESC LIMIT 50")
fun getRecentHistory(): Flow>
@Query("SELECT * FROM update_history WHERE packageName = :packageName ORDER BY updatedAt DESC")
fun getHistoryForApp(packageName: String): Flow>
@Insert
suspend fun insertHistory(history: UpdateHistoryEntity)
@Query("DELETE FROM update_history WHERE updatedAt < :timestamp")
suspend fun deleteOldHistory(timestamp: Long)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/CacheEntryEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "cache_entries")
data class CacheEntryEntity(
@PrimaryKey
val key: String,
val jsonData: String,
val cachedAt: Long,
val expiresAt: Long,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/FavoriteRepoEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "favorite_repos")
data class FavoriteRepoEntity(
@PrimaryKey
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val isInstalled: Boolean = false,
val installedPackageName: String? = null,
val latestVersion: String?,
val latestReleaseUrl: String?,
val addedAt: Long,
val lastSyncedAt: Long,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/InstalledAppEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
import zed.rainxch.core.domain.model.InstallSource
@Entity(tableName = "installed_apps")
data class InstalledAppEntity(
@PrimaryKey val packageName: String,
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val installedVersion: String,
val installedAssetName: String?,
val installedAssetUrl: String?,
val latestVersion: String?,
val latestAssetName: String?,
val latestAssetUrl: String?,
val latestAssetSize: Long?,
val appName: String,
val installSource: InstallSource,
val signingFingerprint: String?,
val installedAt: Long,
val lastCheckedAt: Long,
val lastUpdatedAt: Long,
val isUpdateAvailable: Boolean,
val updateCheckEnabled: Boolean = true,
val releaseNotes: String? = "",
val systemArchitecture: String,
val fileExtension: String,
val isPendingInstall: Boolean = false,
val installedVersionName: String? = null,
val installedVersionCode: Long = 0L,
val latestVersionName: String? = null,
val latestVersionCode: Long? = null,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/SeenRepoEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "seen_repos")
data class SeenRepoEntity(
@PrimaryKey
val repoId: Long,
val seenAt: Long,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/StarredRepositoryEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "starred_repos")
data class StarredRepositoryEntity(
@PrimaryKey
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val stargazersCount: Int,
val forksCount: Int,
val openIssuesCount: Int,
val isInstalled: Boolean = false,
val installedPackageName: String? = null,
val latestVersion: String?,
val latestReleaseUrl: String?,
val starredAt: Long?,
val addedAt: Long,
val lastSyncedAt: Long,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/local/db/entities/UpdateHistoryEntity.kt
================================================
package zed.rainxch.core.data.local.db.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
import zed.rainxch.core.domain.model.InstallSource
@Entity(tableName = "update_history")
data class UpdateHistoryEntity(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val packageName: String,
val appName: String,
val repoOwner: String,
val repoName: String,
val fromVersion: String,
val toVersion: String,
val updatedAt: Long,
val updateSource: InstallSource,
val success: Boolean = true,
val errorMessage: String? = null,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/logging/KermitLogger.kt
================================================
package zed.rainxch.core.data.logging
import co.touchlab.kermit.Logger
import zed.rainxch.core.domain.logging.GitHubStoreLogger
object KermitLogger : GitHubStoreLogger {
override fun debug(message: String) {
Logger.d(message)
}
override fun info(message: String) {
Logger.i(message)
}
override fun warn(message: String) {
Logger.w(message)
}
override fun error(
message: String,
throwable: Throwable?,
) {
Logger.e(message, throwable)
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/AssetNetwork.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.dto.AssetNetwork
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.GithubUser
fun AssetNetwork.toDomain(): GithubAsset =
GithubAsset(
id = id,
name = name,
contentType = contentType,
size = size,
downloadUrl = downloadUrl,
uploader =
GithubUser(
id = uploader.id,
login = uploader.login,
avatarUrl = uploader.avatarUrl,
htmlUrl = uploader.htmlUrl,
),
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/FavouriteRepoMappers.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.local.db.entities.FavoriteRepoEntity
import zed.rainxch.core.domain.model.FavoriteRepo
fun FavoriteRepo.toEntity(): FavoriteRepoEntity =
FavoriteRepoEntity(
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
isInstalled = isInstalled,
installedPackageName = installedPackageName,
latestVersion = latestVersion,
latestReleaseUrl = latestReleaseUrl,
addedAt = addedAt,
lastSyncedAt = lastSyncedAt,
)
fun FavoriteRepoEntity.toDomain(): FavoriteRepo =
FavoriteRepo(
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
isInstalled = isInstalled,
installedPackageName = installedPackageName,
latestVersion = latestVersion,
latestReleaseUrl = latestReleaseUrl,
addedAt = addedAt,
lastSyncedAt = lastSyncedAt,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/GithubAuthMappers.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.dto.GithubDeviceStartDto
import zed.rainxch.core.data.dto.GithubDeviceTokenErrorDto
import zed.rainxch.core.data.dto.GithubDeviceTokenSuccessDto
import zed.rainxch.core.domain.model.GithubDeviceStart
import zed.rainxch.core.domain.model.GithubDeviceTokenError
import zed.rainxch.core.domain.model.GithubDeviceTokenSuccess
fun GithubDeviceStartDto.toDomain() =
GithubDeviceStart(
deviceCode = deviceCode,
userCode = userCode,
verificationUri = verificationUri,
verificationUriComplete = verificationUriComplete,
intervalSec = intervalSec,
expiresInSec = expiresInSec,
)
fun GithubDeviceTokenSuccessDto.toDomain() =
GithubDeviceTokenSuccess(
accessToken = accessToken,
tokenType = tokenType,
expiresIn = expiresIn,
scope = scope,
refreshToken = refreshToken,
refreshTokenExpiresIn = refreshTokenExpiresIn,
)
fun GithubDeviceTokenErrorDto.toDomain() =
GithubDeviceTokenError(
error = error,
errorDescription = errorDescription,
)
fun GithubDeviceStart.toData() =
GithubDeviceStartDto(
deviceCode = deviceCode,
userCode = userCode,
verificationUri = verificationUri,
verificationUriComplete = verificationUriComplete,
intervalSec = intervalSec,
expiresInSec = expiresInSec,
)
fun GithubDeviceTokenSuccess.toData() =
GithubDeviceTokenSuccessDto(
accessToken = accessToken,
tokenType = tokenType,
expiresIn = expiresIn,
scope = scope,
refreshToken = refreshToken,
refreshTokenExpiresIn = refreshTokenExpiresIn,
)
fun GithubDeviceTokenError.toData() =
GithubDeviceTokenErrorDto(
error = error,
errorDescription = errorDescription,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/GithubRepoMapper.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.dto.GithubRepoNetworkModel
import zed.rainxch.core.domain.model.GithubRepoSummary
import zed.rainxch.core.domain.model.GithubUser
fun GithubRepoNetworkModel.toSummary(): GithubRepoSummary =
GithubRepoSummary(
id = id,
name = name,
fullName = fullName,
owner =
GithubUser(
id = owner.id,
login = owner.login,
avatarUrl = owner.avatarUrl,
htmlUrl = owner.htmlUrl,
),
description = description,
htmlUrl = htmlUrl,
stargazersCount = stargazersCount,
forksCount = forksCount,
language = language,
topics = topics,
releasesUrl = releasesUrl,
updatedAt = updatedAt,
defaultBranch = defaultBranch,
isFork = fork,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/InstalledAppsMappers.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.local.db.entities.InstalledAppEntity
import zed.rainxch.core.domain.model.InstalledApp
fun InstalledApp.toEntity(): InstalledAppEntity =
InstalledAppEntity(
packageName = packageName,
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
installedVersion = installedVersion,
installedAssetName = installedAssetName,
installedAssetUrl = installedAssetUrl,
latestVersion = latestVersion,
latestAssetName = latestAssetName,
latestAssetUrl = latestAssetUrl,
latestAssetSize = latestAssetSize,
appName = appName,
installSource = installSource,
installedAt = installedAt,
lastCheckedAt = lastCheckedAt,
lastUpdatedAt = lastUpdatedAt,
isUpdateAvailable = isUpdateAvailable,
updateCheckEnabled = updateCheckEnabled,
releaseNotes = releaseNotes,
systemArchitecture = systemArchitecture,
fileExtension = fileExtension,
isPendingInstall = isPendingInstall,
installedVersionName = installedVersionName,
installedVersionCode = installedVersionCode,
latestVersionName = latestVersionName,
latestVersionCode = latestVersionCode,
signingFingerprint = signingFingerprint,
)
fun InstalledAppEntity.toDomain(): InstalledApp =
InstalledApp(
packageName = packageName,
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
installedVersion = installedVersion,
installedAssetName = installedAssetName,
installedAssetUrl = installedAssetUrl,
latestVersion = latestVersion,
latestAssetName = latestAssetName,
latestAssetUrl = latestAssetUrl,
latestAssetSize = latestAssetSize,
appName = appName,
installSource = installSource,
installedAt = installedAt,
lastCheckedAt = lastCheckedAt,
lastUpdatedAt = lastUpdatedAt,
isUpdateAvailable = isUpdateAvailable,
updateCheckEnabled = updateCheckEnabled,
releaseNotes = releaseNotes,
systemArchitecture = systemArchitecture,
fileExtension = fileExtension,
isPendingInstall = isPendingInstall,
installedVersionName = installedVersionName,
installedVersionCode = installedVersionCode,
latestVersionName = latestVersionName,
latestVersionCode = latestVersionCode,
signingFingerprint = signingFingerprint,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/ReleaseNetwork.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.dto.ReleaseNetwork
import zed.rainxch.core.domain.model.GithubRelease
import zed.rainxch.core.domain.model.GithubUser
fun ReleaseNetwork.toDomain(): GithubRelease =
GithubRelease(
id = id,
tagName = tagName,
name = name,
author =
GithubUser(
id = author.id,
login = author.login,
avatarUrl = author.avatarUrl,
htmlUrl = author.htmlUrl,
),
publishedAt = publishedAt ?: createdAt ?: "",
description = body,
assets = assets.map { it.toDomain() },
tarballUrl = tarballUrl,
zipballUrl = zipballUrl,
htmlUrl = htmlUrl,
isPrerelease = prerelease == true,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/StarredRepoMapper.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.local.db.entities.StarredRepositoryEntity
import zed.rainxch.core.domain.model.StarredRepository
fun StarredRepository.toEntity(): StarredRepositoryEntity =
StarredRepositoryEntity(
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
stargazersCount = stargazersCount,
forksCount = forksCount,
openIssuesCount = openIssuesCount,
isInstalled = isInstalled,
installedPackageName = installedPackageName,
latestVersion = latestVersion,
latestReleaseUrl = latestReleaseUrl,
starredAt = starredAt,
addedAt = addedAt,
lastSyncedAt = lastSyncedAt,
)
fun StarredRepositoryEntity.toDomain(): StarredRepository =
StarredRepository(
repoId = repoId,
repoName = repoName,
repoOwner = repoOwner,
repoOwnerAvatarUrl = repoOwnerAvatarUrl,
repoDescription = repoDescription,
primaryLanguage = primaryLanguage,
repoUrl = repoUrl,
stargazersCount = stargazersCount,
forksCount = forksCount,
openIssuesCount = openIssuesCount,
isInstalled = isInstalled,
installedPackageName = installedPackageName,
latestVersion = latestVersion,
latestReleaseUrl = latestReleaseUrl,
starredAt = starredAt,
addedAt = addedAt,
lastSyncedAt = lastSyncedAt,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/UpdateHistoryMapper.kt
================================================
package zed.rainxch.core.data.mappers
import zed.rainxch.core.data.local.db.entities.UpdateHistoryEntity
import zed.rainxch.core.domain.model.UpdateHistory
fun UpdateHistory.toEntity(): UpdateHistoryEntity =
UpdateHistoryEntity(
id = id,
packageName = packageName,
appName = appName,
repoOwner = repoOwner,
repoName = repoName,
fromVersion = fromVersion,
toVersion = toVersion,
updatedAt = updatedAt,
updateSource = updateSource,
success = success,
errorMessage = errorMessage,
)
fun UpdateHistoryEntity.toDomain(): UpdateHistory =
UpdateHistory(
id = id,
packageName = packageName,
appName = appName,
repoOwner = repoOwner,
repoName = repoName,
fromVersion = fromVersion,
toVersion = toVersion,
updatedAt = updatedAt,
updateSource = updateSource,
success = success,
errorMessage = errorMessage,
)
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/GitHubClientProvider.kt
================================================
package zed.rainxch.core.data.network
import io.ktor.client.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import zed.rainxch.core.data.data_source.TokenStore
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.repository.AuthenticationState
import zed.rainxch.core.domain.repository.RateLimitRepository
class GitHubClientProvider(
private val tokenStore: TokenStore,
private val rateLimitRepository: RateLimitRepository,
private val authenticationState: AuthenticationState,
proxyConfigFlow: StateFlow,
) {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private val mutex = Mutex()
@Volatile
private var currentClient: HttpClient =
createGitHubHttpClient(
tokenStore = tokenStore,
rateLimitRepository = rateLimitRepository,
authenticationState = authenticationState,
scope = scope,
proxyConfig = proxyConfigFlow.value,
)
init {
proxyConfigFlow
.drop(1)
.distinctUntilChanged()
.onEach { proxyConfig ->
mutex.withLock {
currentClient.close()
currentClient =
createGitHubHttpClient(
tokenStore = tokenStore,
rateLimitRepository = rateLimitRepository,
authenticationState = authenticationState,
scope = scope,
proxyConfig = proxyConfig,
)
}
}.launchIn(scope)
}
val client: HttpClient get() = currentClient
fun close() {
currentClient.close()
scope.cancel()
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/HttpClientFactory.kt
================================================
package zed.rainxch.core.data.network
import io.ktor.client.*
import io.ktor.client.call.body
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.header
import io.ktor.client.statement.HttpResponse
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.util.network.UnresolvedAddressException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.json.Json
import zed.rainxch.core.data.data_source.TokenStore
import zed.rainxch.core.data.network.interceptor.RateLimitInterceptor
import zed.rainxch.core.data.network.interceptor.UnauthorizedInterceptor
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.model.RateLimitException
import zed.rainxch.core.domain.repository.AuthenticationState
import zed.rainxch.core.domain.repository.RateLimitRepository
import java.io.IOException
import kotlin.coroutines.cancellation.CancellationException
expect fun createPlatformHttpClient(proxyConfig: ProxyConfig): HttpClient
fun createGitHubHttpClient(
tokenStore: TokenStore,
rateLimitRepository: RateLimitRepository,
authenticationState: AuthenticationState? = null,
scope: CoroutineScope? = null,
proxyConfig: ProxyConfig = ProxyConfig.None,
): HttpClient {
val json =
Json {
ignoreUnknownKeys = true
isLenient = true
}
return createPlatformHttpClient(proxyConfig).config {
install(RateLimitInterceptor) {
this.rateLimitRepository = rateLimitRepository
}
if (authenticationState != null && scope != null) {
install(UnauthorizedInterceptor) {
this.authenticationState = authenticationState
this.scope = scope
}
}
install(ContentNegotiation) {
json(json)
}
install(HttpTimeout) {
requestTimeoutMillis = HttpTimeoutConfig.INFINITE_TIMEOUT_MS
connectTimeoutMillis = 30_000
socketTimeoutMillis = HttpTimeoutConfig.INFINITE_TIMEOUT_MS
}
install(HttpRequestRetry) {
maxRetries = 3
retryIf { _, response ->
val code = response.status.value
if (code == 403) {
val remaining = response.headers["X-RateLimit-Remaining"]?.toIntOrNull()
if (remaining == 0) return@retryIf false
}
code in 500..<600
}
retryOnExceptionIf { _, cause ->
cause is HttpRequestTimeoutException ||
cause is UnresolvedAddressException ||
cause is IOException
}
exponentialDelay()
}
expectSuccess = false
defaultRequest {
url("https://api.github.com")
header(HttpHeaders.Accept, "application/vnd.github+json")
header("X-GitHub-Api-Version", "2022-11-28")
header(HttpHeaders.UserAgent, "GithubStore/1.0 (KMP)")
val token =
tokenStore
.blockingCurrentToken()
?.accessToken
?.trim()
.orEmpty()
if (token.isNotEmpty()) {
header(HttpHeaders.Authorization, "Bearer $token")
}
}
}
}
suspend inline fun HttpClient.executeRequest(crossinline block: suspend HttpClient.() -> HttpResponse): Result =
try {
val response = block()
if (response.status.isSuccess()) {
Result.success(response.body())
} else {
Result.failure(
Exception("HTTP ${response.status.value}: ${response.status.description}"),
)
}
} catch (e: RateLimitException) {
throw e
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Result.failure(e)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/ProxyManager.kt
================================================
package zed.rainxch.core.data.network
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import zed.rainxch.core.domain.model.ProxyConfig
object ProxyManager {
private val _proxyConfig = MutableStateFlow(ProxyConfig.None)
val currentProxyConfig: StateFlow = _proxyConfig.asStateFlow()
fun setNoProxy() {
_proxyConfig.value = ProxyConfig.None
}
fun setSystemProxy() {
_proxyConfig.value = ProxyConfig.System
}
fun setHttpProxy(
host: String,
port: Int,
username: String? = null,
password: String? = null,
) {
_proxyConfig.value = ProxyConfig.Http(host, port, username, password)
}
fun setSocksProxy(
host: String,
port: Int,
username: String? = null,
password: String? = null,
) {
_proxyConfig.value = ProxyConfig.Socks(host, port, username, password)
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/interceptor/RateLimitInterceptor.kt
================================================
package zed.rainxch.core.data.network.interceptor
import co.touchlab.kermit.Logger
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpClientPlugin
import io.ktor.client.statement.HttpReceivePipeline
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.HttpResponsePipeline
import io.ktor.http.Headers
import io.ktor.util.AttributeKey
import zed.rainxch.core.domain.logging.GitHubStoreLogger
import zed.rainxch.core.domain.model.RateLimitException
import zed.rainxch.core.domain.model.RateLimitInfo
import zed.rainxch.core.domain.repository.RateLimitRepository
class RateLimitInterceptor(
private val rateLimitRepository: RateLimitRepository,
) {
class Config {
var rateLimitRepository: RateLimitRepository? = null
}
companion object Plugin : HttpClientPlugin {
override val key: AttributeKey =
AttributeKey("RateLimitInterceptor")
override fun prepare(block: Config.() -> Unit): RateLimitInterceptor {
val config = Config().apply(block)
return RateLimitInterceptor(
rateLimitRepository =
requireNotNull(config.rateLimitRepository) {
"RateLimitRepository must be provided"
},
)
}
override fun install(
plugin: RateLimitInterceptor,
scope: HttpClient,
) {
scope.receivePipeline.intercept(HttpReceivePipeline.State) {
val response = subject
parseRateLimitFromHeaders(response.headers)?.let { rateLimitInfo ->
plugin.rateLimitRepository.updateRateLimit(rateLimitInfo)
if (response.status.value == 403 && rateLimitInfo.isExhausted) {
throw RateLimitException(rateLimitInfo)
}
}
proceedWith(subject)
}
}
private fun parseRateLimitFromHeaders(headers: Headers): RateLimitInfo? {
return try {
val limitHeader =
headers["X-RateLimit-Limit"]
?: return null.also { Logger.w { "Missing X-RateLimit-Limit" } }
val limit =
limitHeader.toIntOrNull()
?: return null.also { Logger.w { "Malformed X-RateLimit-Limit: $limitHeader" } }
val remainingHeader =
headers["X-RateLimit-Remaining"]
?: return null.also { Logger.w { "Missing X-RateLimit-Remaining" } }
val remaining =
remainingHeader.toIntOrNull()
?: return null.also { Logger.w { "Malformed X-RateLimit-Remaining: $remainingHeader" } }
val resetHeader =
headers["X-RateLimit-Reset"]
?: return null.also { Logger.w { "Missing X-RateLimit-Reset" } }
val reset =
resetHeader.toLongOrNull()
?: return null.also { Logger.w { "Malformed X-RateLimit-Reset: $resetHeader" } }
val resource = headers["X-RateLimit-Resource"] ?: "core"
RateLimitInfo(limit, remaining, reset, resource)
} catch (e: Exception) {
Logger.e(e) { "Failed to parse rate limit headers" }
null
}
}
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/interceptor/UnauthorizedInterceptor.kt
================================================
package zed.rainxch.core.data.network.interceptor
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpClientPlugin
import io.ktor.client.statement.HttpReceivePipeline
import io.ktor.util.AttributeKey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import zed.rainxch.core.domain.repository.AuthenticationState
class UnauthorizedInterceptor(
private val authenticationState: AuthenticationState,
private val scope: CoroutineScope,
) {
class Config {
var authenticationState: AuthenticationState? = null
var scope: CoroutineScope? = null
}
companion object Plugin : HttpClientPlugin {
override val key: AttributeKey =
AttributeKey("UnauthorizedInterceptor")
override fun prepare(block: Config.() -> Unit): UnauthorizedInterceptor {
val config = Config().apply(block)
return UnauthorizedInterceptor(
authenticationState =
requireNotNull(config.authenticationState) {
"AuthenticationState must be provided"
},
scope =
requireNotNull(config.scope) {
"CoroutineScope must be provided"
},
)
}
override fun install(
plugin: UnauthorizedInterceptor,
scope: HttpClient,
) {
scope.receivePipeline.intercept(HttpReceivePipeline.After) {
if (subject.status.value == 401) {
plugin.scope.launch {
plugin.authenticationState.notifySessionExpired()
}
}
proceedWith(subject)
}
}
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/AuthenticationStateImpl.kt
================================================
package zed.rainxch.core.data.repository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import zed.rainxch.core.data.data_source.TokenStore
import zed.rainxch.core.domain.repository.AuthenticationState
class AuthenticationStateImpl(
private val tokenStore: TokenStore,
) : AuthenticationState {
private val _sessionExpiredEvent = MutableSharedFlow(extraBufferCapacity = 1)
override val sessionExpiredEvent: SharedFlow = _sessionExpiredEvent.asSharedFlow()
private val sessionExpiredMutex = Mutex()
override fun isUserLoggedIn(): Flow =
tokenStore
.tokenFlow()
.map {
it != null
}
override suspend fun isCurrentlyUserLoggedIn(): Boolean = tokenStore.currentToken() != null
override suspend fun notifySessionExpired() {
sessionExpiredMutex.withLock {
if (tokenStore.currentToken() == null) return@withLock
tokenStore.clear()
_sessionExpiredEvent.emit(Unit)
}
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/FavouritesRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import zed.rainxch.core.data.local.db.dao.FavoriteRepoDao
import zed.rainxch.core.data.local.db.dao.InstalledAppDao
import zed.rainxch.core.data.mappers.toDomain
import zed.rainxch.core.data.mappers.toEntity
import zed.rainxch.core.domain.model.FavoriteRepo
import zed.rainxch.core.domain.repository.FavouritesRepository
class FavouritesRepositoryImpl(
private val favoriteRepoDao: FavoriteRepoDao,
private val installedAppsDao: InstalledAppDao,
) : FavouritesRepository {
override fun getAllFavorites(): Flow> =
favoriteRepoDao
.getAllFavorites()
.map { favoriteRepos ->
favoriteRepos.map { favoriteRepo -> favoriteRepo.toDomain() }
}
override fun isFavorite(repoId: Long): Flow = favoriteRepoDao.isFavorite(repoId)
override suspend fun isFavoriteSync(repoId: Long): Boolean = favoriteRepoDao.isFavoriteSync(repoId)
suspend fun addFavorite(repo: FavoriteRepo) {
val installedApp = installedAppsDao.getAppByRepoId(repo.repoId)
favoriteRepoDao.insertFavorite(
repo
.toEntity()
.copy(
isInstalled = installedApp != null,
installedPackageName = installedApp?.packageName,
),
)
}
override suspend fun toggleFavorite(repo: FavoriteRepo) {
if (favoriteRepoDao.isFavoriteSync(repo.repoId)) {
favoriteRepoDao.deleteFavoriteById(repo.repoId)
} else {
addFavorite(repo)
}
}
override suspend fun updateFavoriteInstallStatus(
repoId: Long,
installed: Boolean,
packageName: String?,
) {
favoriteRepoDao.updateInstallStatus(repoId, installed, packageName)
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import androidx.room.immediateTransaction
import androidx.room.useWriterConnection
import co.touchlab.kermit.Logger
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.http.HttpHeaders
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import zed.rainxch.core.data.dto.ReleaseNetwork
import zed.rainxch.core.data.local.db.AppDatabase
import zed.rainxch.core.data.local.db.dao.InstalledAppDao
import zed.rainxch.core.data.local.db.dao.UpdateHistoryDao
import zed.rainxch.core.data.local.db.entities.UpdateHistoryEntity
import zed.rainxch.core.data.mappers.toDomain
import zed.rainxch.core.data.mappers.toEntity
import zed.rainxch.core.data.network.executeRequest
import zed.rainxch.core.domain.model.GithubRelease
import zed.rainxch.core.domain.model.InstallSource
import zed.rainxch.core.domain.model.InstalledApp
import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.Installer
class InstalledAppsRepositoryImpl(
private val database: AppDatabase,
private val installedAppsDao: InstalledAppDao,
private val historyDao: UpdateHistoryDao,
private val installer: Installer,
private val httpClient: HttpClient,
private val tweaksRepository: TweaksRepository,
) : InstalledAppsRepository {
override suspend fun executeInTransaction(block: suspend () -> R): R =
database.useWriterConnection { transactor ->
transactor.immediateTransaction {
block()
}
}
override fun getAllInstalledApps(): Flow> =
installedAppsDao
.getAllInstalledApps()
.map { it.map { app -> app.toDomain() } }
override fun getAppsWithUpdates(): Flow> =
installedAppsDao
.getAppsWithUpdates()
.map { it.map { app -> app.toDomain() } }
override fun getUpdateCount(): Flow = installedAppsDao.getUpdateCount()
override suspend fun getAppByPackage(packageName: String): InstalledApp? =
installedAppsDao
.getAppByPackage(packageName)
?.toDomain()
override suspend fun getAppByRepoId(repoId: Long): InstalledApp? = installedAppsDao.getAppByRepoId(repoId)?.toDomain()
override fun getAppByRepoIdAsFlow(repoId: Long): Flow =
installedAppsDao.getAppByRepoIdAsFlow(repoId).map { it?.toDomain() }
override suspend fun isAppInstalled(repoId: Long): Boolean = installedAppsDao.getAppByRepoId(repoId) != null
override suspend fun saveInstalledApp(app: InstalledApp) {
installedAppsDao.insertApp(app.toEntity())
}
override suspend fun deleteInstalledApp(packageName: String) {
installedAppsDao.deleteByPackageName(packageName)
}
private suspend fun fetchLatestPublishedRelease(
owner: String,
repo: String,
): GithubRelease? {
return try {
val includePreReleases = tweaksRepository.getIncludePreReleases().first()
val releases =
httpClient
.executeRequest> {
get("/repos/$owner/$repo/releases") {
header(HttpHeaders.Accept, "application/vnd.github+json")
parameter("per_page", 10)
}
}.getOrNull() ?: return null
val latest =
releases
.asSequence()
.filter { it.draft != true }
.filter { includePreReleases || it.prerelease != true }
.maxByOrNull { it.publishedAt ?: it.createdAt ?: "" }
?: return null
latest.toDomain()
} catch (e: Exception) {
Logger.e { "Failed to fetch latest release for $owner/$repo: ${e.message}" }
null
}
}
override suspend fun checkForUpdates(packageName: String): Boolean {
val app = installedAppsDao.getAppByPackage(packageName) ?: return false
try {
val latestRelease =
fetchLatestPublishedRelease(
owner = app.repoOwner,
repo = app.repoName,
)
if (latestRelease != null) {
val normalizedInstalledTag = normalizeVersion(app.installedVersion)
val normalizedLatestTag = normalizeVersion(latestRelease.tagName)
val installableAssets =
latestRelease.assets.filter { asset ->
installer.isAssetInstallable(asset.name)
}
val primaryAsset = installer.choosePrimaryAsset(installableAssets)
// Only flag as update if the latest version is actually newer
// (not just different — avoids false "downgrade" notifications)
val isUpdateAvailable =
if (normalizedInstalledTag == normalizedLatestTag) {
false
} else {
isVersionNewer(normalizedLatestTag, normalizedInstalledTag)
}
Logger.d {
"Update check for ${app.appName}: " +
"installedTag=${app.installedVersion}, latestTag=${latestRelease.tagName}, " +
"installedCode=${app.installedVersionCode}, " +
"isUpdate=$isUpdateAvailable"
}
installedAppsDao.updateVersionInfo(
packageName = packageName,
available = isUpdateAvailable,
version = latestRelease.tagName,
assetName = primaryAsset?.name,
assetUrl = primaryAsset?.downloadUrl,
assetSize = primaryAsset?.size,
releaseNotes = latestRelease.description ?: "",
timestamp = System.currentTimeMillis(),
latestVersionName = latestRelease.tagName,
latestVersionCode = null,
)
return isUpdateAvailable
} else {
installedAppsDao.updateLastChecked(packageName, System.currentTimeMillis())
}
} catch (e: Exception) {
Logger.e { "Failed to check updates for $packageName: ${e.message}" }
installedAppsDao.updateLastChecked(packageName, System.currentTimeMillis())
}
return false
}
override suspend fun checkAllForUpdates() {
val apps = installedAppsDao.getAllInstalledApps().first()
apps.forEach { app ->
if (app.updateCheckEnabled) {
try {
checkForUpdates(app.packageName)
} catch (e: Exception) {
Logger.w { "Failed to check updates for ${app.packageName}: ${e.message}" }
}
}
}
}
override suspend fun updateAppVersion(
packageName: String,
newTag: String,
newAssetName: String,
newAssetUrl: String,
newVersionName: String,
newVersionCode: Long,
signingFingerprint: String?,
) {
val app = installedAppsDao.getAppByPackage(packageName) ?: return
Logger.d {
"Updating app version: $packageName from ${app.installedVersion} to $newTag"
}
historyDao.insertHistory(
UpdateHistoryEntity(
packageName = packageName,
appName = app.appName,
repoOwner = app.repoOwner,
repoName = app.repoName,
fromVersion = app.installedVersion,
toVersion = newTag,
updatedAt = System.currentTimeMillis(),
updateSource = InstallSource.THIS_APP,
success = true,
),
)
installedAppsDao.updateApp(
app.copy(
installedVersion = newTag,
installedAssetName = newAssetName,
installedAssetUrl = newAssetUrl,
installedVersionName = newVersionName,
installedVersionCode = newVersionCode,
latestVersion = newTag,
latestAssetName = newAssetName,
latestAssetUrl = newAssetUrl,
latestVersionName = newVersionName,
latestVersionCode = newVersionCode,
isUpdateAvailable = false,
lastUpdatedAt = System.currentTimeMillis(),
lastCheckedAt = System.currentTimeMillis(),
signingFingerprint = signingFingerprint,
),
)
}
override suspend fun updateApp(app: InstalledApp) {
installedAppsDao.updateApp(app.toEntity())
}
override suspend fun updatePendingStatus(
packageName: String,
isPending: Boolean,
) {
val app = installedAppsDao.getAppByPackage(packageName) ?: return
installedAppsDao.updateApp(app.copy(isPendingInstall = isPending))
}
private fun normalizeVersion(version: String): String = version.removePrefix("v").removePrefix("V").trim()
/**
* Compare two version strings and return true if [candidate] is newer than [current].
* Handles semantic versioning (1.2.3), pre-release suffixes (1.2.3-beta.1),
* and falls back to lexicographic comparison for non-standard formats.
*
* Pre-release versions are considered older than their stable counterparts:
* 1.2.3-beta < 1.2.3 (per semver spec)
*
* This prevents false "downgrade" notifications when a user has a pre-release
* installed and the latest stable version has a lower or equal base version.
*/
private fun isVersionNewer(
candidate: String,
current: String,
): Boolean {
val candidateParsed = parseSemanticVersion(candidate)
val currentParsed = parseSemanticVersion(current)
if (candidateParsed != null && currentParsed != null) {
// Compare major.minor.patch
for (i in 0 until maxOf(candidateParsed.numbers.size, currentParsed.numbers.size)) {
val c = candidateParsed.numbers.getOrElse(i) { 0 }
val r = currentParsed.numbers.getOrElse(i) { 0 }
if (c > r) return true
if (c < r) return false
}
// Numbers are equal; compare pre-release suffixes
// No pre-release > has pre-release (e.g., 1.0.0 > 1.0.0-beta)
return when {
candidateParsed.preRelease == null && currentParsed.preRelease != null -> {
true
}
candidateParsed.preRelease != null && currentParsed.preRelease == null -> {
false
}
candidateParsed.preRelease != null && currentParsed.preRelease != null -> {
comparePreRelease(candidateParsed.preRelease, currentParsed.preRelease) > 0
}
else -> {
false
} // both null, versions are equal
}
}
// Fallback: lexicographic comparison (better than just "not equal")
return candidate > current
}
private data class SemanticVersion(
val numbers: List,
val preRelease: String?,
)
private fun parseSemanticVersion(version: String): SemanticVersion? {
// Split off pre-release suffix: "1.2.3-beta.1" -> "1.2.3" and "beta.1"
val hyphenIndex = version.indexOf('-')
val numberPart = if (hyphenIndex >= 0) version.substring(0, hyphenIndex) else version
val preRelease = if (hyphenIndex >= 0) version.substring(hyphenIndex + 1) else null
val parts = numberPart.split(".")
val numbers = parts.mapNotNull { it.toIntOrNull() }
// Only valid if we could parse at least one number and all parts were valid numbers
if (numbers.isEmpty() || numbers.size != parts.size) return null
return SemanticVersion(numbers, preRelease)
}
/**
* Compare pre-release identifiers per semver spec:
* Identifiers consisting of only digits are compared numerically.
* Identifiers with letters are compared lexically.
* Numeric identifiers always have lower precedence than alphanumeric.
* A larger set of pre-release fields has higher precedence if all preceding are equal.
*/
private fun comparePreRelease(
a: String,
b: String,
): Int {
val aParts = a.split(".")
val bParts = b.split(".")
for (i in 0 until minOf(aParts.size, bParts.size)) {
val aNum = aParts[i].toIntOrNull()
val bNum = bParts[i].toIntOrNull()
val cmp =
when {
aNum != null && bNum != null -> aNum.compareTo(bNum)
aNum != null -> -1
// numeric < alphanumeric
bNum != null -> 1
else -> aParts[i].compareTo(bParts[i])
}
if (cmp != 0) return cmp
}
return aParts.size.compareTo(bParts.size)
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/ProxyRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import zed.rainxch.core.data.network.ProxyManager
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.repository.ProxyRepository
class ProxyRepositoryImpl(
private val preferences: DataStore,
) : ProxyRepository {
private val proxyTypeKey = stringPreferencesKey("proxy_type")
private val proxyHostKey = stringPreferencesKey("proxy_host")
private val proxyPortKey = intPreferencesKey("proxy_port")
private val proxyUsernameKey = stringPreferencesKey("proxy_username")
private val proxyPasswordKey = stringPreferencesKey("proxy_password")
override fun getProxyConfig(): Flow =
preferences.data.map { prefs ->
when (prefs[proxyTypeKey]) {
"system" -> {
ProxyConfig.System
}
"http" -> {
val host = prefs[proxyHostKey]?.takeIf { it.isNotBlank() }
val port = prefs[proxyPortKey]?.takeIf { it in 1..65535 }
if (host != null && port != null) {
ProxyConfig.Http(
host = host,
port = port,
username = prefs[proxyUsernameKey],
password = prefs[proxyPasswordKey],
)
} else {
ProxyConfig.None
}
}
"socks" -> {
val host = prefs[proxyHostKey]?.takeIf { it.isNotBlank() }
val port = prefs[proxyPortKey]?.takeIf { it in 1..65535 }
if (host != null && port != null) {
ProxyConfig.Socks(
host = host,
port = port,
username = prefs[proxyUsernameKey],
password = prefs[proxyPasswordKey],
)
} else {
ProxyConfig.None
}
}
else -> {
ProxyConfig.None
}
}
}
override suspend fun setProxyConfig(config: ProxyConfig) {
// Persist first so config survives crashes, then apply in-memory
preferences.edit { prefs ->
when (config) {
is ProxyConfig.None -> {
prefs[proxyTypeKey] = "none"
prefs.remove(proxyHostKey)
prefs.remove(proxyPortKey)
prefs.remove(proxyUsernameKey)
prefs.remove(proxyPasswordKey)
}
is ProxyConfig.System -> {
prefs[proxyTypeKey] = "system"
prefs.remove(proxyHostKey)
prefs.remove(proxyPortKey)
prefs.remove(proxyUsernameKey)
prefs.remove(proxyPasswordKey)
}
is ProxyConfig.Http -> {
prefs[proxyTypeKey] = "http"
prefs[proxyHostKey] = config.host
prefs[proxyPortKey] = config.port
if (config.username != null) {
prefs[proxyUsernameKey] = config.username!!
} else {
prefs.remove(proxyUsernameKey)
}
if (config.password != null) {
prefs[proxyPasswordKey] = config.password!!
} else {
prefs.remove(proxyPasswordKey)
}
}
is ProxyConfig.Socks -> {
prefs[proxyTypeKey] = "socks"
prefs[proxyHostKey] = config.host
prefs[proxyPortKey] = config.port
if (config.username != null) {
prefs[proxyUsernameKey] = config.username!!
} else {
prefs.remove(proxyUsernameKey)
}
if (config.password != null) {
prefs[proxyPasswordKey] = config.password!!
} else {
prefs.remove(proxyPasswordKey)
}
}
}
}
applyToProxyManager(config)
}
private fun applyToProxyManager(config: ProxyConfig) {
when (config) {
is ProxyConfig.None -> {
ProxyManager.setNoProxy()
}
is ProxyConfig.System -> {
ProxyManager.setSystemProxy()
}
is ProxyConfig.Http -> {
ProxyManager.setHttpProxy(
host = config.host,
port = config.port,
username = config.username,
password = config.password,
)
}
is ProxyConfig.Socks -> {
ProxyManager.setSocksProxy(
host = config.host,
port = config.port,
username = config.username,
password = config.password,
)
}
}
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/RateLimitRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import zed.rainxch.core.domain.model.RateLimitInfo
import zed.rainxch.core.domain.repository.RateLimitRepository
import kotlin.time.Clock
class RateLimitRepositoryImpl : RateLimitRepository {
private val _rateLimitState = MutableStateFlow(null)
override val rateLimitState: StateFlow = _rateLimitState.asStateFlow()
private val _rateLimitExhaustedEvent = MutableSharedFlow(extraBufferCapacity = 1)
override val rateLimitExhaustedEvent: SharedFlow = _rateLimitExhaustedEvent
override fun updateRateLimit(rateLimitInfo: RateLimitInfo?) {
_rateLimitState.value = rateLimitInfo
if (rateLimitInfo?.isExhausted == true) {
_rateLimitExhaustedEvent.tryEmit(rateLimitInfo)
}
}
override fun getCurrentRateLimit(): RateLimitInfo? = _rateLimitState.value
override fun isCurrentlyLimited(): Boolean {
val info = getCurrentRateLimit() ?: return false
return info.isCurrentlyLimited()
}
override fun clear() {
_rateLimitState.value = null
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/SeenReposRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import zed.rainxch.core.data.local.db.dao.SeenRepoDao
import zed.rainxch.core.data.local.db.entities.SeenRepoEntity
import zed.rainxch.core.domain.repository.SeenReposRepository
class SeenReposRepositoryImpl(
private val seenRepoDao: SeenRepoDao,
) : SeenReposRepository {
override fun getAllSeenRepoIds(): Flow> =
seenRepoDao.getAllSeenRepoIds().map { it.toSet() }
override suspend fun markAsSeen(repoId: Long) {
seenRepoDao.insert(
SeenRepoEntity(
repoId = repoId,
seenAt = System.currentTimeMillis(),
),
)
}
override suspend fun clearAll() {
seenRepoDao.clearAll()
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/StarredRepositoryImpl.kt
================================================
@file:OptIn(ExperimentalTime::class)
package zed.rainxch.core.data.repository
import co.touchlab.kermit.Logger
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.http.isSuccess
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.coroutines.withContext
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import zed.rainxch.core.data.dto.GitHubStarredResponse
import zed.rainxch.core.data.local.db.dao.InstalledAppDao
import zed.rainxch.core.data.local.db.dao.StarredRepoDao
import zed.rainxch.core.data.mappers.toDomain
import zed.rainxch.core.data.mappers.toEntity
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.domain.model.RateLimitException
import zed.rainxch.core.domain.repository.StarredRepository
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Clock
import kotlin.time.ExperimentalTime
import kotlin.time.Instant
class StarredRepositoryImpl(
private val starredRepoDao: StarredRepoDao,
private val installedAppsDao: InstalledAppDao,
private val platform: Platform,
private val httpClient: HttpClient,
) : StarredRepository {
companion object {
private const val SYNC_THRESHOLD_MS = 24 * 60 * 60 * 1000L // 24 hours
}
override fun getAllStarred(): Flow> =
starredRepoDao
.getAllStarred()
.map { it.map { entity -> entity.toDomain() } }
override suspend fun isStarred(repoId: Long): Boolean = starredRepoDao.isStarred(repoId)
override suspend fun getLastSyncTime(): Long? = starredRepoDao.getLastSyncTime()
override suspend fun needsSync(): Boolean {
val lastSync = getLastSyncTime() ?: return true
val now = Clock.System.now().toEpochMilliseconds()
return (now - lastSync) > SYNC_THRESHOLD_MS
}
override suspend fun syncStarredRepos(forceRefresh: Boolean): Result =
withContext(Dispatchers.IO) {
try {
if (!forceRefresh && !needsSync()) {
return@withContext Result.success(Unit)
}
val allRepos = mutableListOf()
var page = 1
val perPage = 100
while (true) {
val response =
httpClient.get("/user/starred") {
parameter("per_page", perPage)
parameter("page", page)
}
if (!response.status.isSuccess()) {
if (response.status.value == 401) {
return@withContext Result.failure(
Exception("Authentication required. Please sign in with GitHub."),
)
}
return@withContext Result.failure(
Exception("Failed to fetch starred repos: ${response.status.description}"),
)
}
val repos: List = response.body()
if (repos.isEmpty()) break
allRepos.addAll(repos)
if (repos.size < perPage) break
page++
}
val now = Clock.System.now().toEpochMilliseconds()
val starredRepos = mutableListOf()
coroutineScope {
val semaphore = Semaphore(25)
val deferredResults =
allRepos.map { repo ->
async {
semaphore.withPermit {
val hasValidAssets =
checkForValidAssets(repo.owner.login, repo.name)
if (hasValidAssets) {
val installedApp = installedAppsDao.getAppByRepoId(repo.id)
zed.rainxch.core.domain.model.StarredRepository(
repoId = repo.id,
repoName = repo.name,
repoOwner = repo.owner.login,
repoOwnerAvatarUrl = repo.owner.avatarUrl,
repoDescription = repo.description,
primaryLanguage = repo.language,
repoUrl = repo.htmlUrl,
stargazersCount = repo.stargazersCount,
forksCount = repo.forksCount,
openIssuesCount = repo.openIssuesCount,
isInstalled = installedApp != null,
installedPackageName = installedApp?.packageName,
latestVersion = null,
latestReleaseUrl = null,
starredAt =
repo.starredAt?.let {
Instant.parse(it).toEpochMilliseconds()
},
addedAt = now,
lastSyncedAt = now,
)
} else {
null
}
}
}
}
deferredResults.awaitAll().filterNotNull().let { validRepos ->
starredRepos.addAll(validRepos)
}
}
starredRepoDao.replaceAllStarred(starredRepos.map { it.toEntity() })
Result.success(Unit)
} catch (e: RateLimitException) {
throw e
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Logger.e(e) { "Failed to sync starred repos" }
Result.failure(e)
}
}
private suspend fun checkForValidAssets(
owner: String,
repo: String,
): Boolean {
return try {
val releasesResponse =
httpClient.get("/repos/$owner/$repo/releases") {
header("Accept", "application/vnd.github.v3+json")
parameter("per_page", 10)
}
if (!releasesResponse.status.isSuccess()) {
return false
}
val allReleases: List = releasesResponse.body()
val stableRelease =
allReleases.firstOrNull {
it.draft != true && it.prerelease != true
} ?: return false
if (stableRelease.assets.isEmpty()) {
return false
}
val relevantAssets =
stableRelease.assets.filter { asset ->
val name = asset.name.lowercase()
when (platform) {
Platform.ANDROID -> {
name.endsWith(".apk")
}
Platform.WINDOWS -> {
name.endsWith(".msi") || name.endsWith(".exe")
}
Platform.MACOS -> {
name.endsWith(".dmg") || name.endsWith(".pkg")
}
Platform.LINUX -> {
name.endsWith(".appimage") || name.endsWith(".deb") ||
name.endsWith(
".rpm",
)
}
}
}
relevantAssets.isNotEmpty()
} catch (e: RateLimitException) {
throw e
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Logger.w(e) { "Failed to check valid assets for $owner/$repo" }
false
}
}
@Serializable
private data class GithubReleaseNetworkModel(
val assets: List,
val draft: Boolean? = null,
val prerelease: Boolean? = null,
@SerialName("published_at") val publishedAt: String? = null,
)
@Serializable
private data class AssetNetworkModel(
val name: String,
)
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt
================================================
package zed.rainxch.core.data.repository
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import zed.rainxch.core.domain.model.AppTheme
import zed.rainxch.core.domain.model.FontTheme
import zed.rainxch.core.domain.model.InstallerType
import zed.rainxch.core.domain.repository.TweaksRepository
class TweaksRepositoryImpl(
private val preferences: DataStore,
) : TweaksRepository {
private val THEME_KEY = stringPreferencesKey("app_theme")
private val AMOLED_KEY = booleanPreferencesKey("amoled_theme")
private val IS_DARK_THEME_KEY = booleanPreferencesKey("is_dark_theme")
private val FONT_KEY = stringPreferencesKey("font_theme")
private val AUTO_DETECT_CLIPBOARD_KEY = booleanPreferencesKey("auto_detect_clipboard_links")
private val INSTALLER_TYPE_KEY = stringPreferencesKey("installer_type")
private val AUTO_UPDATE_KEY = booleanPreferencesKey("auto_update_enabled")
private val UPDATE_CHECK_INTERVAL_KEY = longPreferencesKey("update_check_interval_hours")
private val INCLUDE_PRE_RELEASES_KEY = booleanPreferencesKey("include_pre_releases")
private val LIQUID_GLASS_ENABLED_KEY = booleanPreferencesKey("liquid_glass_enabled")
private val HIDE_SEEN_ENABLED_KEY = booleanPreferencesKey("hide_seen_enabled")
override fun getThemeColor(): Flow =
preferences.data.map { prefs ->
val themeName = prefs[THEME_KEY]
AppTheme.fromName(themeName)
}
override suspend fun setThemeColor(theme: AppTheme) {
preferences.edit { prefs ->
prefs[THEME_KEY] = theme.name
}
}
override fun getIsDarkTheme(): Flow =
preferences.data.map { prefs ->
prefs[IS_DARK_THEME_KEY]
}
override suspend fun setDarkTheme(isDarkTheme: Boolean?) {
preferences.edit { prefs ->
if (isDarkTheme == null) {
prefs.remove(IS_DARK_THEME_KEY)
} else {
prefs[IS_DARK_THEME_KEY] = isDarkTheme
}
}
}
override fun getAmoledTheme(): Flow =
preferences.data.map { prefs ->
prefs[AMOLED_KEY] ?: false
}
override suspend fun setAmoledTheme(enabled: Boolean) {
preferences.edit { prefs ->
prefs[AMOLED_KEY] = enabled
}
}
override fun getFontTheme(): Flow =
preferences.data.map { prefs ->
val fontName = prefs[FONT_KEY]
FontTheme.fromName(fontName)
}
override suspend fun setFontTheme(fontTheme: FontTheme) {
preferences.edit { prefs ->
prefs[FONT_KEY] = fontTheme.name
}
}
override fun getAutoDetectClipboardLinks(): Flow =
preferences.data.map { prefs ->
prefs[AUTO_DETECT_CLIPBOARD_KEY] ?: false
}
override suspend fun setAutoDetectClipboardLinks(enabled: Boolean) {
preferences.edit { prefs ->
prefs[AUTO_DETECT_CLIPBOARD_KEY] = enabled
}
}
override fun getInstallerType(): Flow =
preferences.data.map { prefs ->
val name = prefs[INSTALLER_TYPE_KEY]
InstallerType.fromName(name)
}
override suspend fun setInstallerType(type: InstallerType) {
preferences.edit { prefs ->
prefs[INSTALLER_TYPE_KEY] = type.name
}
}
override fun getAutoUpdateEnabled(): Flow =
preferences.data.map { prefs ->
prefs[AUTO_UPDATE_KEY] ?: false
}
override suspend fun setAutoUpdateEnabled(enabled: Boolean) {
preferences.edit { prefs ->
prefs[AUTO_UPDATE_KEY] = enabled
}
}
override fun getUpdateCheckInterval(): Flow =
preferences.data.map { prefs ->
prefs[UPDATE_CHECK_INTERVAL_KEY] ?: DEFAULT_UPDATE_CHECK_INTERVAL_HOURS
}
override suspend fun setUpdateCheckInterval(hours: Long) {
preferences.edit { prefs ->
prefs[UPDATE_CHECK_INTERVAL_KEY] = hours
}
}
override fun getIncludePreReleases(): Flow =
preferences.data.map { prefs ->
prefs[INCLUDE_PRE_RELEASES_KEY] ?: false
}
override suspend fun setIncludePreReleases(enabled: Boolean) {
preferences.edit { prefs ->
prefs[INCLUDE_PRE_RELEASES_KEY] = enabled
}
}
override fun getLiquidGlassEnabled(): Flow =
preferences.data.map { prefs ->
prefs[LIQUID_GLASS_ENABLED_KEY] ?: true
}
override suspend fun setLiquidGlassEnabled(enabled: Boolean) {
preferences.edit { prefs ->
prefs[LIQUID_GLASS_ENABLED_KEY] = enabled
}
}
override fun getHideSeenEnabled(): Flow =
preferences.data.map { prefs ->
prefs[HIDE_SEEN_ENABLED_KEY] ?: false
}
override suspend fun setHideSeenEnabled(enabled: Boolean) {
preferences.edit { prefs ->
prefs[HIDE_SEEN_ENABLED_KEY] = enabled
}
}
companion object {
const val DEFAULT_UPDATE_CHECK_INTERVAL_HOURS = 6L
}
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/services/FileLocationsProvider.kt
================================================
package zed.rainxch.core.data.services
interface FileLocationsProvider {
fun appDownloadsDir(): String
fun userDownloadsDir(): String
fun setExecutableIfNeeded(path: String)
fun getCacheSizeBytes(): Long
fun clearCacheFiles(): Boolean
}
================================================
FILE: core/data/src/commonMain/kotlin/zed/rainxch/core/data/services/LocalizationManager.kt
================================================
package zed.rainxch.core.data.services
interface LocalizationManager {
/**
* Returns the current device language code in ISO 639-1 format (e.g., "en", "zh", "ja")
* Can include region code if available (e.g., "zh-CN", "pt-BR")
*/
fun getCurrentLanguageCode(): String
/**
* Returns the primary language code without region (e.g., "zh" from "zh-CN")
*/
fun getPrimaryLanguageCode(): String
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/di/PlatformModule.jvm.kt
================================================
package zed.rainxch.core.data.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import org.koin.dsl.module
import zed.rainxch.core.data.local.data_store.createDataStore
import zed.rainxch.core.data.local.db.AppDatabase
import zed.rainxch.core.data.local.db.initDatabase
import zed.rainxch.core.data.services.DesktopInstallerInfoExtractor
import zed.rainxch.core.data.utils.DesktopAppLauncher
import zed.rainxch.core.data.utils.DesktopBrowserHelper
import zed.rainxch.core.data.utils.DesktopClipboardHelper
import zed.rainxch.core.data.services.DesktopDownloader
import zed.rainxch.core.data.services.DesktopFileLocationsProvider
import zed.rainxch.core.data.services.DesktopInstaller
import zed.rainxch.core.data.services.DesktopLocalizationManager
import zed.rainxch.core.data.services.DesktopPackageMonitor
import zed.rainxch.core.data.services.DesktopUpdateScheduleManager
import zed.rainxch.core.data.services.FileLocationsProvider
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerStatusProvider
import zed.rainxch.core.domain.system.UpdateScheduleManager
import zed.rainxch.core.data.services.LocalizationManager
import zed.rainxch.core.data.services.DesktopInstallerStatusProvider
import zed.rainxch.core.data.utils.DesktopShareManager
import zed.rainxch.core.domain.network.Downloader
import zed.rainxch.core.domain.system.PackageMonitor
import zed.rainxch.core.domain.utils.AppLauncher
import zed.rainxch.core.domain.utils.BrowserHelper
import zed.rainxch.core.domain.utils.ClipboardHelper
import zed.rainxch.core.domain.utils.ShareManager
actual val corePlatformModule = module {
// Core
single {
DesktopDownloader(
files = get(),
)
}
single {
DesktopInstaller(
platform = get(),
installerInfoExtractor = DesktopInstallerInfoExtractor(),
)
}
single {
DesktopFileLocationsProvider(
platform = get()
)
}
single {
DesktopPackageMonitor()
}
single {
DesktopLocalizationManager()
}
// Locals
single {
initDatabase()
}
single> {
createDataStore()
}
// Utils
single {
DesktopBrowserHelper()
}
single {
DesktopClipboardHelper()
}
single {
DesktopAppLauncher(
logger = get(),
platform = get()
)
}
single {
DesktopShareManager()
}
single {
DesktopInstallerStatusProvider()
}
single {
DesktopUpdateScheduleManager()
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/local/data_store/createDataStore.kt
================================================
package zed.rainxch.core.data.local.data_store
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import java.io.File
fun createDataStore(): DataStore =
createDataStore(
producePath = {
val file = File(System.getProperty("java.io.tmpdir"), dataStoreFileName)
file.absolutePath
},
)
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/local/db/initDatabase.kt
================================================
package zed.rainxch.core.data.local.db
import androidx.room.Room
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import kotlinx.coroutines.Dispatchers
import java.io.File
fun initDatabase(): AppDatabase {
val dbFile = File(System.getProperty("java.io.tmpdir"), "github_store.db")
return Room
.databaseBuilder(
name = dbFile.absolutePath,
).setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.fallbackToDestructiveMigration(true)
.build()
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/model/LinuxPackageType.kt
================================================
package zed.rainxch.core.data.model
enum class LinuxPackageType {
DEB, // Debian/Ubuntu/Mint
RPM, // Fedora/RHEL/CentOS/openSUSE
UNIVERSAL, // Unknown - show AppImage only
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/model/LinuxTerminal.kt
================================================
package zed.rainxch.core.data.model
enum class LinuxTerminal {
GNOME_TERMINAL,
KONSOLE,
XTERM,
XFCE4_TERMINAL,
ALACRITTY,
KITTY,
TILIX,
MATE_TERMINAL,
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/network/HttpClientFactory.jvm.kt
================================================
package zed.rainxch.core.data.network
import io.ktor.client.HttpClient
import io.ktor.client.engine.ProxyBuilder
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.http.Url
import zed.rainxch.core.domain.model.ProxyConfig
import java.net.ProxySelector
import java.net.URI
actual fun createPlatformHttpClient(proxyConfig: ProxyConfig): HttpClient =
HttpClient(OkHttp) {
engine {
proxy =
when (proxyConfig) {
is ProxyConfig.None -> {
null
}
is ProxyConfig.System -> {
val systemProxy =
ProxySelector
.getDefault()
?.select(URI("https://api.github.com"))
?.firstOrNull { it.type() != java.net.Proxy.Type.DIRECT }
if (systemProxy != null) {
val addr = systemProxy.address() as? java.net.InetSocketAddress
if (addr != null) {
when (systemProxy.type()) {
java.net.Proxy.Type.HTTP -> {
ProxyBuilder.http(Url("http://${addr.hostString}:${addr.port}"))
}
java.net.Proxy.Type.SOCKS -> {
ProxyBuilder.socks(addr.hostString, addr.port)
}
else -> {
null
}
}
} else {
null
}
} else {
null
}
}
is ProxyConfig.Http -> {
ProxyBuilder.http(Url("http://${proxyConfig.host}:${proxyConfig.port}"))
}
is ProxyConfig.Socks -> {
ProxyBuilder.socks(proxyConfig.host, proxyConfig.port)
}
}
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopDownloader.kt
================================================
package zed.rainxch.core.data.services
import co.touchlab.kermit.Logger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.withContext
import okhttp3.Call
import okhttp3.Credentials
import okhttp3.OkHttpClient
import okhttp3.Request
import zed.rainxch.core.data.network.ProxyManager
import zed.rainxch.core.domain.model.DownloadProgress
import zed.rainxch.core.domain.model.ProxyConfig
import zed.rainxch.core.domain.network.Downloader
import java.io.File
import java.net.Authenticator
import java.net.InetSocketAddress
import java.net.PasswordAuthentication
import java.net.Proxy
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
class DesktopDownloader(
private val files: FileLocationsProvider,
private val proxyManager: ProxyManager = ProxyManager,
) : Downloader {
private val activeDownloads = ConcurrentHashMap()
private val nameToId = ConcurrentHashMap()
private fun buildClient(): OkHttpClient {
Authenticator.setDefault(null)
return OkHttpClient
.Builder()
.apply {
when (val config = proxyManager.currentProxyConfig.value) {
is ProxyConfig.None -> {
proxy(Proxy.NO_PROXY)
}
is ProxyConfig.System -> {}
is ProxyConfig.Http -> {
proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(config.host, config.port)))
if (config.username != null && config.password != null) {
proxyAuthenticator { _, response ->
response.request
.newBuilder()
.header(
"Proxy-Authorization",
Credentials.basic(config.username!!, config.password!!),
).build()
}
}
}
is ProxyConfig.Socks -> {
proxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress(config.host, config.port)))
if (config.username != null && config.password != null) {
Authenticator.setDefault(
object : Authenticator() {
override fun getPasswordAuthentication() =
PasswordAuthentication(
config.username,
config.password!!.toCharArray(),
)
},
)
}
}
}
}.build()
}
override fun download(
url: String,
suggestedFileName: String?,
): Flow =
flow {
val client = buildClient()
val dir = File(files.userDownloadsDir())
if (!dir.exists()) dir.mkdirs()
val rawName =
suggestedFileName?.takeIf { it.isNotBlank() }
?: url
.substringAfterLast('/')
.substringBefore('?')
.substringBefore('#')
.ifBlank { "asset-${UUID.randomUUID()}" }
val safeName = rawName.substringAfterLast('/').substringAfterLast('\\')
require(safeName.isNotBlank() && safeName != "." && safeName != "..") {
"Invalid file name: $rawName"
}
val downloadId = UUID.randomUUID().toString()
val previous = nameToId.putIfAbsent(safeName, downloadId)
if (previous != null) {
throw IllegalStateException("A download for '$safeName' is already in progress")
}
val destination = File(dir, safeName)
if (destination.exists()) {
Logger.d { "Deleting existing file before download: ${destination.absolutePath}" }
destination.delete()
}
Logger.d { "Starting download: $url" }
val request = Request.Builder().url(url).build()
val call = client.newCall(request)
activeDownloads[downloadId] = call
try {
call.execute().use { response ->
if (!response.isSuccessful) {
throw kotlinx.io.IOException("Unexpected code ${response.code}")
}
val body = response.body
val contentLength = body.contentLength()
val total = if (contentLength > 0) contentLength else null
body.byteStream().use { input ->
destination.outputStream().use { output ->
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
var downloaded: Long = 0
var bytesRead: Int
while (input.read(buffer).also { bytesRead = it } != -1) {
output.write(buffer, 0, bytesRead)
downloaded += bytesRead
val percent =
if (total != null) ((downloaded * 100L) / total).toInt() else null
emit(DownloadProgress(downloaded, total, percent))
}
}
}
if (destination.exists() && destination.length() > 0) {
Logger.d { "Download complete: ${destination.absolutePath}" }
val finalDownloaded = destination.length()
val finalPercent =
if (total != null) ((finalDownloaded * 100L) / total).toInt() else 100
emit(DownloadProgress(finalDownloaded, total, finalPercent))
} else {
throw IllegalStateException("File not ready after download: ${destination.absolutePath}")
}
}
} catch (e: Exception) {
destination.delete()
Logger.e(e) { "Download failed" }
throw e
} finally {
activeDownloads.remove(downloadId)
nameToId.remove(safeName)
}
}.flowOn(Dispatchers.IO)
override suspend fun saveToFile(
url: String,
suggestedFileName: String?,
): String =
withContext(Dispatchers.IO) {
val rawName =
suggestedFileName?.takeIf { it.isNotBlank() }
?: url
.substringAfterLast('/')
.substringBefore('?')
.substringBefore('#')
.ifBlank { "asset-${UUID.randomUUID()}" }
val safeName = rawName.substringAfterLast('/').substringAfterLast('\\')
require(safeName.isNotBlank() && safeName != "." && safeName != "..") {
"Invalid file name: $rawName"
}
val file = File(files.userDownloadsDir(), safeName)
if (file.exists()) {
Logger.d { "Deleting existing file before download: ${file.absolutePath}" }
file.delete()
}
Logger.d { "saveToFile downloading file..." }
download(url, suggestedFileName).collect { }
file.absolutePath
}
override suspend fun getDownloadedFilePath(fileName: String): String? =
withContext(Dispatchers.IO) {
val file = File(files.userDownloadsDir(), fileName)
if (file.exists() && file.length() > 0) file.absolutePath else null
}
override suspend fun cancelDownload(fileName: String): Boolean =
withContext(Dispatchers.IO) {
var cancelled = false
var deleted = false
val downloadId = nameToId[fileName]
if (downloadId != null) {
activeDownloads[downloadId]?.let { call ->
if (!call.isCanceled()) {
call.cancel()
cancelled = true
}
}
activeDownloads.remove(downloadId)
nameToId.remove(fileName)
}
val file = File(files.userDownloadsDir(), fileName)
if (file.exists()) {
deleted = file.delete()
}
cancelled || deleted
}
companion object {
private const val DEFAULT_BUFFER_SIZE = 8 * 1024
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopFileLocationsProvider.kt
================================================
package zed.rainxch.core.data.services
import co.touchlab.kermit.Logger
import zed.rainxch.core.domain.model.Platform
import java.io.File
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission
class DesktopFileLocationsProvider(
private val platform: Platform,
) : FileLocationsProvider {
override fun appDownloadsDir(): String {
val baseDir =
when (platform) {
Platform.WINDOWS -> {
val appData =
System.getenv("LOCALAPPDATA")
?: (System.getProperty("user.home") + "\\AppData\\Local")
File(appData, "GithubStore\\Downloads")
}
Platform.MACOS -> {
val home = System.getProperty("user.home")
File(home, "Library/Caches/GithubStore/Downloads")
}
Platform.LINUX -> {
val cacheHome =
System.getenv("XDG_CACHE_HOME")
?: (System.getProperty("user.home") + "/.cache")
File(cacheHome, "githubstore/downloads")
}
else -> {
File(System.getProperty("user.home"), ".githubstore/downloads")
}
}
if (!baseDir.exists()) {
baseDir.mkdirs()
}
return baseDir.absolutePath
}
override fun setExecutableIfNeeded(path: String) {
if (platform == Platform.LINUX || platform == Platform.MACOS) {
try {
val file = File(path)
val filePath = file.toPath()
val perms = Files.getPosixFilePermissions(filePath).toMutableSet()
perms.add(PosixFilePermission.OWNER_EXECUTE)
perms.add(PosixFilePermission.GROUP_EXECUTE)
perms.add(PosixFilePermission.OTHERS_EXECUTE)
Files.setPosixFilePermissions(filePath, perms)
} catch (e: Exception) {
try {
Runtime.getRuntime().exec(arrayOf("chmod", "+x", path)).waitFor()
} catch (e2: Exception) {
println("Warning: Could not set executable permission on $path")
}
}
}
}
override fun userDownloadsDir(): String {
val appSubdirName = "GitHub Store Downloads"
val downloadsDir =
when (platform) {
Platform.WINDOWS -> {
val userProfile =
System.getenv("USERPROFILE")
?: System.getProperty("user.home")
File(userProfile, "Downloads").resolve(appSubdirName)
}
Platform.MACOS -> {
val home = System.getProperty("user.home")
File(home, "Downloads").resolve(appSubdirName)
}
Platform.LINUX -> {
val xdgDownloads = getXdgDownloadsDir()
val baseDir =
if (xdgDownloads != null) {
File(xdgDownloads)
} else {
val home = System.getProperty("user.home")
File(home, "Downloads")
}
baseDir.resolve(appSubdirName)
}
else -> {
File(System.getProperty("user.home"), "Downloads").resolve(appSubdirName)
}
}
if (!downloadsDir.exists()) {
downloadsDir.mkdirs()
}
return downloadsDir.absolutePath
}
override fun getCacheSizeBytes(): Long {
val appDir = File(appDownloadsDir())
val userDir = File(userDownloadsDir())
return calculateDirSize(appDir) + calculateDirSize(userDir)
}
override fun clearCacheFiles(): Boolean {
val appDir = File(appDownloadsDir())
val userDir = File(userDownloadsDir())
val appCleared = deleteDirectoryContents(appDir)
val userCleared = deleteDirectoryContents(userDir)
return appCleared && userCleared
}
private fun calculateDirSize(dir: File): Long {
if (!dir.exists()) return 0L
var size = 0L
dir.listFiles()?.forEach { file ->
size += if (file.isDirectory) calculateDirSize(file) else file.length()
}
return size
}
private fun deleteDirectoryContents(dir: File): Boolean {
if (!dir.exists()) return true
var allDeleted = true
dir.listFiles()?.forEach { file ->
if (file.isDirectory) {
if (!deleteDirectoryContents(file)) allDeleted = false
if (!file.delete()) allDeleted = false
} else {
if (!file.delete()) allDeleted = false
}
}
return allDeleted
}
private fun getXdgDownloadsDir(): String? {
return try {
val userDirsFile =
File(
System.getProperty("user.home"),
".config/user-dirs.dirs",
)
if (userDirsFile.exists()) {
userDirsFile.readLines().forEach { line ->
if (line.trim().startsWith("XDG_DOWNLOAD_DIR=")) {
val path =
line
.substringAfter("=")
.trim()
.removeSurrounding("\"")
.replace("\$HOME", System.getProperty("user.home"))
return path
}
}
}
null
} catch (e: Exception) {
Logger.w { "Failed to read XDG user dirs: ${e.message}" }
null
}
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt
================================================
package zed.rainxch.core.data.services
import co.touchlab.kermit.Logger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import zed.rainxch.core.data.model.LinuxPackageType
import zed.rainxch.core.data.model.LinuxTerminal
import zed.rainxch.core.domain.model.AssetArchitectureMatcher
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor
import java.awt.Desktop
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.io.File
import java.io.IOException
import kotlin.collections.iterator
import kotlin.getValue
class DesktopInstaller(
private val platform: Platform,
private val installerInfoExtractor: InstallerInfoExtractor,
) : Installer {
private val linuxPackageType: LinuxPackageType by lazy {
determineLinuxPackageType()
}
private val systemArchitecture: SystemArchitecture by lazy {
determineSystemArchitecture()
}
override fun getApkInfoExtractor(): InstallerInfoExtractor = installerInfoExtractor
override fun detectSystemArchitecture(): SystemArchitecture = systemArchitecture
override fun isObtainiumInstalled(): Boolean = false
override fun openInObtainium(
repoOwner: String,
repoName: String,
onOpenInstaller: () -> Unit,
) {
}
override fun isAppManagerInstalled(): Boolean = false
override fun openInAppManager(
filePath: String,
onOpenInstaller: () -> Unit,
) {
}
override fun openApp(packageName: String): Boolean {
// Desktop apps are launched differently per platform
Logger.d { "Open app not supported on desktop for: $packageName" }
return false
}
override fun openWithExternalInstaller(filePath: String) {
// Not applicable on desktop
}
override fun isAssetInstallable(assetName: String): Boolean {
val name = assetName.lowercase()
val hasValidExtension =
when (platform) {
Platform.ANDROID -> {
name.endsWith(".apk")
}
Platform.WINDOWS -> {
name.endsWith(".msi") || name.endsWith(".exe")
}
Platform.MACOS -> {
name.endsWith(".dmg") || name.endsWith(".pkg")
}
Platform.LINUX -> {
name.endsWith(".appimage") || name.endsWith(".deb") || name.endsWith(".rpm")
}
}
if (!hasValidExtension) return false
return isArchitectureCompatible(name, systemArchitecture)
}
override fun choosePrimaryAsset(assets: List): GithubAsset? {
if (assets.isEmpty()) return null
val priority =
when (platform) {
Platform.ANDROID -> {
listOf(".apk")
}
Platform.WINDOWS -> {
listOf(".msi", ".exe")
}
Platform.MACOS -> {
listOf(".dmg", ".pkg")
}
Platform.LINUX -> {
when (linuxPackageType) {
LinuxPackageType.DEB -> listOf(".appimage", ".deb", ".rpm")
LinuxPackageType.RPM -> listOf(".appimage", ".rpm", ".deb")
LinuxPackageType.UNIVERSAL -> listOf(".appimage", ".deb", ".rpm")
}
}
}
val compatibleAssets =
assets.filter { asset ->
isArchitectureCompatible(asset.name.lowercase(), systemArchitecture)
}
val assetsToConsider = compatibleAssets.ifEmpty { assets }
return assetsToConsider.maxByOrNull { asset ->
val name = asset.name.lowercase()
val extensionIdx = priority.indexOfFirst { name.endsWith(it) }
val extensionScore =
if (extensionIdx == -1) {
-100000
} else {
(priority.size - extensionIdx) * 10000
}
val archScore =
if (isExactArchitectureMatch(name, systemArchitecture)) {
1000
} else {
0
}
val sizeScore = (asset.size / 1000000).coerceAtMost(100)
extensionScore + archScore + sizeScore
}
}
private fun determineSystemArchitecture(): SystemArchitecture {
if (platform == Platform.MACOS) {
try {
val process = ProcessBuilder("uname", "-m").start()
val output =
process.inputStream
.bufferedReader()
.readText()
.trim()
process.waitFor()
return when (output) {
"arm64" -> SystemArchitecture.AARCH64
"x86_64" -> SystemArchitecture.X86_64
else -> SystemArchitecture.fromString(System.getProperty("os.arch"))
}
} catch (_: Exception) {
}
}
val osArch = System.getProperty("os.arch") ?: return SystemArchitecture.UNKNOWN
return SystemArchitecture.fromString(osArch)
}
private fun determineLinuxPackageType(): LinuxPackageType {
if (platform != Platform.LINUX) return LinuxPackageType.UNIVERSAL
return try {
val osRelease = tryReadOsRelease()
if (osRelease != null) {
val idLike = osRelease["ID_LIKE"]?.lowercase() ?: ""
val id = osRelease["ID"]?.lowercase() ?: ""
if (id in listOf("debian", "ubuntu", "linuxmint", "pop", "elementary") ||
idLike.contains("debian") || idLike.contains("ubuntu")
) {
Logger.d { "Detected Debian-based distribution: $id" }
return LinuxPackageType.DEB
}
if (id in
listOf(
"fedora",
"rhel",
"centos",
"rocky",
"almalinux",
"opensuse",
"suse",
) ||
idLike.contains("fedora") || idLike.contains("rhel") ||
idLike.contains("suse") || idLike.contains("centos")
) {
Logger.d { "Detected RPM-based distribution: $id" }
return LinuxPackageType.RPM
}
}
if (commandExists("apt") || commandExists("apt-get")) {
Logger.d { "Detected package manager: apt" }
return LinuxPackageType.DEB
}
if (commandExists("dnf")) {
Logger.d { "Detected package manager: dnf" }
return LinuxPackageType.RPM
}
if (commandExists("yum")) {
Logger.d { "Detected package manager: yum" }
return LinuxPackageType.RPM
}
if (commandExists("zypper")) {
Logger.d { "Detected package manager: zypper" }
return LinuxPackageType.RPM
}
Logger.d { "Could not determine package type, defaulting to UNIVERSAL" }
LinuxPackageType.UNIVERSAL
} catch (e: Exception) {
Logger.w { "Failed to detect Linux package type: ${e.message}" }
LinuxPackageType.UNIVERSAL
}
}
private fun tryReadOsRelease(): Map? {
val osReleaseFiles =
listOf(
"/etc/os-release",
"/usr/lib/os-release",
)
for (filePath in osReleaseFiles) {
try {
val file = File(filePath)
if (file.exists()) {
val content = file.readText()
return parseOsRelease(content)
}
} catch (e: Exception) {
Logger.w { "Could not read $filePath: ${e.message}" }
}
}
return null
}
private fun parseOsRelease(content: String): Map {
val result = mutableMapOf()
content.lines().forEach { line ->
val trimmed = line.trim()
if (trimmed.isNotEmpty() && !trimmed.startsWith("#")) {
val parts = trimmed.split("=", limit = 2)
if (parts.size == 2) {
val key = parts[0].trim()
val value = parts[1].trim().removeSurrounding("\"")
result[key] = value
}
}
}
return result
}
private fun commandExists(command: String): Boolean =
try {
val process = ProcessBuilder("which", command).start()
process.waitFor() == 0
} catch (_: Exception) {
false
}
private fun isArchitectureCompatible(
assetName: String,
systemArch: SystemArchitecture,
): Boolean {
val name = assetName.lowercase()
if (platform == Platform.MACOS) {
if (name.contains("universal") || name.contains("darwin")) {
return true
}
if ((name.endsWith(".dmg") || name.endsWith(".pkg")) &&
!listOf("x86_64", "amd64", "arm64", "aarch64").any { name.contains(it) }
) {
return true
}
}
return AssetArchitectureMatcher.isCompatible(name, systemArch)
}
private fun isExactArchitectureMatch(
assetName: String,
systemArch: SystemArchitecture,
): Boolean = AssetArchitectureMatcher.isExactMatch(assetName, systemArch)
override suspend fun isSupported(extOrMime: String): Boolean {
val ext = extOrMime.lowercase().removePrefix(".")
return when (platform) {
Platform.WINDOWS -> ext in listOf("msi", "exe")
Platform.MACOS -> ext in listOf("dmg", "pkg")
Platform.LINUX -> ext in listOf("appimage", "deb", "rpm")
else -> false
}
}
override suspend fun ensurePermissionsOrThrow(extOrMime: String) =
withContext(Dispatchers.IO) {
val ext = extOrMime.lowercase().removePrefix(".")
if (platform == Platform.LINUX && ext == "appimage") {
try {
val tempFile = File.createTempFile("appimage_perm_test", ".tmp")
try {
val canSetExecutable = tempFile.setExecutable(true)
if (!canSetExecutable) {
throw IllegalStateException(
"Unable to set executable permissions. AppImage installation requires " +
"the ability to make files executable.",
)
}
} finally {
tempFile.delete()
}
} catch (e: IOException) {
throw IllegalStateException(
"Failed to verify permission capabilities for AppImage installation: ${e.message}",
e,
)
} catch (e: SecurityException) {
throw IllegalStateException(
"Security restrictions prevent setting executable permissions for AppImage files.",
e,
)
}
}
}
override fun uninstall(packageName: String) {
// Desktop doesn't have a unified uninstall mechanism
Logger.d { "Uninstall not supported on desktop for: $packageName" }
}
override suspend fun install(
filePath: String,
extOrMime: String,
) = withContext(Dispatchers.IO) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("File not found: $filePath")
}
val ext = extOrMime.lowercase().removePrefix(".")
when (platform) {
Platform.WINDOWS -> installWindows(file, ext)
Platform.MACOS -> installMacOS(file, ext)
Platform.LINUX -> installLinux(file, ext)
else -> throw UnsupportedOperationException("Installation not supported on $platform")
}
}
private fun installWindows(
file: File,
ext: String,
) {
when (ext) {
"msi" -> {
val pb = ProcessBuilder("msiexec", "/i", file.absolutePath)
pb.start()
}
"exe" -> {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(file)
} else {
val pb = ProcessBuilder(file.absolutePath)
pb.start()
}
}
else -> {
throw IllegalArgumentException("Unsupported Windows installer: .$ext")
}
}
}
private fun installMacOS(
file: File,
ext: String,
) {
when (ext) {
"dmg" -> {
val pb = ProcessBuilder("open", file.absolutePath)
pb.start()
tryShowNotification(
title = "Installation Started",
message = "Please drag the application to your Applications folder",
)
}
"pkg" -> {
try {
val script =
"""
do shell script "installer -pkg '${file.absolutePath}' -target /" with administrator privileges
""".trimIndent()
val pb = ProcessBuilder("osascript", "-e", script)
val process = pb.start()
val exitCode = process.waitFor()
if (exitCode != 0) {
throw IOException("Installation cancelled or failed")
}
Logger.d { "PKG installed successfully" }
} catch (e: Exception) {
Logger.w { "Automated install failed, opening installer GUI: ${e.message}" }
ProcessBuilder("open", file.absolutePath).start()
}
}
else -> {
throw IllegalArgumentException("Unsupported macOS installer: .$ext")
}
}
}
private fun tryShowNotification(
title: String,
message: String,
) {
if (platform == Platform.MACOS) {
try {
val script =
"""
display notification "$message" with title "$title"
""".trimIndent()
ProcessBuilder("osascript", "-e", script).start()
} catch (e: Exception) {
Logger.w { "Could not show macOS notification: ${e.message}" }
}
} else {
try {
ProcessBuilder(
"notify-send",
title,
message,
"-u",
"critical",
"-t",
"10000",
).start()
} catch (e: Exception) {
Logger.w { "Could not show notification: ${e.message}" }
}
}
}
private fun installLinux(
file: File,
ext: String,
) {
when (ext) {
"appimage" -> {
installAppImage(file)
}
"deb" -> {
installDebPackage(file)
}
"rpm" -> {
installRpmPackage(file)
}
else -> {
throw IllegalArgumentException("Unsupported Linux installer: .$ext")
}
}
}
private fun installDebPackage(file: File) {
Logger.d { "Installing DEB package: ${file.absolutePath}" }
if (linuxPackageType == LinuxPackageType.RPM) {
Logger.i { "Detected DEB package on RPM system. Initiating conversion flow." }
openTerminalForAlienConversion(file.absolutePath)
return
}
val installMethods =
listOf(
listOf("pkexec", "apt", "install", "-y", file.absolutePath),
listOf("pkexec", "sh", "-c", "dpkg -i '${file.absolutePath}' || apt-get install -f -y"),
listOf("gdebi-gtk", file.absolutePath),
null,
)
for (method in installMethods) {
if (method == null) {
openTerminalForDebInstall(file.absolutePath)
return
}
try {
Logger.d { "Trying installation method: ${method.joinToString(" ")}" }
val process = ProcessBuilder(method).start()
val exitCode = process.waitFor()
if (exitCode == 0) {
Logger.d { "DEB package installed successfully" }
tryShowNotification("Installation Complete", "Package installed successfully")
return
} else {
Logger.w { "Installation method failed with exit code: $exitCode" }
}
} catch (e: IOException) {
Logger.w { "Installation method not available: ${e.message}" }
}
}
throw IOException("Could not install DEB package. Please install it manually.")
}
private fun openTerminalForAlienConversion(filePath: String) {
Logger.d { "Opening terminal for Alien conversion and installation" }
val availableTerminals = detectAvailableTerminals()
if (availableTerminals.isEmpty()) {
Logger.e { "No terminal emulator found for conversion" }
tryShowNotification(
"Conversion Required",
"Please install 'alien', convert '$filePath' to RPM, and install manually.",
)
throw IOException("No terminal found to run Alien conversion.")
}
val command =
buildString {
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'DEB Package on RPM System Detected'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("echo 'This package will be converted to RPM format.'; ")
append("echo 'This requires the \"alien\" tool.'; ")
append("echo ''; ")
append("if ! command -v alien &> /dev/null; then ")
append("echo 'Installing alien and rpm-build...'; ")
append("sudo dnf install -y alien rpm-build 2>/dev/null || ")
append("sudo yum install -y alien rpm-build 2>/dev/null || ")
append("sudo zypper install -y alien rpm-build 2>/dev/null; ")
append("fi; ")
append("if ! command -v alien &> /dev/null; then ")
append("echo ''; ")
append("echo 'ERROR: Failed to install alien.'; ")
append("echo 'Please install it manually: sudo dnf install alien rpm-build'; ")
append("echo ''; ")
append("echo 'Press Enter to close...'; read; exit 1; ")
append("fi; ")
append("echo ''; ")
append("echo 'Converting to RPM (this may take a minute)...'; ")
append("TMPDIR=/tmp/alien_install_$; ")
append($$"mkdir -p \"$TMPDIR\" && cd \"$TMPDIR\" || exit 1; ")
append("cp '$filePath' ./package.deb; ")
append("sudo alien -r -c package.deb; ")
append("if [ ! -f *.rpm ]; then ")
append("echo ''; ")
append("echo 'ERROR: Conversion failed.'; ")
append($$"cd .. && rm -rf \"$TMPDIR\"; ")
append("echo 'Press Enter to close...'; read; exit 1; ")
append("fi; ")
append("echo ''; ")
append("echo 'Installing converted RPM...'; ")
append("INSTALL_SUCCESS=0; ")
append("if sudo dnf install -y ./*.rpm 2>&1; then INSTALL_SUCCESS=1; ")
append("elif sudo yum install -y ./*.rpm 2>&1; then INSTALL_SUCCESS=1; ")
append("elif sudo zypper install -y --allow-unsigned-rpm ./*.rpm 2>&1; then INSTALL_SUCCESS=1; ")
append("elif sudo rpm -ivh --nodeps --force ./*.rpm 2>&1; then INSTALL_SUCCESS=1; ")
append("fi; ")
append("echo ''; ")
append($$"if [ $INSTALL_SUCCESS -eq 1 ]; then ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installation Complete!'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("else ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installation Failed!'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("echo 'The RPM was created but installation failed.'; ")
append("echo 'This usually happens due to file conflicts.'; ")
append("echo ''; ")
append("echo 'The converted RPM is located at:'; ")
append($$"echo \"$TMPDIR/\"*.rpm; ")
append("echo ''; ")
append("echo 'You can try installing it manually with:'; ")
append($$"echo \"sudo rpm -ivh --force $TMPDIR/\"*.rpm; ")
append("echo ''; ")
append("echo 'Or open the file with your software manager.'; ")
append("fi; ")
append($$"cd .. && rm -rf \"$TMPDIR\"; ")
append("echo ''; ")
append("echo 'Press Enter to close...'; read")
}
runCommandInTerminal(command, availableTerminals)
}
private fun installRpmPackage(file: File) {
Logger.d { "Installing RPM package: ${file.absolutePath}" }
val installMethods =
listOf(
listOf("pkexec", "dnf", "install", "-y", "--nogpgcheck", file.absolutePath),
listOf("pkexec", "yum", "install", "-y", "--nogpgcheck", file.absolutePath),
listOf("pkexec", "zypper", "install", "-y", "--no-gpg-checks", file.absolutePath),
listOf("pkexec", "rpm", "-ivh", "--nosignature", file.absolutePath),
null,
)
for (method in installMethods) {
if (method == null) {
openTerminalForRpmInstall(file.absolutePath)
return
}
try {
Logger.d { "Trying installation method: ${method.joinToString(" ")}" }
val process = ProcessBuilder(method).start()
val exitCode = process.waitFor()
if (exitCode == 0) {
Logger.d { "RPM package installed successfully" }
tryShowNotification("Installation Complete", "Package installed successfully")
return
} else {
Logger.w { "Installation method failed with exit code: $exitCode" }
}
} catch (e: IOException) {
Logger.w { "Installation method not available: ${e.message}" }
}
}
throw IOException("Could not install RPM package. Please install it manually.")
}
private fun openTerminalForDebInstall(filePath: String) {
val command =
buildString {
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installing DEB Package'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("sudo dpkg -i '$filePath' && sudo apt-get install -f -y; ")
append("echo ''; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installation Complete!'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("echo 'Press Enter to close...'; read")
}
val availableTerminals = detectAvailableTerminals()
if (availableTerminals.isEmpty()) {
tryShowNotification(
"Installation Required",
"Please install manually using your file manager",
)
tryCopyToClipboard("sudo dpkg -i '$filePath' && sudo apt-get install -f -y")
throw IOException("No terminal emulator found.")
}
runCommandInTerminal(command, availableTerminals)
}
private fun openTerminalForRpmInstall(filePath: String) {
val command =
buildString {
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installing RPM Package'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("sudo dnf install -y --nogpgcheck '$filePath' 2>/dev/null || ")
append("sudo yum install -y --nogpgcheck '$filePath' 2>/dev/null || ")
append("sudo zypper install -y --no-gpg-checks '$filePath' 2>/dev/null || ")
append("sudo rpm -ivh --nosignature '$filePath'; ")
append("echo ''; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo 'Installation Complete!'; ")
append("echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'; ")
append("echo ''; ")
append("echo 'Press Enter to close...'; read")
}
val availableTerminals = detectAvailableTerminals()
if (availableTerminals.isEmpty()) {
tryShowNotification(
"Installation Required",
"Please install manually using your file manager",
)
tryCopyToClipboard("sudo dnf install -y --nogpgcheck '$filePath'")
throw IOException("No terminal emulator found.")
}
runCommandInTerminal(command, availableTerminals)
}
private fun runCommandInTerminal(
command: String,
terminals: List,
) {
for (terminal in terminals) {
try {
Logger.d { "Trying terminal: ${terminal.name}" }
val processBuilder =
when (terminal) {
LinuxTerminal.GNOME_TERMINAL -> {
ProcessBuilder(
"gnome-terminal",
"--",
"bash",
"-c",
command,
)
}
LinuxTerminal.KONSOLE -> {
ProcessBuilder(
"konsole",
"-e",
"bash",
"-c",
command,
)
}
LinuxTerminal.XTERM -> {
ProcessBuilder(
"xterm",
"-e",
"bash",
"-c",
command,
)
}
LinuxTerminal.XFCE4_TERMINAL -> {
ProcessBuilder(
"xfce4-terminal",
"-e",
"bash -c \"$command\"",
)
}
LinuxTerminal.ALACRITTY -> {
ProcessBuilder(
"alacritty",
"-e",
"bash",
"-c",
command,
)
}
LinuxTerminal.KITTY -> {
ProcessBuilder(
"kitty",
"bash",
"-c",
command,
)
}
LinuxTerminal.TILIX -> {
ProcessBuilder(
"tilix",
"-e",
"bash -c \"$command\"",
)
}
LinuxTerminal.MATE_TERMINAL -> {
ProcessBuilder(
"mate-terminal",
"-e",
"bash -c \"$command\"",
)
}
}
processBuilder.start()
Logger.d { "Terminal opened successfully: ${terminal.name}" }
return
} catch (e: IOException) {
Logger.w { "Failed to open ${terminal.name}: ${e.message}" }
}
}
throw IOException("Could not open any terminal emulator")
}
private fun detectAvailableTerminals(): List {
val availableTerminals = mutableListOf()
val terminalCommands =
mapOf(
LinuxTerminal.GNOME_TERMINAL to "gnome-terminal",
LinuxTerminal.KONSOLE to "konsole",
LinuxTerminal.XFCE4_TERMINAL to "xfce4-terminal",
LinuxTerminal.ALACRITTY to "alacritty",
LinuxTerminal.KITTY to "kitty",
LinuxTerminal.TILIX to "tilix",
LinuxTerminal.MATE_TERMINAL to "mate-terminal",
LinuxTerminal.XTERM to "xterm",
)
for ((terminal, command) in terminalCommands) {
if (commandExists(command)) {
availableTerminals.add(terminal)
Logger.d { "Found terminal: $command" }
}
}
return availableTerminals
}
private fun tryCopyToClipboard(text: String) {
try {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
clipboard.setContents(StringSelection(text), null)
Logger.d { "Command copied to clipboard" }
} catch (e: Exception) {
Logger.w { "Could not copy to clipboard: ${e.message}" }
}
}
private fun installAppImage(file: File) {
Logger.d { "Installing AppImage: ${file.absolutePath}" }
try {
Logger.d { "Moving AppImage to ~/Applications..." }
val installedFile = moveToApplicationsDirectory(file)
Logger.d { "Moved to: ${installedFile.absolutePath}" }
Logger.d { "Setting executable permissions..." }
val executableSet = installedFile.setExecutable(true, false)
Logger.d { "Set executable via Java: $executableSet" }
if (!executableSet) {
Logger.w { "Failed to set executable via Java, trying chmod..." }
val chmodProcess = ProcessBuilder("chmod", "+x", installedFile.absolutePath).start()
val chmodExitCode = chmodProcess.waitFor()
Logger.d { "chmod exit code: $chmodExitCode" }
}
if (!installedFile.canExecute()) {
throw IllegalStateException("Failed to make AppImage executable")
}
Logger.d { "AppImage is now executable" }
Logger.d { "Launching AppImage..." }
val process =
ProcessBuilder(installedFile.absolutePath)
.inheritIO()
.start()
Logger.d { "AppImage launched successfully (PID: ${process.pid()})" }
showInstallationNotification(installedFile)
Logger.d { "AppImage installation completed successfully" }
} catch (e: IOException) {
Logger.e { "Failed to install AppImage: ${e.message}" }
e.printStackTrace()
throw IllegalStateException(
"Failed to install AppImage: ${e.message}. " +
"Please ensure you have write permissions to ~/Applications folder.",
e,
)
} catch (e: SecurityException) {
Logger.e { "Security exception: ${e.message}" }
e.printStackTrace()
throw IllegalStateException(
"Security restrictions prevent installing AppImage.",
e,
)
} catch (e: Exception) {
Logger.e { "Unexpected error: ${e.message}" }
e.printStackTrace()
throw IllegalStateException("Failed to install AppImage: ${e.message}", e)
}
}
/**
* Move AppImage to ~/Applications directory
* Creates the directory if it doesn't exist
*/
private fun moveToApplicationsDirectory(file: File): File {
val homeDir = System.getProperty("user.home")
val applicationsDir = File(homeDir, "Applications")
if (!applicationsDir.exists()) {
Logger.d { "Creating ~/Applications directory..." }
val created = applicationsDir.mkdirs()
Logger.d { "Directory created: $created" }
}
if (file.parent == applicationsDir.absolutePath) {
Logger.d { "AppImage already in ~/Applications, no move needed" }
return file
}
val destinationFile = File(applicationsDir, file.name)
val finalDestination =
if (destinationFile.exists()) {
Logger.d { "File already exists in ~/Applications, generating unique name" }
generateUniqueFileName(applicationsDir, file.name)
} else {
destinationFile
}
Logger.d { "Moving from: ${file.absolutePath}" }
Logger.d { "Moving to: ${finalDestination.absolutePath}" }
file.copyTo(finalDestination, overwrite = false)
Logger.d { "Copy successful, file size: ${finalDestination.length()} bytes" }
val deleted = file.delete()
Logger.d { "Original file deleted: $deleted" }
if (!finalDestination.exists()) {
throw IllegalStateException("File was moved but doesn't exist at destination")
}
return finalDestination
}
private fun showInstallationNotification(file: File) {
try {
val message = "AppImage installed and launched from ~/Applications"
Logger.i { message }
Logger.i { "Location: ${file.absolutePath}" }
ProcessBuilder(
"notify-send",
"-i",
"application-x-executable",
"AppImage Installed",
"Installed to ~/Applications\n\nYou can find it at:\n${file.name}",
).start()
} catch (e: Exception) {
Logger.d { "Could not show notification: ${e.message}" }
}
}
private fun generateUniqueFileName(
directory: File,
originalName: String,
): File {
val nameWithoutExtension = originalName.substringBeforeLast(".")
val extension = originalName.substringAfterLast(".", "")
var counter = 1
var candidateFile: File
do {
val newName =
if (extension.isNotEmpty()) {
"${nameWithoutExtension}_$counter.$extension"
} else {
"${nameWithoutExtension}_$counter"
}
candidateFile = File(directory, newName)
counter++
} while (candidateFile.exists() && counter < 1000)
if (candidateFile.exists()) {
throw IllegalStateException("Could not generate unique filename")
}
return candidateFile
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstallerInfoExtractor.kt
================================================
package zed.rainxch.core.data.services
import zed.rainxch.core.domain.model.ApkPackageInfo
import zed.rainxch.core.domain.system.InstallerInfoExtractor
class DesktopInstallerInfoExtractor : InstallerInfoExtractor {
override suspend fun extractPackageInfo(filePath: String): ApkPackageInfo? = null
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstallerStatusProvider.kt
================================================
package zed.rainxch.core.data.services
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import zed.rainxch.core.domain.model.ShizukuAvailability
import zed.rainxch.core.domain.system.InstallerStatusProvider
/**
* Desktop (JVM) no-op implementation of [InstallerStatusProvider].
* Shizuku is Android-only, so this always reports UNAVAILABLE.
*/
class DesktopInstallerStatusProvider : InstallerStatusProvider {
override val shizukuAvailability: StateFlow =
MutableStateFlow(ShizukuAvailability.UNAVAILABLE).asStateFlow()
override fun requestShizukuPermission() {
// No-op on desktop
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopLocalizationManager.kt
================================================
package zed.rainxch.core.data.services
import java.util.Locale
class DesktopLocalizationManager : LocalizationManager {
override fun getCurrentLanguageCode(): String {
val locale = Locale.getDefault()
val language = locale.language
val country = locale.country
return if (country.isNotEmpty()) {
"$language-$country"
} else {
language
}
}
override fun getPrimaryLanguageCode(): String = Locale.getDefault().language
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopPackageMonitor.kt
================================================
package zed.rainxch.core.data.services
import zed.rainxch.core.domain.model.DeviceApp
import zed.rainxch.core.domain.model.SystemPackageInfo
import zed.rainxch.core.domain.system.PackageMonitor
class DesktopPackageMonitor : PackageMonitor {
override suspend fun isPackageInstalled(packageName: String): Boolean = false
override suspend fun getInstalledPackageInfo(packageName: String): SystemPackageInfo? = null
override suspend fun getAllInstalledPackageNames(): Set = setOf()
override suspend fun getAllInstalledApps(): List = emptyList()
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopUpdateScheduleManager.kt
================================================
package zed.rainxch.core.data.services
import zed.rainxch.core.domain.system.UpdateScheduleManager
/**
* No-op implementation for Desktop — WorkManager is Android-only.
*/
class DesktopUpdateScheduleManager : UpdateScheduleManager {
override fun reschedule(intervalHours: Long) {
// No background scheduler on Desktop
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/utils/DesktopAppLauncher.kt
================================================
package zed.rainxch.core.data.utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import zed.rainxch.core.domain.logging.GitHubStoreLogger
import zed.rainxch.core.domain.model.InstalledApp
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.domain.utils.AppLauncher
import java.io.File
class DesktopAppLauncher(
private val logger: GitHubStoreLogger,
private val platform: Platform,
) : AppLauncher {
override suspend fun launchApp(installedApp: InstalledApp): Result =
withContext(Dispatchers.IO) {
runCatching {
when (platform) {
Platform.WINDOWS -> launchWindowsApp(installedApp)
Platform.MACOS -> launchMacOSApp(installedApp)
Platform.LINUX -> launchLinuxApp(installedApp)
else -> throw Exception("Unsupported platform: $platform")
}
}.onFailure { error ->
logger.error("Failed to launch app ${installedApp.appName}: ${error.message}")
}
}
override suspend fun canLaunchApp(installedApp: InstalledApp): Boolean =
withContext(Dispatchers.IO) {
when (platform) {
Platform.WINDOWS -> canLaunchWindowsApp(installedApp)
Platform.MACOS -> canLaunchMacOSApp(installedApp)
Platform.LINUX -> canLaunchLinuxApp(installedApp)
else -> false
}
}
private fun launchWindowsApp(installedApp: InstalledApp) {
val programFiles =
listOfNotNull(
System.getenv("ProgramFiles"),
System.getenv("ProgramFiles(x86)"),
System.getenv("LOCALAPPDATA"),
)
var launched = false
for (basePath in programFiles) {
val possiblePaths =
listOf(
File(basePath, installedApp.appName),
File(basePath, installedApp.repoName),
File(basePath, installedApp.packageName.substringAfterLast(".")),
)
for (appDir in possiblePaths) {
if (appDir.exists() && appDir.isDirectory) {
val exeFiles =
appDir
.walkTopDown()
.maxDepth(3)
.filter { it.extension.equals("exe", ignoreCase = true) }
.filter { !it.name.contains("uninstall", ignoreCase = true) }
.toList()
val mainExe =
exeFiles.find {
it.nameWithoutExtension.equals(installedApp.appName, ignoreCase = true) ||
it.nameWithoutExtension.equals(
installedApp.repoName,
ignoreCase = true,
)
} ?: exeFiles.firstOrNull()
if (mainExe != null) {
ProcessBuilder("cmd", "/c", "start", "", mainExe.absolutePath)
.start()
launched = true
logger.debug("Launched Windows app from: ${mainExe.absolutePath}")
break
}
}
}
if (launched) break
}
if (!launched) {
val appNameVariations =
listOf(
installedApp.appName,
installedApp.repoName,
installedApp.appName.replace(" ", ""),
)
for (name in appNameVariations) {
try {
ProcessBuilder("cmd", "/c", "start", "", name)
.start()
launched = true
logger.debug("Launched Windows app using shell: $name")
break
} catch (e: Exception) {
}
}
}
if (!launched) {
val displayName = findWindowsDisplayName(installedApp)
if (displayName != null) {
val installLocation = getWindowsInstallLocation(displayName)
if (installLocation != null) {
val installDir = File(installLocation)
val exeFiles =
installDir.listFiles { file ->
file.extension.equals("exe", ignoreCase = true) &&
!file.name.contains("uninstall", ignoreCase = true)
}
val mainExe = exeFiles?.firstOrNull()
if (mainExe != null) {
ProcessBuilder("cmd", "/c", "start", "", mainExe.absolutePath)
.start()
launched = true
logger.debug("Launched Windows app from registry location: ${mainExe.absolutePath}")
}
}
}
}
if (!launched) {
throw Exception("Could not find executable for ${installedApp.appName}")
}
}
private fun launchMacOSApp(installedApp: InstalledApp) {
val appName =
if (installedApp.appName.endsWith(".app")) {
installedApp.appName
} else {
"${installedApp.appName}.app"
}
val appPath = File("/Applications", appName)
if (appPath.exists()) {
ProcessBuilder("open", "-a", appPath.absolutePath).start()
logger.debug("Launched macOS app: ${appPath.absolutePath}")
return
}
val appsDir = File("/Applications")
val matchingApp =
appsDir.listFiles()?.find { file ->
file.isDirectory &&
file.name.endsWith(".app") &&
(
file.name.contains(installedApp.appName, ignoreCase = true) ||
file.name.contains(installedApp.repoName, ignoreCase = true)
)
}
if (matchingApp != null) {
ProcessBuilder("open", "-a", matchingApp.absolutePath).start()
logger.debug("Launched macOS app: ${matchingApp.absolutePath}")
return
}
try {
ProcessBuilder("open", "-b", installedApp.packageName).start()
logger.debug("Launched macOS app by bundle ID: ${installedApp.packageName}")
return
} catch (e: Exception) {
}
val userAppsDir = File(System.getProperty("user.home"), "Applications")
val userMatchingApp =
userAppsDir.listFiles()?.find { file ->
file.isDirectory &&
file.name.endsWith(".app") &&
(
file.name.contains(installedApp.appName, ignoreCase = true) ||
file.name.contains(installedApp.repoName, ignoreCase = true)
)
}
if (userMatchingApp != null) {
ProcessBuilder("open", "-a", userMatchingApp.absolutePath).start()
logger.debug("Launched macOS app from user folder: ${userMatchingApp.absolutePath}")
return
}
throw Exception("Could not find app for ${installedApp.appName}")
}
private fun launchLinuxApp(installedApp: InstalledApp) {
val commandVariations =
listOf(
installedApp.appName.lowercase().replace(" ", "-"),
installedApp.appName.lowercase().replace(" ", ""),
installedApp.repoName.lowercase(),
installedApp.packageName.substringAfterLast("."),
)
for (command in commandVariations) {
try {
ProcessBuilder(command).start()
logger.debug("Launched Linux app with command: $command")
return
} catch (e: Exception) {
}
}
val desktopFileDirs =
listOf(
"/usr/share/applications",
"/usr/local/share/applications",
"${System.getProperty("user.home")}/.local/share/applications",
)
for (dir in desktopFileDirs) {
val desktopDir = File(dir)
if (!desktopDir.exists()) continue
val desktopFile =
desktopDir.listFiles()?.find { file ->
file.extension.equals("desktop", ignoreCase = true) &&
(
file.nameWithoutExtension.contains(
installedApp.appName,
ignoreCase = true,
) ||
file.nameWithoutExtension.contains(
installedApp.repoName,
ignoreCase = true,
)
)
}
if (desktopFile != null) {
val execLine =
desktopFile
.readLines()
.find {
it.trim().startsWith("Exec=")
}?.substringAfter("Exec=")
if (execLine != null) {
val command = execLine.replace(Regex("%[fFuU]"), "").trim()
ProcessBuilder("sh", "-c", command).start()
logger.debug("Launched Linux app from .desktop file: $command")
return
}
}
}
try {
val flatpakList = executeCommand("flatpak", "list", "--app")
if (flatpakList.contains(installedApp.appName, ignoreCase = true) ||
flatpakList.contains(installedApp.repoName, ignoreCase = true)
) {
val appId =
flatpakList
.lines()
.find {
it.contains(installedApp.appName, ignoreCase = true) ||
it.contains(installedApp.repoName, ignoreCase = true)
}?.split(Regex("\\s+"))
?.firstOrNull()
if (appId != null) {
ProcessBuilder("flatpak", "run", appId).start()
logger.debug("Launched Linux app via flatpak: $appId")
return
}
}
} catch (e: Exception) {
}
if (installedApp.fileExtension.equals("appimage", ignoreCase = true)) {
val appImageDirs =
listOf(
"${System.getProperty("user.home")}/Applications",
"${System.getProperty("user.home")}/.local/bin",
"/opt",
)
for (dir in appImageDirs) {
val dirFile = File(dir)
val appImage =
dirFile.listFiles()?.find { file ->
file.extension.equals("appimage", ignoreCase = true) &&
file.nameWithoutExtension.contains(
installedApp.appName,
ignoreCase = true,
)
}
if (appImage != null && appImage.canExecute()) {
ProcessBuilder(appImage.absolutePath).start()
logger.debug("Launched AppImage: ${appImage.absolutePath}")
return
}
}
}
throw Exception("Could not launch ${installedApp.appName}")
}
private fun canLaunchWindowsApp(installedApp: InstalledApp): Boolean {
val programFiles =
listOfNotNull(
System.getenv("ProgramFiles"),
System.getenv("ProgramFiles(x86)"),
)
for (basePath in programFiles) {
val appDir = File(basePath, installedApp.appName)
if (appDir.exists() && appDir.isDirectory) {
val hasExe =
appDir
.walkTopDown()
.maxDepth(3)
.any { it.extension.equals("exe", ignoreCase = true) }
if (hasExe) return true
}
}
return false
}
private fun canLaunchMacOSApp(installedApp: InstalledApp): Boolean {
val appPath = File("/Applications", "${installedApp.appName}.app")
if (appPath.exists()) return true
val appsDir = File("/Applications")
return appsDir.listFiles()?.any { file ->
file.name.endsWith(".app") &&
file.name.contains(installedApp.appName, ignoreCase = true)
} ?: false
}
private fun canLaunchLinuxApp(installedApp: InstalledApp): Boolean {
val command = installedApp.appName.lowercase().replace(" ", "-")
val which = executeCommand("which", command)
if (which.isNotBlank()) return true
val desktopFileDirs =
listOf(
"/usr/share/applications",
"/usr/local/share/applications",
"${System.getProperty("user.home")}/.local/share/applications",
)
return desktopFileDirs.any { dir ->
File(dir).listFiles()?.any { file ->
file.extension.equals("desktop", ignoreCase = true) &&
file.nameWithoutExtension.contains(installedApp.appName, ignoreCase = true)
} ?: false
}
}
private fun findWindowsDisplayName(installedApp: InstalledApp): String? {
val searchName = installedApp.appName
val result =
executeCommand(
"powershell",
"-Command",
"Get-ItemProperty HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where-Object { \$_.DisplayName -like '*$searchName*' } | Select-Object -First 1 -ExpandProperty DisplayName",
)
return result.trim().takeIf { it.isNotBlank() }
}
private fun getWindowsInstallLocation(displayName: String): String? {
val result =
executeCommand(
"powershell",
"-Command",
"Get-ItemProperty HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where-Object { \$_.DisplayName -eq '$displayName' } | Select-Object -First 1 -ExpandProperty InstallLocation",
)
return result.trim().takeIf { it.isNotBlank() }
}
private fun executeCommand(vararg command: String): String =
try {
val process =
ProcessBuilder(*command)
.redirectErrorStream(true)
.start()
val output = process.inputStream.bufferedReader().readText()
process.waitFor()
output
} catch (e: Exception) {
""
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/utils/DesktopBrowserHelper.kt
================================================
package zed.rainxch.core.data.utils
import zed.rainxch.core.domain.utils.BrowserHelper
import java.awt.Desktop
import java.net.URI
class DesktopBrowserHelper : BrowserHelper {
override fun openUrl(
url: String,
onFailure: (error: String) -> Unit,
) {
val os = System.getProperty("os.name").lowercase()
try {
when {
os.contains("linux") -> {
val processBuilder = ProcessBuilder("xdg-open", url)
processBuilder.redirectErrorStream(true)
processBuilder.start()
}
Desktop.isDesktopSupported() &&
Desktop
.getDesktop()
.isSupported(Desktop.Action.BROWSE)
-> {
Desktop.getDesktop().browse(URI(url))
}
else -> {
onFailure("Cannot open browser automatically. Please visit: $url")
}
}
} catch (e: Exception) {
onFailure("Failed to open browser: ${e.message}. Please visit: $url")
}
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/utils/DesktopClipboardHelper.kt
================================================
package zed.rainxch.core.data.utils
import zed.rainxch.core.domain.utils.ClipboardHelper
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection
class DesktopClipboardHelper : ClipboardHelper {
override fun copy(
label: String,
text: String,
) {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
clipboard.setContents(StringSelection(text), null)
}
override fun getText(): String? =
try {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
clipboard.getData(DataFlavor.stringFlavor) as? String
} else {
null
}
} catch (_: Exception) {
null
}
}
================================================
FILE: core/data/src/jvmMain/kotlin/zed/rainxch/core/data/utils/DesktopShareManager.kt
================================================
package zed.rainxch.core.data.utils
import zed.rainxch.core.domain.utils.ShareManager
import java.awt.Desktop
import java.awt.FileDialog
import java.awt.Frame
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.io.File
import javax.swing.JFileChooser
import javax.swing.SwingUtilities
import javax.swing.filechooser.FileNameExtensionFilter
class DesktopShareManager : ShareManager {
override fun shareText(text: String) {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
val selection = StringSelection(text)
clipboard.setContents(selection, null)
}
override fun shareFile(fileName: String, content: String, mimeType: String) {
SwingUtilities.invokeLater {
val chooser = JFileChooser().apply {
dialogTitle = "Save exported apps"
selectedFile = File(fileName)
fileFilter = FileNameExtensionFilter("JSON files", "json")
}
val result = chooser.showSaveDialog(null)
if (result == JFileChooser.APPROVE_OPTION) {
var file = chooser.selectedFile
if (!file.name.endsWith(".json")) {
file = File(file.absolutePath + ".json")
}
file.writeText(content)
}
}
}
override fun pickFile(mimeType: String, onResult: (String?) -> Unit) {
SwingUtilities.invokeLater {
val chooser = JFileChooser().apply {
dialogTitle = "Select file to import"
fileFilter = FileNameExtensionFilter("JSON files", "json")
}
val result = chooser.showOpenDialog(null)
if (result == JFileChooser.APPROVE_OPTION) {
try {
val content = chooser.selectedFile.readText()
onResult(content)
} catch (e: Exception) {
onResult(null)
}
} else {
onResult(null)
}
}
}
}
================================================
FILE: core/domain/.gitignore
================================================
/build
================================================
FILE: core/domain/build.gradle.kts
================================================
plugins {
alias(libs.plugins.convention.kmp.library)
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
}
}
androidMain {
dependencies {
}
}
jvmMain {
dependencies {
}
}
}
}
================================================
FILE: core/domain/src/androidMain/AndroidManifest.xml
================================================
================================================
FILE: core/domain/src/androidMain/kotlin/zed/rainxch/core/domain/Platform.android.kt
================================================
package zed.rainxch.core.domain
import zed.rainxch.core.domain.model.Platform
actual fun getPlatform(): Platform = Platform.ANDROID
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/Platform.kt
================================================
package zed.rainxch.core.domain
import zed.rainxch.core.domain.model.Platform
expect fun getPlatform(): Platform
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/logging/GitHubStoreLogger.kt
================================================
package zed.rainxch.core.domain.logging
interface GitHubStoreLogger {
fun debug(message: String)
fun info(message: String)
fun warn(message: String)
fun error(
message: String,
throwable: Throwable? = null,
)
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/ApkPackageInfo.kt
================================================
package zed.rainxch.core.domain.model
data class ApkPackageInfo(
val packageName: String,
val versionName: String,
val versionCode: Long,
val appName: String,
val signingFingerprint: String?,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AppTheme.kt
================================================
package zed.rainxch.core.domain.model
enum class AppTheme {
DYNAMIC,
OCEAN,
PURPLE,
FOREST,
SLATE,
AMBER,
;
companion object {
fun fromName(name: String?): AppTheme = entries.find { it.name == name } ?: OCEAN
}
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AssetArchitectureMatcher.kt
================================================
package zed.rainxch.core.domain.model
object AssetArchitectureMatcher {
private val universalRegex =
Regex(
pattern = """(^|[^a-z0-9])(universal|noarch|all-arch|fat)([^a-z0-9]|$)""",
)
private val x86_64Regex =
Regex(
pattern = """(^|[^a-z0-9])(x86[_-]64|amd64|x64)([^a-z0-9]|$)""",
)
private val arm64Regex =
Regex(
pattern = """(^|[^a-z0-9])(aarch64|arm64|arm64-v8a|armv8a|armv8l|armv8|arm-v8|v8a)([^a-z0-9]|$)""",
)
private val x86Regex =
Regex(
pattern = """(^|[^a-z0-9])(i386|i686|x86)([^a-z0-9]|$)""",
)
private val armRegex =
Regex(
pattern = """(^|[^a-z0-9])(armeabi-v7a|armeabi|armv7a|armv7|arm-v7|v7a|arm)([^a-z0-9]|$)""",
)
fun detectArchitecture(assetName: String): SystemArchitecture? {
val name = assetName.lowercase().replace('_', '-')
if (universalRegex.containsMatchIn(name)) return null
if (x86_64Regex.containsMatchIn(name)) return SystemArchitecture.X86_64
if (arm64Regex.containsMatchIn(name)) return SystemArchitecture.AARCH64
if (x86Regex.containsMatchIn(name)) return SystemArchitecture.X86
if (armRegex.containsMatchIn(name)) return SystemArchitecture.ARM
return null
}
fun isCompatible(
assetName: String,
systemArch: SystemArchitecture,
): Boolean {
val assetArch = detectArchitecture(assetName) ?: return true
return when (systemArch) {
SystemArchitecture.X86_64 -> assetArch == SystemArchitecture.X86_64 || assetArch == SystemArchitecture.X86
SystemArchitecture.AARCH64 -> assetArch == SystemArchitecture.AARCH64 || assetArch == SystemArchitecture.ARM
SystemArchitecture.X86 -> assetArch == SystemArchitecture.X86
SystemArchitecture.ARM -> assetArch == SystemArchitecture.ARM
SystemArchitecture.UNKNOWN -> true
}
}
fun isExactMatch(
assetName: String,
systemArch: SystemArchitecture,
): Boolean {
val assetArch = detectArchitecture(assetName) ?: return false
return assetArch == systemArch
}
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/DeviceApp.kt
================================================
package zed.rainxch.core.domain.model
data class DeviceApp(
val packageName: String,
val appName: String,
val versionName: String?,
val versionCode: Long,
val signingFingerprint: String?,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/DiscoveryPlatform.kt
================================================
package zed.rainxch.core.domain.model
enum class DiscoveryPlatform {
All,
Android,
Macos,
Windows,
Linux,
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/DownloadProgress.kt
================================================
package zed.rainxch.core.domain.model
data class DownloadProgress(
val bytesDownloaded: Long,
val totalBytes: Long?,
val percent: Int?,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/ExportedApp.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class ExportedApp(
val packageName: String,
val repoOwner: String,
val repoName: String,
val repoUrl: String,
)
@Serializable
data class ExportedAppList(
val version: Int = 1,
val exportedAt: Long = 0L,
val apps: List = emptyList(),
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/FavoriteRepo.kt
================================================
package zed.rainxch.core.domain.model
data class FavoriteRepo(
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val isInstalled: Boolean = false,
val installedPackageName: String? = null,
val latestVersion: String?,
val latestReleaseUrl: String?,
val addedAt: Long,
val lastSyncedAt: Long,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/FontTheme.kt
================================================
package zed.rainxch.core.domain.model
enum class FontTheme(
val displayName: String,
) {
SYSTEM("System"),
CUSTOM("JetBrains Mono + Inter"),
;
companion object {
fun fromName(name: String?): FontTheme = entries.find { it.name == name } ?: CUSTOM
}
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubAsset.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class GithubAsset(
val id: Long,
val name: String,
val contentType: String,
val size: Long,
val downloadUrl: String,
val uploader: GithubUser,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubDeviceStart.kt
================================================
package zed.rainxch.core.domain.model
data class GithubDeviceStart(
val deviceCode: String,
val userCode: String,
val verificationUri: String,
val verificationUriComplete: String? = null,
val intervalSec: Int = 5,
val expiresInSec: Int,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubDeviceTokenError.kt
================================================
package zed.rainxch.core.domain.model
data class GithubDeviceTokenError(
val error: String,
val errorDescription: String? = null,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubDeviceTokenSuccess.kt
================================================
package zed.rainxch.core.domain.model
data class GithubDeviceTokenSuccess(
val accessToken: String,
val tokenType: String,
val expiresIn: Long? = null,
val scope: String? = null,
val refreshToken: String? = null,
val refreshTokenExpiresIn: Long? = null,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubRelease.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class GithubRelease(
val id: Long,
val tagName: String,
val name: String?,
val author: GithubUser,
val publishedAt: String,
val description: String?,
val assets: List,
val tarballUrl: String,
val zipballUrl: String,
val htmlUrl: String,
val isPrerelease: Boolean = false,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubRepoSummary.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class GithubRepoSummary(
val id: Long,
val name: String,
val fullName: String,
val owner: GithubUser,
val description: String?,
val defaultBranch: String,
val htmlUrl: String,
val stargazersCount: Int,
val forksCount: Int,
val language: String?,
val topics: List?,
val releasesUrl: String,
val updatedAt: String,
val isFork: Boolean = false,
val availablePlatforms: List = emptyList(),
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubUser.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class GithubUser(
val id: Long,
val login: String,
val avatarUrl: String,
val htmlUrl: String,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubUserProfile.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class GithubUserProfile(
val id: Long,
val login: String,
val name: String?,
val bio: String?,
val avatarUrl: String,
val htmlUrl: String,
val followers: Int,
val following: Int,
val publicRepos: Int,
val location: String?,
val company: String?,
val blog: String?,
val twitterUsername: String?,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/InstallSource.kt
================================================
package zed.rainxch.core.domain.model
enum class InstallSource {
THIS_APP,
OBTAINIUM,
APP_MANAGER,
MANUAL,
UNKNOWN,
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/InstalledApp.kt
================================================
package zed.rainxch.core.domain.model
data class InstalledApp(
val packageName: String,
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val installedVersion: String,
val installedAssetName: String?,
val installedAssetUrl: String?,
val latestVersion: String?,
val latestAssetName: String?,
val latestAssetUrl: String?,
val latestAssetSize: Long?,
val appName: String,
val installSource: InstallSource,
val installedAt: Long,
val lastCheckedAt: Long,
val lastUpdatedAt: Long,
val isUpdateAvailable: Boolean,
val signingFingerprint: String?,
val updateCheckEnabled: Boolean = true,
val releaseNotes: String? = "",
val systemArchitecture: String,
val fileExtension: String,
val isPendingInstall: Boolean = false,
val installedVersionName: String? = null,
val installedVersionCode: Long = 0L,
val latestVersionName: String? = null,
val latestVersionCode: Long? = null,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/InstallerType.kt
================================================
package zed.rainxch.core.domain.model
enum class InstallerType {
DEFAULT,
SHIZUKU;
companion object {
fun fromName(name: String?): InstallerType =
entries.find { it.name == name } ?: DEFAULT
}
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/PackageChangeType.kt
================================================
package zed.rainxch.core.domain.model
enum class PackageChangeType {
INSTALLED,
UNINSTALLED,
UPDATED,
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/PaginatedDiscoveryRepositories.kt
================================================
package zed.rainxch.core.domain.model
import kotlinx.serialization.Serializable
@Serializable
data class PaginatedDiscoveryRepositories(
val repos: List,
val hasMore: Boolean,
val nextPageIndex: Int,
val totalCount: Int? = null,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/Platform.kt
================================================
package zed.rainxch.core.domain.model
enum class Platform {
ANDROID,
WINDOWS,
MACOS,
LINUX,
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/ProxyConfig.kt
================================================
package zed.rainxch.core.domain.model
sealed class ProxyConfig {
data object None : ProxyConfig()
data object System : ProxyConfig()
data class Http(
val host: String,
val port: Int,
val username: String? = null,
val password: String? = null,
) : ProxyConfig()
data class Socks(
val host: String,
val port: Int,
val username: String? = null,
val password: String? = null,
) : ProxyConfig()
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/RateLimitException.kt
================================================
package zed.rainxch.core.domain.model
class RateLimitException(
val rateLimitInfo: RateLimitInfo,
) : Exception()
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/RateLimitInfo.kt
================================================
package zed.rainxch.core.domain.model
import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Instant
data class RateLimitInfo(
val limit: Int,
val remaining: Int,
val resetTimestamp: Long,
val resource: String = "core",
) {
val isExhausted: Boolean
get() = remaining == 0
fun timeUntilReset(): Duration {
val reset = Instant.fromEpochSeconds(resetTimestamp)
return (reset - Clock.System.now()).coerceAtLeast(Duration.ZERO)
}
fun isCurrentlyLimited(): Boolean = isExhausted && timeUntilReset() > Duration.ZERO
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/ShizukuAvailability.kt
================================================
package zed.rainxch.core.domain.model
enum class ShizukuAvailability {
UNAVAILABLE,
NOT_RUNNING,
PERMISSION_NEEDED,
READY
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/StarredRepository.kt
================================================
package zed.rainxch.core.domain.model
data class StarredRepository(
val repoId: Long,
val repoName: String,
val repoOwner: String,
val repoOwnerAvatarUrl: String,
val repoDescription: String?,
val primaryLanguage: String?,
val repoUrl: String,
val stargazersCount: Int,
val forksCount: Int,
val openIssuesCount: Int,
val isInstalled: Boolean = false,
val installedPackageName: String? = null,
val latestVersion: String?,
val latestReleaseUrl: String?,
val starredAt: Long?,
val addedAt: Long,
val lastSyncedAt: Long,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/SystemArchitecture.kt
================================================
package zed.rainxch.core.domain.model
enum class SystemArchitecture {
X86_64, // Intel/AMD 64-bit
AARCH64, // ARM 64-bit
X86, // Intel/AMD 32-bit
ARM, // ARM 32-bit
UNKNOWN,
;
companion object {
fun fromString(arch: String): SystemArchitecture {
val normalized = arch.lowercase().trim()
return when (normalized) {
in listOf("x86_64", "amd64", "x64") -> X86_64
in listOf("aarch64", "arm64", "arm64-v8a", "armv8", "armv8a", "armv8l") -> AARCH64
in listOf("x86", "i386", "i686") -> X86
in listOf("arm", "armv7l", "armv7", "armv7a", "armeabi", "armeabi-v7a") -> ARM
else -> UNKNOWN
}
}
}
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/SystemPackageInfo.kt
================================================
package zed.rainxch.core.domain.model
data class SystemPackageInfo(
val packageName: String,
val versionName: String,
val versionCode: Long,
val isInstalled: Boolean,
val signingFingerprint: String?,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/UpdateHistory.kt
================================================
package zed.rainxch.core.domain.model
data class UpdateHistory(
val id: Long = 0,
val packageName: String,
val appName: String,
val repoOwner: String,
val repoName: String,
val fromVersion: String,
val toVersion: String,
val updatedAt: Long,
val updateSource: InstallSource,
val success: Boolean = true,
val errorMessage: String? = null,
)
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/network/Downloader.kt
================================================
package zed.rainxch.core.domain.network
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.DownloadProgress
interface Downloader {
fun download(
url: String,
suggestedFileName: String? = null,
): Flow
suspend fun saveToFile(
url: String,
suggestedFileName: String? = null,
): String
suspend fun getDownloadedFilePath(fileName: String): String?
suspend fun cancelDownload(fileName: String): Boolean
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/AuthenticationState.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
interface AuthenticationState {
fun isUserLoggedIn(): Flow
suspend fun isCurrentlyUserLoggedIn(): Boolean
val sessionExpiredEvent: SharedFlow
suspend fun notifySessionExpired()
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/FavouritesRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.FavoriteRepo
interface FavouritesRepository {
fun getAllFavorites(): Flow>
fun isFavorite(repoId: Long): Flow
suspend fun isFavoriteSync(repoId: Long): Boolean
suspend fun toggleFavorite(repo: FavoriteRepo)
suspend fun updateFavoriteInstallStatus(
repoId: Long,
installed: Boolean,
packageName: String?,
)
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/InstalledAppsRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.InstalledApp
interface InstalledAppsRepository {
fun getAllInstalledApps(): Flow>
fun getAppsWithUpdates(): Flow>
fun getUpdateCount(): Flow
suspend fun getAppByPackage(packageName: String): InstalledApp?
suspend fun getAppByRepoId(repoId: Long): InstalledApp?
fun getAppByRepoIdAsFlow(repoId: Long): Flow
suspend fun isAppInstalled(repoId: Long): Boolean
suspend fun saveInstalledApp(app: InstalledApp)
suspend fun deleteInstalledApp(packageName: String)
suspend fun checkForUpdates(packageName: String): Boolean
suspend fun checkAllForUpdates()
suspend fun updateAppVersion(
packageName: String,
newTag: String,
newAssetName: String,
newAssetUrl: String,
newVersionName: String,
newVersionCode: Long,
signingFingerprint: String?,
)
suspend fun updateApp(app: InstalledApp)
suspend fun updatePendingStatus(
packageName: String,
isPending: Boolean,
)
suspend fun executeInTransaction(block: suspend () -> R): R
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/ProxyRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.ProxyConfig
interface ProxyRepository {
fun getProxyConfig(): Flow
suspend fun setProxyConfig(config: ProxyConfig)
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/RateLimitRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import zed.rainxch.core.domain.model.RateLimitInfo
interface RateLimitRepository {
val rateLimitState: StateFlow
val rateLimitExhaustedEvent: SharedFlow
fun updateRateLimit(rateLimitInfo: RateLimitInfo?)
fun getCurrentRateLimit(): RateLimitInfo?
fun isCurrentlyLimited(): Boolean
fun clear()
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/SeenReposRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
interface SeenReposRepository {
fun getAllSeenRepoIds(): Flow>
suspend fun markAsSeen(repoId: Long)
suspend fun clearAll()
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/StarredRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.StarredRepository
interface StarredRepository {
fun getAllStarred(): Flow>
suspend fun isStarred(repoId: Long): Boolean
suspend fun syncStarredRepos(forceRefresh: Boolean = false): Result
suspend fun getLastSyncTime(): Long?
suspend fun needsSync(): Boolean
}
================================================
FILE: core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/TweaksRepository.kt
================================================
package zed.rainxch.core.domain.repository
import kotlinx.coroutines.flow.Flow
import zed.rainxch.core.domain.model.AppTheme
import zed.rainxch.core.domain.model.FontTheme
import zed.rainxch.core.domain.model.InstallerType
interface TweaksRepository {
fun getThemeColor(): Flow
suspend fun setThemeColor(theme: AppTheme)
fun getIsDarkTheme(): Flow
suspend fun setDarkTheme(isDarkTheme: Boolean?)
fun getAmoledTheme(): Flow
suspend fun setAmoledTheme(enabled: Boolean)
fun getFontTheme(): Flow
suspend fun setFontTheme(fontTheme: FontTheme)
fun getAutoDetectClipboardLinks(): Flow
suspend fun setAutoDetectClipboardLinks(enabled: Boolean)
fun getInstallerType(): Flow
suspend fun setInstallerType(type: InstallerType)
fun getAutoUpdateEnabled(): Flow
suspend fun setAutoUpdateEnabled(enabled: Boolean)
fun getUpdateCheckInterval(): Flow
suspend fun setUpdateCheckInterval(hours: Long)
fun getIncludePreReleases(): Flow