Ver Fonte

improvements of favorite apps

milan jurkulák há 2 anos atrás
pai
commit
8b576254c9

+ 1 - 0
build.gradle.kts

@@ -40,6 +40,7 @@ allprojects {
 //        implementation(compose.preview)
 //         resources
 //        implementation(compose.components.resources)
+        implementation(libs.ini4j)
         // http client
         implementation(libs.okhttp.client)
         // palette

+ 2 - 2
buildSrc/src/main/kotlin/org/mjdev/gradle/extensions/ProjectExt.kt

@@ -2,8 +2,8 @@ package org.mjdev.gradle.extensions
 
 import org.gradle.api.Project
 import org.gradle.api.Task
-import org.gradle.internal.impldep.jakarta.xml.bind.DatatypeConverter
 import org.gradle.kotlin.dsl.extra
+import java.lang.Boolean.parseBoolean
 
 @Suppress("HasPlatformType", "unused", "MemberVisibilityCanBePrivate")
 object ProjectExt {
@@ -12,7 +12,7 @@ object ProjectExt {
         get() = project.extra.properties["android.studio.version"]
 
     val Project.runningFromAndroidStudio
-        get() = DatatypeConverter.parseBoolean(project.extra.properties["android.injected.invoked.from.ide"].toString())
+        get() = parseBoolean(project.extra.properties["android.injected.invoked.from.ide"].toString())
 
     val Project.isAndroidStudio
         get() = project.extra.properties.keys.contains("android.studio.version")

+ 1 - 0
gradle/libs.versions.toml

@@ -33,6 +33,7 @@ font-icons-awesome = { module = "br.com.devsrsouza.compose.icons:font-awesome-de
 #compose-webview = { module = "io.github.kevinnzou:compose-webview-multiplatform", version.ref = "compose-webview" }
 #decompose = { module = "com.arkivanov.decompose:decompose", version.ref = "decompose" }
 #decompose-extensions-compose = { module = "com.arkivanov.decompose:extensions-compose", version.ref = "decompose" }
+ini4j = { module = "org.ini4j:ini4j", version = "0.5.4" }
 google-generativeai = { module = "dev.shreyaspatil.generativeai:generativeai-google-jvm", version.ref = "generativeai" }
 
 #// open ai

+ 2 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -1,5 +1,6 @@
+#Thu Sep 12 09:54:13 CEST 2024
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists

+ 2 - 1
src/main/kotlin/eu/mjdev/desktop/components/appsmenu/AppsMenu.kt

@@ -46,6 +46,7 @@ fun AppsMenu(
     items: MutableState<List<Any>> = remember { mutableStateOf(api.appsProvider.appCategories) },
     enter: EnterTransition = fadeIn() + slideInVertically(initialOffsetY = { it }),
     exit: ExitTransition = slideOutVertically(targetOffsetY = { it }) + fadeOut(),
+    appMenuMaxHeight: Dp = api.containerSize.height - bottomY,
     windowState: TopWindowState = rememberTopWindowState(
         position = api.currentUser.theme.panelLocation.alignment,
         size = DpSize(appMenuMinWidth, appMenuMinHeight),
@@ -74,7 +75,7 @@ fun AppsMenu(
             .width(appMenuMinWidth)
             .heightIn(
                 min = appMenuMinHeight,
-                max = appMenuMinHeight
+                max = appMenuMaxHeight
             )
     ) {
         Box(

+ 4 - 2
src/main/kotlin/eu/mjdev/desktop/provider/data/App.kt

@@ -37,9 +37,11 @@ class App(
     val iconBackground: Color
         get() : Color = runCatching { colorFromName() }.getOrNull() ?: Color.White
 
+    // todo :  replace all params with what needed
     fun start() = runCatching {
-        println("Starting app: $name [$exec]")
-        ProcessBuilder("/bin/bash", "-c", exec).start()
+        val cleanExec = exec.replace("%u", "").replace("%U", "")
+        println("Starting app: $name [$cleanExec]")
+        ProcessBuilder("/bin/bash", "-c", cleanExec).start()
     }.onFailure { error ->
         error.printStackTrace()
     }

+ 17 - 24
src/main/kotlin/eu/mjdev/desktop/provider/data/DesktopFile.kt

@@ -1,5 +1,6 @@
 package eu.mjdev.desktop.provider.data
 
+import org.ini4j.Ini
 import java.io.File
 
 @Suppress("ConstPropertyName", "unused")
@@ -7,54 +8,43 @@ class DesktopFile(
     val file: File
 ) {
     private val content
-        get() = file.readText()
-
-    private val lines
-        get() = content.split("\n").map { line ->
-            line.trim()
-        }
+        get() = Ini(file)
 
     private val props
-        get() = lines.mapNotNull { line ->
-            if (line.contains("=")) {
-                val first = line.substring(0, line.indexOf('='))
-                val second = line.substring(line.indexOf('=') + 1)
-                Pair(first, second)
-            } else null
-        }.toMap()
+        get() = content.get("Desktop Entry")
 
     val type
-        get() = props[Prop_Type] ?: ""
+        get() = props?.get(Prop_Type) ?: ""
 
     val version
-        get() = props[Prop_Version] ?: ""
+        get() = props?.get(Prop_Version) ?: ""
 
     val name
-        get() = props[Prop_Name] ?: ""
+        get() = props?.get(Prop_Name) ?: ""
 
     val comment
-        get() = props[Prop_Comment] ?: ""
+        get() = props?.get(Prop_Comment) ?: ""
 
     val path
-        get() = props[Prop_Path] ?: ""
+        get() = props?.get(Prop_Path) ?: ""
 
     val exec
-        get() = props[Prop_Exec] ?: ""
+        get() = props?.get(Prop_Exec) ?: ""
 
     val icon
-        get() = props[Prop_Icon] ?: ""
+        get() = props?.get(Prop_Icon) ?: ""
 
     val categories
-        get() = (props[Prop_Categories] ?: "").split(";").toList()
+        get() = (props?.get(Prop_Categories) ?: "").split(";").toList()
 
     val notifyOnStart
-        get() = (props[Prop_StartupNotify] ?: "false").asBoolean()
+        get() = (props?.get(Prop_StartupNotify) ?: "false").asBoolean()
 
     val runInTerminal
-        get() = (props[Prop_Terminal] ?: "false").asBoolean()
+        get() = (props?.get(Prop_Terminal) ?: "false").asBoolean()
 
     companion object {
-        const val Prop_Type = "Type" // string
+        const val Prop_Type = "Type" // string "Application"
         const val Prop_Version = "Version" // string
         const val Prop_Path = "Path" // string
         const val Prop_Name = "Name" // string
@@ -64,6 +54,9 @@ class DesktopFile(
         const val Prop_Terminal = "Terminal" // boolean
         const val Prop_Icon = "Icon" // string
         const val Prop_Categories = "Categories" // string delimited ;
+        const val Prop_GenericName = "GenericName"
+        const val Prop_MimeType = "MimeType" // string delimited ;
+        const val Prop_Actions = "Actions"
 
         private fun String.asBoolean(): Boolean = when (this.lowercase()) {
             "true" -> true

+ 9 - 16
src/main/kotlin/eu/mjdev/desktop/provider/providers/AppsProvider.kt

@@ -9,7 +9,6 @@ import eu.mjdev.desktop.provider.data.Category
 import eu.mjdev.desktop.provider.data.DesktopFile
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.flow
-import me.xdrop.fuzzywuzzy.FuzzySearch
 import java.io.File
 import java.util.*
 
@@ -93,7 +92,10 @@ class AppsProvider(
         }.getOrNull() ?: emptyList()
 
     private val allAppsDesktopFiles
-        get() = allAppsDesktopFilesLocal + allAppsDesktopFilesShared + allAppsDesktopFilesFlatPack + allAppsDesktopFilesSnap
+        get() = allAppsDesktopFilesLocal +
+                allAppsDesktopFilesShared +
+                allAppsDesktopFilesFlatPack +
+                allAppsDesktopFilesSnap
 
     val currentLocale: Locale
         get() = userDirsLocale ?: Locale.ENGLISH
@@ -122,7 +124,6 @@ class AppsProvider(
             map
         }
 
-    @Suppress("UNNECESSARY_SAFE_CALL")
     val favoriteApps: Flow<List<App>>
         get() = flow {
             Command(
@@ -130,20 +131,12 @@ class AppsProvider(
                 "get",
                 "org.gnome.shell",
                 "favorite-apps"
-            ).execute()?.toList<String>()?.map { appName ->
-                val deskFile = allAppsDesktopFiles.filter { deskFile ->
-                    deskFile?.file?.name?.contains(appName) == true
+            ).execute()?.toList<String>()?.map { deskFileName ->
+                allAppsDesktopFiles.filter { deskFile ->
+                    deskFile.file.name.contentEquals(deskFileName) == true
                 }.map { deskFile ->
-                    Pair(FuzzySearch.ratio(appName, deskFile.file.name), deskFile)
-                }.maxByOrNull {
-                    it.first
-                }?.second
-                if (deskFile != null) {
-                    App(desktopFile = deskFile, file = deskFile?.file)
-                } else {
-                    println("Missing desktop file: $appName")
-                    null
-                }
+                    App(desktopFile = deskFile, file = deskFile.file)
+                }.firstOrNull()
             }.also { list ->
                 emit(list?.filterNotNull() ?: emptyList())
             }