diff --git a/detekt.yml b/detekt.yml index 095bbaa..bc8e30a 100644 --- a/detekt.yml +++ b/detekt.yml @@ -143,20 +143,20 @@ complexity: active: true excludes: [ - "**/test/**", + "**/test/**", "**/androidTest/**", - "**/commonTest/**", - "**/jvmTest/**", - "**/jsTest/**", - "**/iosTest/**", + "**/commonTest/**", + "**/jvmTest/**", + "**/jsTest/**", + "**/iosTest/**", ] thresholdInFiles: 11 thresholdInClasses: 11 thresholdInInterfaces: 11 thresholdInObjects: 11 thresholdInEnums: 11 - ignoreDeprecated: false - ignorePrivate: false + ignoreDeprecated: true + ignorePrivate: true ignoreOverridden: false coroutines: diff --git a/src/main/kotlin/app/Main.kt b/src/main/kotlin/app/Main.kt index e63950f..6ce6dc6 100644 --- a/src/main/kotlin/app/Main.kt +++ b/src/main/kotlin/app/Main.kt @@ -3,5 +3,8 @@ package app import androidx.compose.ui.window.application fun main() = application(false) { + val environment = System.getenv("SKIKO_RENDER_API") + val property = System.getProperty("skiko.renderApi") + println("env: $environment render: $property") appWindow() } diff --git a/src/main/kotlin/storage/Db.kt b/src/main/kotlin/storage/Db.kt index 6d6858d..65a439d 100644 --- a/src/main/kotlin/storage/Db.kt +++ b/src/main/kotlin/storage/Db.kt @@ -6,13 +6,21 @@ import org.mapdb.DBMaker import org.mapdb.HTreeMap import org.mapdb.Serializer import storage.serializer.ObjectSerializer +import java.io.File object Db { private const val PREFIX = "Session-" - private val db by lazy { - DBMaker.fileDB("sessions.db").fileMmapEnableIfSupported().checksumHeaderBypass().make() + private val diskDb by lazy { + val homeDir = System.getProperty("user.home") + val slash = File.pathSeparator + val dbName = "sessions.db" + val dbFile = File("$homeDir${slash}logvue${slash}$dbName") + if (!(dbFile.canRead() && dbFile.canWrite())) { + throw SecurityException("Can not read at path ${dbFile.canonicalPath}") + } + DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() } private var session: HTreeMap? = null @@ -20,11 +28,11 @@ object Db { private val LOCK = Any() val configs by lazy { - db.hashMap("configs", Serializer.STRING, Serializer.STRING).createOrOpen() + diskDb.hashMap("configs", Serializer.STRING, Serializer.STRING).createOrOpen() } private val sessionInfoMap by lazy { - db.hashMap("sessionInfo", Serializer.STRING, ObjectSerializer()).createOrOpen() + diskDb.hashMap("sessionInfo", Serializer.STRING, ObjectSerializer()).createOrOpen() } init { @@ -37,14 +45,14 @@ object Db { return sessionInfoMap[sessionId] } - fun getAllSessions() = db.getAllNames().filter { it.startsWith(PREFIX) }.sortedBy { getSessionNumber(it) } + fun getAllSessions() = diskDb.getAllNames().filter { it.startsWith(PREFIX) }.sortedBy { getSessionNumber(it) } - fun getLastSessionNumber(): Int { + private fun getLastSessionNumber(): Int { val lastSessionId = getAllSessions().lastOrNull() ?: sessionIdFromNumber(0) return getSessionNumber(lastSessionId) } - fun getPreviousSessionNumber(): Int { + private fun getPreviousSessionNumber(): Int { val lastDbSessionId = configs["lastSessionId"] val lastSessionId = if (lastDbSessionId.isNullOrBlank() || !lastDbSessionId.startsWith(PREFIX)) { getAllSessions().lastOrNull() ?: sessionIdFromNumber(0) @@ -54,11 +62,11 @@ object Db { return getSessionNumber(lastSessionId) } - fun getSessionNumber(sessionId: String) = sessionId.split("-").lastOrNull()?.toIntOrNull() ?: 0 + private fun getSessionNumber(sessionId: String) = sessionId.split("-").lastOrNull()?.toIntOrNull() ?: 0 - fun areNoSessionsCreated() = getAllSessions().isEmpty() + private fun areNoSessionsCreated() = getAllSessions().isEmpty() - fun isThisTheOnlySession(sessionId: String): Boolean { + private fun isThisTheOnlySession(sessionId: String): Boolean { val sessions = getAllSessions() if (sessions.size != 1) return false return sessions.first() == sessionId @@ -78,12 +86,12 @@ object Db { } else if (sessionId == sessionId()) { changeSession(null) } - val oldSession = db.hashMap(sessionId, Serializer.STRING, ObjectSerializer()) + val oldSession = diskDb.hashMap(sessionId, Serializer.STRING, ObjectSerializer()) .open() oldSession.clear() sessionInfoMap.remove(sessionId) val recIds = arrayListOf() - db.nameCatalogParamsFor(sessionId).forEach { (t, u) -> + diskDb.nameCatalogParamsFor(sessionId).forEach { (t, u) -> if (t.endsWith("rootRecids")) { u.split(",").forEach { value -> val recId = value.trim().toLongOrNull() @@ -93,15 +101,15 @@ object Db { } } recIds.forEach { - db.getStore().delete(it, Serializer.STRING) + diskDb.getStore().delete(it, Serializer.STRING) } - val newCatalog = db.nameCatalogLoad() + val newCatalog = diskDb.nameCatalogLoad() val keys = newCatalog.keys.filter { it.startsWith(sessionId) } keys.forEach { newCatalog.remove(it) } - db.nameCatalogSave(newCatalog) - db.commit() + diskDb.nameCatalogSave(newCatalog) + diskDb.commit() } fun changeSession(sessionId: String?) { @@ -123,7 +131,7 @@ object Db { } if (sessionNumber < 1) throw Exception("Session number must be greater than 1") val sessionId = sessionIdFromNumber(sessionNumber) - val session = db + val session = diskDb .hashMap(sessionId, Serializer.STRING, ObjectSerializer()) .createOrOpen() this.sessionId = sessionId @@ -143,6 +151,6 @@ object Db { } fun close() { - db.close() + diskDb.close() } } diff --git a/src/main/kotlin/utils/Helpers.kt b/src/main/kotlin/utils/Helpers.kt index 0bae37f..3823ab7 100644 --- a/src/main/kotlin/utils/Helpers.kt +++ b/src/main/kotlin/utils/Helpers.kt @@ -276,16 +276,10 @@ object Helpers { return takeValue } - fun isWindows(): Boolean { - val os = System.getProperty("os.name").lowercase(Locale.getDefault()) - // windows - return os.indexOf("win") >= 0 - } - fun openFileExplorer(path: Path) { try { val pathString = path.absolutePathString() - val command = if (isWindows()) { + val command = if (SystemTools.getOS() == OsWindows) { "Explorer.exe $pathString" } else { "open $pathString" diff --git a/src/main/kotlin/utils/Renderer.kt b/src/main/kotlin/utils/Renderer.kt new file mode 100644 index 0000000..db36c7f --- /dev/null +++ b/src/main/kotlin/utils/Renderer.kt @@ -0,0 +1,48 @@ +package utils + +import org.jetbrains.skiko.GraphicsApi +import org.jetbrains.skiko.OS +import org.jetbrains.skiko.hostOs + +object Renderer { + +// private const val RENDER_API_KEY = "skiko.renderApi" + +// fun setRender() { +// when(SystemTools.getOS()) { +// OsWindows, OsLinux -> { +// System.setProperty(RENDER_API_KEY, "OPENGL") +// } +// OsMac -> { +// +// } +// } +// } + + internal fun parseRenderApi(text: String?): GraphicsApi { + return when (text) { + "SOFTWARE_COMPAT" -> GraphicsApi.SOFTWARE_COMPAT + "SOFTWARE_FAST", "DIRECT_SOFTWARE", "SOFTWARE" -> GraphicsApi.SOFTWARE_FAST + "OPENGL" -> GraphicsApi.OPENGL + "DIRECT3D" -> { + if (hostOs == OS.Windows) GraphicsApi.DIRECT3D + else throw UnsupportedOperationException("$hostOs does not support DirectX rendering API.") + } + "METAL" -> { + if (hostOs == OS.MacOS) GraphicsApi.METAL + else throw UnsupportedOperationException("$hostOs does not support Metal rendering API.") + } + else -> bestRenderApiForCurrentOS() + } + } + + private fun bestRenderApiForCurrentOS(): GraphicsApi { + return when (hostOs) { + OS.MacOS -> GraphicsApi.METAL + OS.Linux -> GraphicsApi.OPENGL + OS.Windows -> GraphicsApi.DIRECT3D + OS.JS, OS.Ios -> TODO("commonize me") + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/utils/SystemTools.kt b/src/main/kotlin/utils/SystemTools.kt new file mode 100644 index 0000000..2d5ebcc --- /dev/null +++ b/src/main/kotlin/utils/SystemTools.kt @@ -0,0 +1,22 @@ +package utils + +import java.util.* + +object SystemTools { + + fun getOS(): OS { + val os = System.getProperty("os.name").lowercase(Locale.getDefault()) + return when { + os.contains("window") -> OsWindows + os.contains("nix") || os.contains("nux") || os.contains("aix") -> OsLinux + os.contains("os x") || os.contains("mac") -> OsMac + else -> throw UnsupportedOperationException("Operating system $os is not supported") + } + } + +} + +sealed interface OS +object OsWindows : OS +object OsLinux : OS +object OsMac : OS \ No newline at end of file