From 904b35f99fb05f6ad759da4e469e6829010f7968 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Tue, 11 Jan 2022 22:48:43 +0530 Subject: [PATCH 01/10] Db location to system home --- detekt.yml | 14 ++++---- src/main/kotlin/app/Main.kt | 3 ++ src/main/kotlin/storage/Db.kt | 44 ++++++++++++++----------- src/main/kotlin/utils/Helpers.kt | 8 +---- src/main/kotlin/utils/Renderer.kt | 48 ++++++++++++++++++++++++++++ src/main/kotlin/utils/SystemTools.kt | 22 +++++++++++++ 6 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 src/main/kotlin/utils/Renderer.kt create mode 100644 src/main/kotlin/utils/SystemTools.kt 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 From d4d1a3d7093673769f24a3391b248bb90da1881c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 11 Jan 2022 17:19:09 +0000 Subject: [PATCH 02/10] Restyled by prettier-yaml --- detekt.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/detekt.yml b/detekt.yml index bc8e30a..086f894 100644 --- a/detekt.yml +++ b/detekt.yml @@ -143,12 +143,12 @@ complexity: active: true excludes: [ - "**/test/**", + "**/test/**", "**/androidTest/**", - "**/commonTest/**", - "**/jvmTest/**", - "**/jsTest/**", - "**/iosTest/**", + "**/commonTest/**", + "**/jvmTest/**", + "**/jsTest/**", + "**/iosTest/**", ] thresholdInFiles: 11 thresholdInClasses: 11 From 56115b21dfd749ef605c0f42fde9ccca2da4b0ff Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 11 Jan 2022 17:19:10 +0000 Subject: [PATCH 03/10] Restyled by whitespace --- src/main/kotlin/utils/Renderer.kt | 2 +- src/main/kotlin/utils/SystemTools.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/utils/Renderer.kt b/src/main/kotlin/utils/Renderer.kt index db36c7f..ced6e42 100644 --- a/src/main/kotlin/utils/Renderer.kt +++ b/src/main/kotlin/utils/Renderer.kt @@ -45,4 +45,4 @@ object Renderer { } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/utils/SystemTools.kt b/src/main/kotlin/utils/SystemTools.kt index 2d5ebcc..8189001 100644 --- a/src/main/kotlin/utils/SystemTools.kt +++ b/src/main/kotlin/utils/SystemTools.kt @@ -19,4 +19,4 @@ object SystemTools { sealed interface OS object OsWindows : OS object OsLinux : OS -object OsMac : OS \ No newline at end of file +object OsMac : OS From aed32375dd0a8fb33c5d0226d0d037b43940c1ba Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Tue, 11 Jan 2022 22:51:51 +0530 Subject: [PATCH 04/10] build action fix --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cec573a..53f8cd9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,9 +13,9 @@ on: - 'docs/**' - '.github/config/labels.yml' - pull_request: - branches: - - main + pull_request: + branches: + - main workflow_dispatch: repository_dispatch: From 6109d731907732ba1baa23448fcccbf13ad783b9 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Tue, 11 Jan 2022 23:18:11 +0530 Subject: [PATCH 05/10] build action fix --- src/main/kotlin/storage/Db.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/storage/Db.kt b/src/main/kotlin/storage/Db.kt index 65a439d..c2d6eb4 100644 --- a/src/main/kotlin/storage/Db.kt +++ b/src/main/kotlin/storage/Db.kt @@ -14,7 +14,7 @@ object Db { private val diskDb by lazy { val homeDir = System.getProperty("user.home") - val slash = File.pathSeparator + val slash = File.separator val dbName = "sessions.db" val dbFile = File("$homeDir${slash}logvue${slash}$dbName") if (!(dbFile.canRead() && dbFile.canWrite())) { From 6a1fe3149e86b71f4aadddd2dcbdd7e9d2dce891 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Tue, 11 Jan 2022 23:29:14 +0530 Subject: [PATCH 06/10] Commented db file read/write checks --- src/main/kotlin/storage/Db.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/storage/Db.kt b/src/main/kotlin/storage/Db.kt index c2d6eb4..2cdd324 100644 --- a/src/main/kotlin/storage/Db.kt +++ b/src/main/kotlin/storage/Db.kt @@ -17,9 +17,9 @@ object Db { val slash = File.separator 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}") - } +// if (!(dbFile.canRead() && dbFile.canWrite())) { +// throw SecurityException("Can not read at path ${dbFile.canonicalPath}") +// } // TODO: try to move to inMemory db if this fails and show an error DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() } From d6085157874767c0a75a781e5d1e08fa90093322 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Wed, 12 Jan 2022 01:34:02 +0530 Subject: [PATCH 07/10] Using lib appdirs for data path --- build.gradle.kts | 2 ++ src/main/kotlin/app/MainWindow.kt | 3 +-- src/main/kotlin/storage/Db.kt | 9 +------- src/main/kotlin/storage/StorageHelper.kt | 29 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/storage/StorageHelper.kt diff --git a/build.gradle.kts b/build.gradle.kts index 2b11bcb..83c16f7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,6 +39,8 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10") implementation("io.sentry:sentry-log4j2:5.5.2") + // https://mvnrepository.com/artifact/net.harawata/appdirs + implementation("net.harawata:appdirs:1.2.1") r8("com.android.tools:r8:3.0.73") } diff --git a/src/main/kotlin/app/MainWindow.kt b/src/main/kotlin/app/MainWindow.kt index 28749ab..80cce72 100644 --- a/src/main/kotlin/app/MainWindow.kt +++ b/src/main/kotlin/app/MainWindow.kt @@ -11,7 +11,6 @@ import inputs.adb.ddmlib.AdbHelper import storage.Db import ui.CustomTheme import utils.AppLog -import utils.CustomExceptionHandler import utils.SentryHelper import java.awt.Desktop @@ -28,7 +27,7 @@ fun ApplicationScope.appWindow() { closeApp("User Close") exitApplication() } - Thread.setDefaultUncaughtExceptionHandler(CustomExceptionHandler()) +// Thread.setDefaultUncaughtExceptionHandler(CustomExceptionHandler()) SentryHelper.init() val windowState = rememberWindowState(WindowPlacement.Floating, size = DpSize(1440.dp, 1024.dp)) Window(onCloseRequest = onCloseRequest, title = CustomTheme.strings.appName, state = windowState) { diff --git a/src/main/kotlin/storage/Db.kt b/src/main/kotlin/storage/Db.kt index 2cdd324..8de4bae 100644 --- a/src/main/kotlin/storage/Db.kt +++ b/src/main/kotlin/storage/Db.kt @@ -6,20 +6,13 @@ 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 diskDb by lazy { - val homeDir = System.getProperty("user.home") - val slash = File.separator - 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}") -// } // TODO: try to move to inMemory db if this fails and show an error + val dbFile = StorageHelper.getDbFile() DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() } diff --git a/src/main/kotlin/storage/StorageHelper.kt b/src/main/kotlin/storage/StorageHelper.kt new file mode 100644 index 0000000..0797120 --- /dev/null +++ b/src/main/kotlin/storage/StorageHelper.kt @@ -0,0 +1,29 @@ +package storage + +import com.voxfinite.logvue.APP_NAME +import net.harawata.appdirs.AppDirsFactory +import java.io.File +import java.io.IOException + +object StorageHelper { + + @Throws(IOException::class) + fun getDbFile(): File { + val appDirs = AppDirsFactory.getInstance() + val dataDir = appDirs.getUserDataDir(APP_NAME, null, APP_NAME) + val dbName = "sessions.db" + val dbFile = File(dataDir, dbName) + if (!dbFile.exists()) { + dbFile.createNewFile() + } + if (!checkFileValid(dbFile)) { + throw IOException("Cannot create database file at path ${dbFile.canonicalPath}") + } + return dbFile + } + + fun checkFileValid(file: File): Boolean { + return ((file.canRead() && file.canWrite())) + } + +} \ No newline at end of file From 7b8bb183e80c9e6bacaa49f4d548ebdd8c49e7f5 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Wed, 12 Jan 2022 12:04:41 +0530 Subject: [PATCH 08/10] folder permission fix --- src/main/kotlin/app/MainWindow.kt | 3 +- src/main/kotlin/storage/Db.kt | 4 +- src/main/kotlin/storage/StorageHelper.kt | 52 ++++++++++++++----- .../kotlin/utils/CustomExceptionHandler.kt | 1 + src/main/kotlin/utils/DbCreationException.kt | 8 +++ 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/utils/DbCreationException.kt diff --git a/src/main/kotlin/app/MainWindow.kt b/src/main/kotlin/app/MainWindow.kt index 80cce72..28749ab 100644 --- a/src/main/kotlin/app/MainWindow.kt +++ b/src/main/kotlin/app/MainWindow.kt @@ -11,6 +11,7 @@ import inputs.adb.ddmlib.AdbHelper import storage.Db import ui.CustomTheme import utils.AppLog +import utils.CustomExceptionHandler import utils.SentryHelper import java.awt.Desktop @@ -27,7 +28,7 @@ fun ApplicationScope.appWindow() { closeApp("User Close") exitApplication() } -// Thread.setDefaultUncaughtExceptionHandler(CustomExceptionHandler()) + Thread.setDefaultUncaughtExceptionHandler(CustomExceptionHandler()) SentryHelper.init() val windowState = rememberWindowState(WindowPlacement.Floating, size = DpSize(1440.dp, 1024.dp)) Window(onCloseRequest = onCloseRequest, title = CustomTheme.strings.appName, state = windowState) { diff --git a/src/main/kotlin/storage/Db.kt b/src/main/kotlin/storage/Db.kt index 8de4bae..00f6fcf 100644 --- a/src/main/kotlin/storage/Db.kt +++ b/src/main/kotlin/storage/Db.kt @@ -2,7 +2,6 @@ package storage import models.LogItem import models.SessionInfo -import org.mapdb.DBMaker import org.mapdb.HTreeMap import org.mapdb.Serializer import storage.serializer.ObjectSerializer @@ -12,8 +11,7 @@ object Db { private const val PREFIX = "Session-" private val diskDb by lazy { - val dbFile = StorageHelper.getDbFile() - DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() + StorageHelper.createDiskDb() } private var session: HTreeMap? = null diff --git a/src/main/kotlin/storage/StorageHelper.kt b/src/main/kotlin/storage/StorageHelper.kt index 0797120..f120561 100644 --- a/src/main/kotlin/storage/StorageHelper.kt +++ b/src/main/kotlin/storage/StorageHelper.kt @@ -2,28 +2,54 @@ package storage import com.voxfinite.logvue.APP_NAME import net.harawata.appdirs.AppDirsFactory +import org.mapdb.DB +import org.mapdb.DBException +import org.mapdb.DBMaker +import utils.DbCreationException +import utils.reportException import java.io.File import java.io.IOException +import java.nio.file.Files +import java.nio.file.attribute.PosixFilePermissions object StorageHelper { + internal fun createDiskDb(): DB { + val dbFile = getDbFile() + return try { + DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() + } catch (e: DBException.VolumeIOError) { + DbCreationException("Mmap enabled db could not be created", e).reportException() + try { + DBMaker.fileDB(dbFile).fileChannelEnable().checksumHeaderBypass().make() + } catch (ee: DBException.VolumeIOError) { + DbCreationException("file channel enabled db could not be created", ee).reportException() + DBMaker.fileDB(dbFile).checksumHeaderBypass().make() + } + } + } + @Throws(IOException::class) - fun getDbFile(): File { + private fun getDbFile(): File { val appDirs = AppDirsFactory.getInstance() val dataDir = appDirs.getUserDataDir(APP_NAME, null, APP_NAME) - val dbName = "sessions.db" - val dbFile = File(dataDir, dbName) - if (!dbFile.exists()) { - dbFile.createNewFile() + val folder = File(dataDir) + if (!folder.exists() || !folder.isDirectory) { + if (folder.exists()) { + folder.delete() + } + try { + Files.createDirectory( + folder.toPath(), PosixFilePermissions.asFileAttribute( + PosixFilePermissions.fromString("rwxr-x---") + ) + ) + } catch (e: IOException) { + throw IOException("Cannot create app folder at path ${folder.canonicalPath}", e) + } } - if (!checkFileValid(dbFile)) { - throw IOException("Cannot create database file at path ${dbFile.canonicalPath}") - } - return dbFile - } - - fun checkFileValid(file: File): Boolean { - return ((file.canRead() && file.canWrite())) + val dbName = "sessions.db" + return File(dataDir, dbName) } } \ No newline at end of file diff --git a/src/main/kotlin/utils/CustomExceptionHandler.kt b/src/main/kotlin/utils/CustomExceptionHandler.kt index 998b3b3..434200c 100644 --- a/src/main/kotlin/utils/CustomExceptionHandler.kt +++ b/src/main/kotlin/utils/CustomExceptionHandler.kt @@ -5,6 +5,7 @@ class CustomExceptionHandler : Thread.UncaughtExceptionHandler { override fun uncaughtException(t: Thread?, e: Throwable?) { e?.printStackTrace() setCrashed() + throw e ?: Exception("Unknown exception") } companion object { diff --git a/src/main/kotlin/utils/DbCreationException.kt b/src/main/kotlin/utils/DbCreationException.kt new file mode 100644 index 0000000..8007da9 --- /dev/null +++ b/src/main/kotlin/utils/DbCreationException.kt @@ -0,0 +1,8 @@ +package utils + +class DbCreationException : Exception { + constructor() : super() + constructor(message: String) : super(message) + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(cause: Throwable) : super(cause) +} From 8ea02ebbf84bb1448a0312b502c2c700d7753044 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Wed, 12 Jan 2022 12:20:00 +0530 Subject: [PATCH 09/10] folder permission fix - windows --- src/main/kotlin/storage/StorageHelper.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/storage/StorageHelper.kt b/src/main/kotlin/storage/StorageHelper.kt index f120561..50121fb 100644 --- a/src/main/kotlin/storage/StorageHelper.kt +++ b/src/main/kotlin/storage/StorageHelper.kt @@ -9,9 +9,11 @@ import utils.DbCreationException import utils.reportException import java.io.File import java.io.IOException +import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.attribute.PosixFilePermissions + object StorageHelper { internal fun createDiskDb(): DB { @@ -39,11 +41,15 @@ object StorageHelper { folder.delete() } try { - Files.createDirectory( - folder.toPath(), PosixFilePermissions.asFileAttribute( + val isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix") + if (isPosix) { + val posixAttribute = PosixFilePermissions.asFileAttribute( PosixFilePermissions.fromString("rwxr-x---") ) - ) + Files.createDirectory(folder.toPath(), posixAttribute) + } else { + Files.createDirectory(folder.toPath()) + } } catch (e: IOException) { throw IOException("Cannot create app folder at path ${folder.canonicalPath}", e) } From cc2f599ca2445d2f895f7fb1eefb15c7a527fc96 Mon Sep 17 00:00:00 2001 From: "aman.kapoor" Date: Wed, 12 Jan 2022 14:56:17 +0530 Subject: [PATCH 10/10] Fix: create directories on Windows --- src/main/kotlin/app/MainWindow.kt | 4 +--- src/main/kotlin/inputs/adb/ddmlib/AdbHelper.kt | 12 +++++++----- src/main/kotlin/storage/StorageHelper.kt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/app/MainWindow.kt b/src/main/kotlin/app/MainWindow.kt index 28749ab..8d6ed8a 100644 --- a/src/main/kotlin/app/MainWindow.kt +++ b/src/main/kotlin/app/MainWindow.kt @@ -1,8 +1,6 @@ package app import androidx.compose.runtime.Composable -import androidx.compose.ui.unit.DpSize -import androidx.compose.ui.unit.dp import androidx.compose.ui.window.ApplicationScope import androidx.compose.ui.window.Window import androidx.compose.ui.window.WindowPlacement @@ -30,7 +28,7 @@ fun ApplicationScope.appWindow() { } Thread.setDefaultUncaughtExceptionHandler(CustomExceptionHandler()) SentryHelper.init() - val windowState = rememberWindowState(WindowPlacement.Floating, size = DpSize(1440.dp, 1024.dp)) + val windowState = rememberWindowState(WindowPlacement.Maximized) Window(onCloseRequest = onCloseRequest, title = CustomTheme.strings.appName, state = windowState) { App() } diff --git a/src/main/kotlin/inputs/adb/ddmlib/AdbHelper.kt b/src/main/kotlin/inputs/adb/ddmlib/AdbHelper.kt index 5bd9416..fa2b6d9 100644 --- a/src/main/kotlin/inputs/adb/ddmlib/AdbHelper.kt +++ b/src/main/kotlin/inputs/adb/ddmlib/AdbHelper.kt @@ -29,15 +29,17 @@ object AdbHelper { private const val PACKAGES_COMMAND = "pm list packages -3 -e" // list of lines with format : package:com.ea.games.r3_row + private const val ADB_TIMEOUT = 10L + fun init() { val options = AdbInitOptions.builder().setClientSupportEnabled(true).build() AndroidDebugBridge.init(options) AndroidDebugBridge.addDeviceChangeListener(Devices()) val adbPath = adbPath() bridge = if (!adbPath.isNullOrBlank()) { - AndroidDebugBridge.createBridge(adbPath, false, 10, TimeUnit.SECONDS) + AndroidDebugBridge.createBridge(adbPath, false, ADB_TIMEOUT, TimeUnit.SECONDS) } else { - AndroidDebugBridge.createBridge(10, TimeUnit.SECONDS) + AndroidDebugBridge.createBridge(ADB_TIMEOUT, TimeUnit.SECONDS) } AndroidDebugBridge.addDebugBridgeChangeListener { bridge = it @@ -112,18 +114,18 @@ object AdbHelper { suspend fun getPackages(device: IDevice, onValue: (packages: List) -> Unit) = withContext(Dispatchers.IO) { device.executeShellCommand( PACKAGES_COMMAND, PackagesReceiver(onValue), - 10, TimeUnit.SECONDS + ADB_TIMEOUT, TimeUnit.SECONDS ) } private fun IDevice.emptyShellCommand(command: String) { executeShellCommand( command, - EmptyReceiver, 10, TimeUnit.SECONDS + EmptyReceiver, ADB_TIMEOUT, TimeUnit.SECONDS ) } - private fun adbPath(): String? { + fun adbPath(): String? { val androidEnvHome: File? = try { System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT") } catch (e: SecurityException) { diff --git a/src/main/kotlin/storage/StorageHelper.kt b/src/main/kotlin/storage/StorageHelper.kt index 50121fb..baf9983 100644 --- a/src/main/kotlin/storage/StorageHelper.kt +++ b/src/main/kotlin/storage/StorageHelper.kt @@ -46,9 +46,9 @@ object StorageHelper { val posixAttribute = PosixFilePermissions.asFileAttribute( PosixFilePermissions.fromString("rwxr-x---") ) - Files.createDirectory(folder.toPath(), posixAttribute) + Files.createDirectories(folder.toPath(), posixAttribute) } else { - Files.createDirectory(folder.toPath()) + Files.createDirectories(folder.toPath()) } } catch (e: IOException) { throw IOException("Cannot create app folder at path ${folder.canonicalPath}", e)