|
| 1 | +/* |
| 2 | + * Copyright 2024 Sujan Poudel |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package me.sujanpoudel.utils.paths |
| 18 | + |
| 19 | +import kotlinx.io.files.Path |
| 20 | +import me.sujanpoudel.utils.paths.utils.div |
| 21 | +import me.sujanpoudel.utils.paths.utils.toPath |
| 22 | +import me.sujanpoudel.utils.platformIdentifier.Platform |
| 23 | +import me.sujanpoudel.utils.platformIdentifier.platform |
| 24 | + |
| 25 | +class NodeDirectoriesTest : DirectoriesTest() { |
| 26 | + private fun getEnv(key: String) = eval("""process.env["$key"]""") as String |
| 27 | + |
| 28 | + override fun exceptedCacheDir(appId: String): Path { |
| 29 | + val platform = platform() as? Platform.JS.Node ?: error("not supported") |
| 30 | + |
| 31 | + return when (platform.os) { |
| 32 | + is Platform.OS.Linux -> getEnv("HOME").toPath() / ".cache" / appId |
| 33 | + is Platform.OS.MacOs -> getEnv("HOME").toPath() / "Library/Caches" / appId |
| 34 | + is Platform.OS.Windows -> getEnv("APPDATA").toPath() / "Caches" / appId |
| 35 | + |
| 36 | + else -> error("not supported") |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + override fun exceptedDataDir(appId: String): Path { |
| 41 | + val platform = platform() as? Platform.JS.Node ?: error("not supported") |
| 42 | + |
| 43 | + return when (platform.os) { |
| 44 | + is Platform.OS.Linux -> getEnv("HOME").toPath() / ".local/share" / appId |
| 45 | + is Platform.OS.MacOs -> getEnv("HOME").toPath() / "Library/Application Support" / appId |
| 46 | + is Platform.OS.Windows -> getEnv("APPDATA").toPath() / appId |
| 47 | + else -> error("not supported") |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments