Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use NSApplicationSupportDirectory for all darwin platforms #34

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Platform-specific application home and cache directories for KMP.
| Platform | Cache Directory | Data Directory |
|-----------------------|--------------------------------------------|--------------------------------------------|
| Android | `context.cacheDir` | `ApplicationInfo.dataDir` |
| IOS/IpadOs/WatchOs | `NSCachesDirectory` | `NSHomeDirectory` |
| IOS/IpadOs/WatchOs | `NSCachesDirectory` | `NSApplicationSupportDirectory` |
| Mac (native/jvm/node) | `~/Library/Caches/<app-id>` | `~/Library/Application Support/<app-id>` |
| Windows (jvm/node) | `C:\Users\<user>\AppData/Caches/<app-id>` | `C:\Users\<user>\AppData/<app-id>>` |
| Linux (jvm/node) | `~/.cache/<app-id>` | `~/local/share/<app-id>` |
Expand Down Expand Up @@ -58,7 +58,7 @@ val packageName = "example.com.app"
val dataDirectory = appDataDirectory(packageName)
```

This will return `ApplicationInfo.dataDir` on android, `NSHomeDirectory` on IOS and equivalent platform specific data
This will return `ApplicationInfo.dataDir` on android, `NSApplicationSupportDirectory` on IOS and equivalent platform specific data
directory on other platforms.

#### App cache directory
Expand Down
2 changes: 1 addition & 1 deletion multiplatform-paths/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mavenPublishing {
pom {
name.set("Multiplatform Paths")
description.set(
"Get platform specific app data and cache directory(equivalent to ApplicationInfo.dataDir or NSHomeDirectory) in Kotlin Multiplatform application",
"Get platform specific app data and cache directory(equivalent to ApplicationInfo.dataDir or NSApplicationSupportDirectory) in Kotlin Multiplatform application",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ import me.sujanpoudel.utils.platformIdentifier.Platform
import me.sujanpoudel.utils.platformIdentifier.platform
import platform.Foundation.NSApplicationSupportDirectory
import platform.Foundation.NSCachesDirectory
import platform.Foundation.NSHomeDirectory
import platform.Foundation.NSSearchPathForDirectoriesInDomains
import platform.Foundation.NSUserDomainMask

actual fun dataDirectory(appId: String): Path = if (platform() is Platform.OS.MacOs) {
actual fun dataDirectory(appId: String): Path =
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true)
.firstOrNull()?.toString()?.toPath()
?.let { it / appId } ?: error("Unable to get 'NSApplicationSupportDirectory'")
} else {
NSHomeDirectory().toPath()
}

actual fun cacheDirectory(appId: String): Path {
val cachesDirectory = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true)
Expand Down