Quellcode durchsuchen

code improvements

milan jurkulák vor 2 Jahren
Ursprung
Commit
27600f35f1

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/components/controlcenter/pages/AIPage.kt

@@ -29,7 +29,7 @@ fun AIPage() = ControlCenterPage(
     val onDone: (String) -> Unit = { what ->
         if (what.isNotEmpty()) {
             questionsList.add(Pair(what, ""))
-            api.aiProvider.ask(what) { _, res ->
+            api.ai.ask(what) { _, res ->
                 res.replace("* **", "").replace("**", "").let { resx ->
                     questionsList.removeIf { it.first == what }
                     questionsList.add(Pair(what, resx))

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/components/custom/Clock.kt

@@ -61,7 +61,7 @@ fun Clock(
             val parsed = time.split(":")
             val isZeroMinutes = (parsed.getOrNull(1) ?: "-") == "00"
             if (talkEveryHour && isZeroMinutes) {
-                api.aiProvider.talk("It is ${parsed.firstOrNull()} hour")
+                api.ai.talk("It is ${parsed.firstOrNull()} hour")
             }
         }
     }

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/components/desktoppanel/applets/DesktopPanelFavoriteApps.kt

@@ -44,7 +44,7 @@ fun DesktopPanelFavoriteApps(
             items(apps) { app ->
                 DesktopPanelIcon(
                     app = app,
-                    isRunning = app.isRunning,
+                    isRunning = app.isRunning || app.hasWindow(api),
                     isStarting = app.isStarted,
                     iconColor = iconColor,
                     iconBackgroundColor = iconBackgroundColor,

+ 9 - 5
src/main/kotlin/eu/mjdev/desktop/data/App.kt

@@ -123,12 +123,16 @@ class App(
     }
 
     fun isWindowFocus(api: DesktopProvider): Boolean =
-        api.windowsTracker.isWindowActive(pids)
+        api.windows.isWindowActive(pids)
+
+    fun hasWindow(api: DesktopProvider) =
+        api.windows.getWindowsByPids(pids).isNotEmpty()
 
     fun requestWindowFocus(api: DesktopProvider) {
-        val windows = api.windowsTracker.getWindowsByPids(pids)
+        val windows = api.windows.getWindowsByPids(pids)
         if (windows.isNotEmpty()) {
             println("Got windows:${windows.size}")
+            println("$windows")
             windows.forEach { w -> w.toFront() }
         } else {
             closeWindow(api)
@@ -136,7 +140,7 @@ class App(
     }
 
     fun minimizeWindow(api: DesktopProvider) {
-        val windows = api.windowsTracker.getWindowsByPids(pids)
+        val windows = api.windows.getWindowsByPids(pids)
         if (windows.isNotEmpty()) {
             windows.forEach { w -> w.minimize() }
         } else {
@@ -145,7 +149,7 @@ class App(
     }
 
     fun maximizeWindow(api: DesktopProvider) {
-        val windows = api.windowsTracker.getWindowsByPids(pids)
+        val windows = api.windows.getWindowsByPids(pids)
         if (windows.isNotEmpty()) {
             windows.forEach { w -> w.maximize() }
         } else {
@@ -154,7 +158,7 @@ class App(
     }
 
     fun closeWindow(api: DesktopProvider) {
-        val windows = api.windowsTracker.getWindowsByPids(pids)
+        val windows = api.windows.getWindowsByPids(pids)
         if (windows.isNotEmpty()) {
             windows.forEach { w -> w.close() }
         } else {

+ 4 - 4
src/main/kotlin/eu/mjdev/desktop/helpers/managers/WindowsManager.kt

@@ -211,7 +211,7 @@ class WindowsManager {
         return ret
     }
 
-    fun get_property(
+    private fun get_property(
         window: Window?,
         xa_prop_type: Atom,
         prop_name: String?,
@@ -255,7 +255,7 @@ class WindowsManager {
         return ret_prop.value
     }
 
-    fun client_msg(
+    private fun client_msg(
         window: Window,
         msg: String,
         data0: Long,
@@ -290,7 +290,7 @@ class WindowsManager {
         ) EXIT_SUCCESS else EXIT_FAILURE
     }
 
-    fun activate_window(
+    private fun activate_window(
         window: Window,
         switch_desktop: Boolean
     ): Boolean {
@@ -314,7 +314,7 @@ class WindowsManager {
         return EXIT_SUCCESS
     }
 
-    fun get_active_window(): Window? = get_property_as_window(
+    private fun get_active_window(): Window? = get_property_as_window(
         x11.XDefaultRootWindow(display),
         XA_WINDOW,
         "_NET_ACTIVE_WINDOW"

+ 3 - 3
src/main/kotlin/eu/mjdev/desktop/provider/DesktopProvider.kt

@@ -30,8 +30,8 @@ class DesktopProvider(
     val connection: ConnectivityManager = ConnectivityManager(),
 //    val scriptManager: ScriptEngineManager = ScriptEngineManager(),
     val kcefHelper: KCEFHelper = KCEFHelper(scope),
-    val aiProvider: AIProvider = AIProvider(scope, AiPluginGemini(scope)),
-    val windowsTracker: WindowsManager = WindowsManager()
+    val ai: AIProvider = AIProvider(scope, AiPluginGemini(scope)),
+    val windows: WindowsManager = WindowsManager()
 ) {
     private val __currentUser: User by lazy { User.load() }
     private val _currentUser: MutableState<User> = mutableStateOf(__currentUser)
@@ -83,7 +83,7 @@ class DesktopProvider(
     fun dispose() {
         kcefHelper.dispose()
         mounts.dispose()
-        windowsTracker.dispose()
+        windows.dispose()
     }
 
 //    fun runScript(script: String): Any =