Skip to content

Commit

Permalink
Copyright and general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
psuzn committed Apr 19, 2024
1 parent 70828b2 commit 4433b29
Show file tree
Hide file tree
Showing 53 changed files with 837 additions and 37 deletions.
6 changes: 3 additions & 3 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import io.gitlab.arturbosch.detekt.DetektPlugin
import org.jlleitschuh.gradle.ktlint.KtlintPlugin

/*
* Copyright 2024 Sujan Poudel
*
Expand All @@ -17,6 +14,9 @@ import org.jlleitschuh.gradle.ktlint.KtlintPlugin
* limitations under the License.
*/

import io.gitlab.arturbosch.detekt.DetektPlugin
import org.jlleitschuh.gradle.ktlint.KtlintPlugin

plugins {
`kotlin-dsl`
alias(libs.plugins.kotlin.jvm)
Expand Down
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

import io.gitlab.arturbosch.detekt.Detekt
import org.jlleitschuh.gradle.ktlint.tasks.KtLintCheckTask
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask
Expand Down
15 changes: 15 additions & 0 deletions context-provider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

plugins {
id("module")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.contextProvider

import android.app.Application
Expand Down
15 changes: 15 additions & 0 deletions multiplatform-paths/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

plugins {
id("packaging")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import kotlinx.io.files.Path
import me.sujanpoudel.utils.contextProvider.applicationContext
import me.sujanpoudel.utils.paths.utils.toPath

actual fun dataDirectory(appId: String) = applicationContext.applicationInfo.dataDir.toPath()
actual fun dataDirectory(appId: String): Path = applicationContext.applicationInfo.dataDir.toPath()

actual fun cacheDirectory(appId: String) = applicationContext.cacheDir.absolutePath.toPath()
actual fun cacheDirectory(appId: String): Path = applicationContext.cacheDir.absolutePath.toPath()
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import kotlinx.io.files.Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths.utils

import kotlinx.io.files.Path

inline fun String.toPath(): Path = Path(this)

operator fun Path.div(child: String) = Path(this, child)
operator fun Path.div(child: String): Path = Path(this, child)
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import kotlinx.io.files.Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import kotlinx.io.files.Path
import me.sujanpoudel.utils.paths.utils.div
import me.sujanpoudel.utils.paths.utils.toPath
import me.sujanpoudel.utils.platformIdentifier.Platform

fun desktopAppHomeDirectory(appId: String, os: Platform.OS, getEnv: (String) -> String) = when (os) {
fun desktopAppHomeDirectory(appId: String, os: Platform.OS, getEnv: (String) -> String): Path = when (os) {
is Platform.OS.MacOs -> getEnv("HOME").toPath() / "Library/Application Support" / appId
is Platform.OS.Windows -> getEnv("APPDATA").toPath() / appId
is Platform.OS.Linux -> getEnv("HOME").toPath() / ".local" / "share" / appId
else -> getEnv("HOME").toPath() / ".$appId"
}

fun desktopCacheDirectory(appId: String, os: Platform.OS, getEnv: (String) -> String) = when (os) {
fun desktopCacheDirectory(appId: String, os: Platform.OS, getEnv: (String) -> String): Path = when (os) {
is Platform.OS.MacOs -> getEnv("HOME").toPath() / "Library/Caches" / appId
is Platform.OS.Windows -> getEnv("APPDATA").toPath() / "Caches" / appId
is Platform.OS.Linux -> getEnv("HOME").toPath() / ".cache" / appId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import me.sujanpoudel.utils.platformIdentifier.hostOs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.paths

import kotlinx.io.files.Path
import me.sujanpoudel.utils.platformIdentifier.Platform
import me.sujanpoudel.utils.platformIdentifier.platform

private val platform = platform() as Platform.JS

actual fun dataDirectory(appId: String) = when (platform) {
actual fun dataDirectory(appId: String): Path = when (platform) {
is Platform.JS.Node -> desktopAppHomeDirectory(
appId = appId,
os = platform.os,
Expand All @@ -15,7 +32,7 @@ actual fun dataDirectory(appId: String) = when (platform) {
else -> error("Non node environment")
}

actual fun cacheDirectory(appId: String) = when (platform) {
actual fun cacheDirectory(appId: String): Path = when (platform) {
is Platform.JS.Node -> desktopCacheDirectory(
appId = appId,
os = platform.os,
Expand Down
15 changes: 15 additions & 0 deletions platform-identifier/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

plugins {
id("packaging")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.platformIdentifier

import android.content.pm.PackageManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.platformIdentifier

import kotlinx.cinterop.ByteVar
Expand All @@ -8,8 +24,8 @@ import kotlinx.cinterop.toKString
import platform.posix.__system_property_get
import kotlin.experimental.ExperimentalNativeApi

const val SYSTEM_PROP_BUILD_VERSION = "ro.build.version.sdk"
const val SYSTEM_PROP_OS_VERSION = "ro.build.version.release"
private const val SYSTEM_PROP_BUILD_VERSION: String = "ro.build.version.sdk"
private const val SYSTEM_PROP_OS_VERSION: String = "ro.build.version.release"

@OptIn(ExperimentalNativeApi::class)
actual fun platform(): Platform {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.platformIdentifier

import kotlin.test.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Sujan Poudel
*
* 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.
*/

package me.sujanpoudel.utils.platformIdentifier

import android.content.Context
Expand Down
Loading

0 comments on commit 4433b29

Please sign in to comment.