|
|
@@ -1,36 +1,26 @@
|
|
|
package eu.mjdev.desktop.provider
|
|
|
|
|
|
import androidx.compose.runtime.*
|
|
|
-import androidx.compose.ui.graphics.ImageBitmap
|
|
|
-import androidx.compose.ui.graphics.toAwtImage
|
|
|
import androidx.compose.ui.platform.*
|
|
|
import androidx.compose.ui.unit.DpSize
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import coil3.ImageLoader
|
|
|
-import eu.mjdev.desktop.components.controlcenter.base.ControlCenterPage
|
|
|
import eu.mjdev.desktop.components.controlcenter.pages.*
|
|
|
import eu.mjdev.desktop.data.App
|
|
|
import eu.mjdev.desktop.data.DesktopFile
|
|
|
import eu.mjdev.desktop.data.User
|
|
|
import eu.mjdev.desktop.extensions.Compose.asyncImageLoader
|
|
|
-import eu.mjdev.desktop.helpers.adb.AdbDiscover.Companion.adbDevicesHandler
|
|
|
-import eu.mjdev.desktop.helpers.bitmap.Bitmap
|
|
|
import eu.mjdev.desktop.helpers.internal.Palette
|
|
|
import eu.mjdev.desktop.managers.*
|
|
|
-import eu.mjdev.desktop.helpers.system.DBus
|
|
|
import eu.mjdev.desktop.helpers.system.OsRelease
|
|
|
import eu.mjdev.desktop.helpers.system.Shell
|
|
|
-import eu.mjdev.desktop.managers.WindowsManager
|
|
|
import eu.mjdev.desktop.provider.AIProvider.AiPluginGemini
|
|
|
import eu.mjdev.desktop.theme.gtk.GtkThemeHelper
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import java.awt.*
|
|
|
import java.io.File
|
|
|
-import java.io.FileReader
|
|
|
import java.net.URI
|
|
|
-import javax.script.ScriptEngine
|
|
|
-import javax.script.ScriptEngineManager
|
|
|
import kotlin.system.exitProcess
|
|
|
|
|
|
@Suppress("unused", "MemberVisibilityCanBePrivate", "SameParameterValue")
|
|
|
@@ -42,106 +32,111 @@ class DesktopProvider(
|
|
|
val isFirstStart: Boolean = true, // todo
|
|
|
val isInstalled: Boolean = false, // todo
|
|
|
) : AutoCloseable {
|
|
|
- val scriptManager: ScriptEngineManager by lazy { ScriptEngineManager() }
|
|
|
- val scriptEngine: ScriptEngine by lazy {
|
|
|
- scriptManager.getEngineByName("JavaScript").apply {
|
|
|
- // todo
|
|
|
- }
|
|
|
- }
|
|
|
+ // val scriptManager: ScriptEngineManager by lazy { ScriptEngineManager() }
|
|
|
+// val scriptEngine: ScriptEngine by lazy {
|
|
|
+// scriptManager.getEngineByName("JavaScript").apply {
|
|
|
+// // todo
|
|
|
+// }
|
|
|
+// }
|
|
|
val osDetails by lazy { OsRelease() }
|
|
|
val toolkit: Toolkit by lazy { Toolkit.getDefaultToolkit() }
|
|
|
- val kcefHelper: KCEFHelper by lazy { KCEFHelper(this) }
|
|
|
- val gnome: GnomeManager by lazy { GnomeManager() }
|
|
|
- val connectionManager: ConnectivityManager by lazy { ConnectivityManager() }
|
|
|
- val windowsManager: WindowsManager by lazy { WindowsManager(this) }
|
|
|
- val dbus: DBus by lazy { DBus() }
|
|
|
+ val kcefHelper by lazy { KCEFHelper(this) }
|
|
|
+ val gnome by lazy { GnomeManager() }
|
|
|
+ val connectionManager by lazy { ConnectivityManager() }
|
|
|
+
|
|
|
+ // val windowsManager by lazy { WindowsManager(this) }
|
|
|
+// val dbus: DBus by lazy { DBus() }
|
|
|
val ai: AIProvider by lazy {
|
|
|
// todo user can configure
|
|
|
AIProvider(scope, AiPluginGemini(scope))
|
|
|
}
|
|
|
val appsProvider by lazy { AppsProvider(this) }
|
|
|
- val mounts by lazy {
|
|
|
- FileSystemWatcher(scope) {
|
|
|
- println("Mounted: ${this.targetDirectory}")
|
|
|
- }
|
|
|
+
|
|
|
+ // val mounts by lazy {
|
|
|
+// FileSystemWatcher(scope) {
|
|
|
+// println("Mounted: ${this.targetDirectory}")
|
|
|
+// }
|
|
|
+// }
|
|
|
+ val gtkTheme by lazy { GtkThemeHelper(this) }
|
|
|
+ val palette by lazy { Palette(this) }
|
|
|
+ val desktopUtils: Desktop by lazy {
|
|
|
+ Desktop.getDesktop()
|
|
|
}
|
|
|
- val gtkTheme: GtkThemeHelper by lazy { GtkThemeHelper(this) }
|
|
|
- val palette: Palette by lazy { Palette(this) }
|
|
|
- val homeDir: File
|
|
|
+
|
|
|
+ val homeDir
|
|
|
get() = currentUser.homeDir
|
|
|
- val allUsers: List<User>
|
|
|
+ val allUsers
|
|
|
get() = User.allUsers
|
|
|
- val machineName: String
|
|
|
+ val machineName
|
|
|
get() = Shell.executeAndRead("hostname").trim()
|
|
|
|
|
|
// todo state
|
|
|
val currentUser: User
|
|
|
get() = allUsers.firstOrNull { u -> u.isLoggedIn } ?: User.Nobody
|
|
|
- val controlCenterPagesState: MutableState<List<ControlCenterPage>> = mutableStateOf(CONTROL_CENTER_PAGES)
|
|
|
- var lastTheme: String = ""
|
|
|
- val adbHandler = adbDevicesHandler(
|
|
|
- coroutineScope = scope,
|
|
|
- onAdded = { device ->
|
|
|
- println("Device discovered : $device")
|
|
|
- // when device connected
|
|
|
- },
|
|
|
- onRemoved = { device ->
|
|
|
- println("Device removed : $device")
|
|
|
- // when device removed
|
|
|
- }
|
|
|
- )
|
|
|
+
|
|
|
+ val controlCenterPagesState = mutableStateOf(CONTROL_CENTER_PAGES)
|
|
|
+
|
|
|
+// val adbHandler = adbDevicesHandler(
|
|
|
+// coroutineScope = scope,
|
|
|
+// onAdded = { device ->
|
|
|
+// println("Device discovered : $device")
|
|
|
+// // when device connected
|
|
|
+// },
|
|
|
+// onRemoved = { device ->
|
|
|
+// println("Device removed : $device")
|
|
|
+// // when device removed
|
|
|
+// }
|
|
|
+// )
|
|
|
+
|
|
|
val containerSize: DpSize
|
|
|
get() = runCatching {
|
|
|
toolkit.screenSize.let { screen -> DpSize(screen.width.dp, screen.height.dp) }
|
|
|
}.getOrNull() ?: DpSize.Zero
|
|
|
+
|
|
|
val isAlwaysOnTopSupported
|
|
|
get() = runCatching {
|
|
|
toolkit.isAlwaysOnTopSupported
|
|
|
}.getOrNull() ?: false
|
|
|
+
|
|
|
val cursorSize
|
|
|
get() = toolkit.getBestCursorSize(32, 32).let {
|
|
|
DpSize(it.width.dp, it.height.dp)
|
|
|
}
|
|
|
- val desktopUtils: Desktop by lazy {
|
|
|
- Desktop.getDesktop()
|
|
|
- }
|
|
|
+
|
|
|
val controlCenterPages
|
|
|
get() = controlCenterPagesState.value
|
|
|
+
|
|
|
val graphicsEnvironment: GraphicsEnvironment
|
|
|
get() = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
|
|
+
|
|
|
val graphicsDevice: GraphicsDevice
|
|
|
get() = graphicsEnvironment.defaultScreenDevice
|
|
|
+
|
|
|
val isTransparencySupported
|
|
|
get() = graphicsDevice.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)
|
|
|
|
|
|
- init {
|
|
|
- runCatching {
|
|
|
- mounts.init()
|
|
|
- }
|
|
|
- runCatching {
|
|
|
- dbus.updateEnvironment()
|
|
|
- }
|
|
|
- runCatching {
|
|
|
- lastTheme = gnome.getGTKTheme()
|
|
|
- }
|
|
|
+// init {
|
|
|
// runCatching {
|
|
|
-// gnome.setGTKTheme(THEME_MJDEV)
|
|
|
+// windowsManager.init()
|
|
|
// }
|
|
|
- }
|
|
|
+// runCatching {
|
|
|
+// mounts.init()
|
|
|
+// }
|
|
|
+// runCatching {
|
|
|
+// dbus.updateEnvironment()
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
override fun close() {
|
|
|
// runCatching {
|
|
|
-// gnome.setGTKTheme(lastTheme)
|
|
|
+// mounts.dispose()
|
|
|
+// }
|
|
|
+// runCatching {
|
|
|
+// kcefHelper.dispose()
|
|
|
+// }
|
|
|
+// runCatching {
|
|
|
+// windowsManager.dispose()
|
|
|
// }
|
|
|
- runCatching {
|
|
|
- mounts.dispose()
|
|
|
- }
|
|
|
- runCatching {
|
|
|
- kcefHelper.dispose()
|
|
|
- }
|
|
|
- runCatching {
|
|
|
- windowsManager.dispose()
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
fun openMail(emailAddress: String) = runCatching {
|
|
|
@@ -172,13 +167,13 @@ class DesktopProvider(
|
|
|
openFileInAssociated(File(filePath))
|
|
|
}
|
|
|
|
|
|
- fun runScript(script: String): Any = runCatching {
|
|
|
- scriptEngine.eval(script)
|
|
|
- }
|
|
|
+// fun runScript(script: String): Any = runCatching {
|
|
|
+// scriptEngine.eval(script)
|
|
|
+// }
|
|
|
|
|
|
- fun runScript(file: File): Any = runCatching {
|
|
|
- scriptEngine.eval(FileReader(file))
|
|
|
- }
|
|
|
+// fun runScript(file: File): Any = runCatching {
|
|
|
+// scriptEngine.eval(FileReader(file))
|
|
|
+// }
|
|
|
|
|
|
fun beep() = runCatching {
|
|
|
toolkit.beep()
|
|
|
@@ -188,17 +183,17 @@ class DesktopProvider(
|
|
|
toolkit.sync()
|
|
|
}
|
|
|
|
|
|
- fun createCustomCursor(cursor: Image, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
- toolkit.createCustomCursor(cursor, hotSpot, name)
|
|
|
- }.getOrNull()
|
|
|
+// fun createCustomCursor(cursor: Image, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
+// toolkit.createCustomCursor(cursor, hotSpot, name)
|
|
|
+// }.getOrNull()
|
|
|
|
|
|
- fun createCustomCursor(cursor: Bitmap, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
- toolkit.createCustomCursor(cursor.image, hotSpot, name)
|
|
|
- }.getOrNull()
|
|
|
+// fun createCustomCursor(cursor: Bitmap, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
+// toolkit.createCustomCursor(cursor.image, hotSpot, name)
|
|
|
+// }.getOrNull()
|
|
|
|
|
|
- fun createCustomCursor(cursor: ImageBitmap, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
- toolkit.createCustomCursor(cursor.toAwtImage(), hotSpot, name)
|
|
|
- }.getOrNull()
|
|
|
+// fun createCustomCursor(cursor: ImageBitmap, hotSpot: Point, name: String): Cursor? = runCatching {
|
|
|
+// toolkit.createCustomCursor(cursor.toAwtImage(), hotSpot, name)
|
|
|
+// }.getOrNull()
|
|
|
|
|
|
// todo
|
|
|
// fun createCustomCursor(cursor: ImageVector, hotSpot: Point, name: String) =
|
|
|
@@ -213,19 +208,24 @@ class DesktopProvider(
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ fun lock() {
|
|
|
+ Shell.executeAndRead("/usr/bin/loginctl", "lock-sessions")
|
|
|
+ }
|
|
|
+
|
|
|
fun logOut() {
|
|
|
- // todo
|
|
|
exitProcess(0)
|
|
|
}
|
|
|
|
|
|
+ fun suspend() {
|
|
|
+ Shell.executeAndRead("/usr/bin/systemctl", "suspend")
|
|
|
+ }
|
|
|
+
|
|
|
fun shutdown() {
|
|
|
- // todo
|
|
|
- exitProcess(0)
|
|
|
+ Shell.executeAndRead("/usr/sbin/halt", "--poweroff")
|
|
|
}
|
|
|
|
|
|
fun restart() {
|
|
|
- // todo
|
|
|
- exitProcess(0)
|
|
|
+ Shell.executeAndRead("/usr/sbin/halt", "--reboot")
|
|
|
}
|
|
|
|
|
|
companion object {
|