-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: use platform-specific default directories for downloads and database #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,7 +229,8 @@ private fun runServer(args: Array<String>) { | |
| var port = 8642 | ||
| var token: String? = null | ||
| var corsOrigins: List<String> = emptyList() | ||
| var downloadDir = "downloads" | ||
| var downloadDir = System.getProperty("user.home") + | ||
| File.separator + "Downloads" | ||
| var speedLimit = SpeedLimit.Unlimited | ||
|
|
||
| var i = 0 | ||
|
|
@@ -307,10 +308,13 @@ private fun runServer(args: Array<String>) { | |
|
|
||
| File(downloadDir).mkdirs() | ||
|
|
||
| val dbPath = File(downloadDir, "kdown.db").absolutePath | ||
| val dbPath = defaultDbPath() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Switching the server DB location to Useful? React with 👍 / 👎. |
||
| val driver = DriverFactory(dbPath).createDriver() | ||
| val taskStore = SqliteTaskStore(driver) | ||
| val config = DownloadConfig(speedLimit = speedLimit) | ||
| val config = DownloadConfig( | ||
| defaultDirectory = downloadDir, | ||
| speedLimit = speedLimit, | ||
| ) | ||
|
|
||
| val kdown = KDown( | ||
| httpEngine = KtorHttpEngine(), | ||
|
|
@@ -529,7 +533,7 @@ private fun printServerUsage() { | |
| println(" --cors <origins> CORS allowed origins,") | ||
| println(" comma-separated (optional)") | ||
| println(" --dir <path> Download directory") | ||
| println(" (default: ./downloads)") | ||
| println(" (default: ~/Downloads)") | ||
| println(" --speed-limit <value> Global speed limit") | ||
| println(" (e.g., 10m, 500k)") | ||
| println(" --help, -h Show this help message") | ||
|
|
@@ -541,6 +545,29 @@ private fun printServerUsage() { | |
| println(" kdown-cli server --speed-limit 10m") | ||
| } | ||
|
|
||
| private fun defaultDbPath(): String { | ||
| val os = System.getProperty("os.name", "").lowercase() | ||
| val home = System.getProperty("user.home") | ||
| val configDir = when { | ||
| os.contains("mac") -> | ||
| "$home${File.separator}Library${File.separator}" + | ||
| "Application Support${File.separator}kdown" | ||
| os.contains("win") -> { | ||
| val appData = System.getenv("APPDATA") | ||
| ?: "$home${File.separator}AppData${File.separator}Roaming" | ||
| "$appData${File.separator}kdown" | ||
| } | ||
| else -> { | ||
| val xdg = System.getenv("XDG_CONFIG_HOME") | ||
| ?: "$home${File.separator}.config" | ||
| "$xdg${File.separator}kdown" | ||
| } | ||
| } | ||
| val dir = File(configDir) | ||
| dir.mkdirs() | ||
| return File(dir, "kdown.db").absolutePath | ||
| } | ||
|
|
||
| private fun parsePriority(value: String): DownloadPriority? { | ||
| return when (value.trim().lowercase()) { | ||
| "low" -> DownloadPriority.LOW | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ package com.linroid.kdown.sqlite | |
| import app.cash.sqldelight.db.SqlDriver | ||
| import app.cash.sqldelight.driver.native.NativeSqliteDriver | ||
|
|
||
| actual class DriverFactory { | ||
| actual class DriverFactory(private val dbPath: String) { | ||
| actual fun createDriver(): SqlDriver { | ||
| return NativeSqliteDriver(KDownDatabase.Schema, "kdown.db") | ||
| return NativeSqliteDriver(KDownDatabase.Schema, dbPath) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude finished @linroid's task in 2m 27s —— View job Fixing iOS NativeSqliteDriver crashIssue: Root Cause: The iOS app was passing Solution: 1. Updated actual class DriverFactory(private val dbPath: String) {
actual fun createDriver(): SqlDriver {
// NativeSqliteDriver only accepts a database name (filename without path separators)
// The database will be created in the application's default database directory.
// We extract just the filename from the provided path.
val fileName = dbPath.substringAfterLast('/')
return NativeSqliteDriver(KDownDatabase.Schema, fileName)
}
}2. Updated fun MainViewController() = ComposeUIViewController {
val backendManager = remember {
// NativeSqliteDriver only accepts a filename, not a full path.
// The database will be stored in the application's default database directory.
val taskStore = createSqliteTaskStore(DriverFactory("kdown.db"))
// ... rest of the code
}
}Removed the Todo List:
Note: I need your approval to commit these changes. The commit is staged and ready. Once you approve the
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @claude Use the dbName as the DriverFactory constructor parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude finished @linroid's task in 6m 14s —— View job Refactoring iOS DriverFactory to use
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the default directory to
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)routes writes to shared external storage, but this app only declaresINTERNETinapp/android/src/main/AndroidManifest.xmland writes files viaRandomAccessFile. On modern Android (targetSdk 36), direct writes to/storage/emulated/0/Downloadare blocked for normal apps, so downloads started with the default settings can fail with permission/disk errors.Useful? React with 👍 / 👎.