Improved stuff and made linux fine

This commit is contained in:
pmoellerfriedrich 2023-09-04 11:06:04 +02:00
parent 6e9347a012
commit 623b86b34a
3 changed files with 116 additions and 47 deletions

View File

@ -1,13 +1,39 @@
import androidx.compose.animation.* import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring import androidx.compose.animation.core.spring
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material3.* import androidx.compose.material3.Icon
import androidx.compose.runtime.* import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.BiasAlignment import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -15,13 +41,22 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.input.key.* import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.res.loadImageBitmap import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.useResource import androidx.compose.ui.res.useResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.* import androidx.compose.ui.window.DialogWindow
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberDialogState
import androidx.compose.ui.window.rememberWindowState
import notifications.NotificationCenter import notifications.NotificationCenter
import theme.Minimize import theme.Minimize
import theme.QuickLaunchTheme import theme.QuickLaunchTheme
@ -155,8 +190,9 @@ fun main() {
minimize = { windowState.isMinimized = true }, minimize = { windowState.isMinimized = true },
openShortcuts = { openHelpWindow.value = true } openShortcuts = { openHelpWindow.value = true }
) )
if (openHelpWindow.value) {
DialogWindow( DialogWindow(
transparent = false,
visible = openHelpWindow.value,
title = "Edit shortcuts", title = "Edit shortcuts",
onCloseRequest = { onCloseRequest = {
openHelpWindow.value = false openHelpWindow.value = false
@ -173,5 +209,4 @@ fun main() {
} }
} }
} }
}

View File

@ -11,7 +11,7 @@ object ShortCutHandler {
private val currentPath: File = private val currentPath: File =
File(System.getProperty("user.home"), ".QuickLaunch") File(System.getProperty("user.home"), ".QuickLaunch")
private val shortcutsFile = File(currentPath, "shortcuts.json") private val shortcutsFile = File(currentPath, "shortcuts.json")
private val _shortcuts = MutableStateFlow<Map<String, String>>(emptyMap()) private val _shortcuts = MutableStateFlow<MutableMap<String, String>>(mutableMapOf())
val shortcuts: StateFlow<Map<String, String>> = _shortcuts val shortcuts: StateFlow<Map<String, String>> = _shortcuts
@ -34,30 +34,44 @@ object ShortCutHandler {
fun addShortcut(short: String, path: String) { fun addShortcut(short: String, path: String) {
_shortcuts.value = buildMap { _shortcuts.value = buildMap {
putAll(shortcuts.value) putAll(_shortcuts.value)
put(short, path) put(short, path)
}.toMutableMap()
}
fun renameShortcutQuietly(oldShort: String, newShort: String) {
if (_shortcuts.value.containsKey(oldShort)) {
_shortcuts.value.remove(oldShort)?.let {
_shortcuts.value.put(newShort, it)
}
}
}
fun updateShortcutQuietly(short: String, path: String){
if (_shortcuts.value.containsKey(short)){
_shortcuts.value[short] = path
} }
} }
fun removeShortcut(short: String) { fun removeShortcut(short: String) {
_shortcuts.value = buildMap { _shortcuts.value = buildMap {
putAll(shortcuts.value.filterNot { entry -> entry.key == short }) putAll(_shortcuts.value.filterNot { entry -> entry.key == short })
} }.toMutableMap()
} }
fun executeShortcut(short: String) { fun executeShortcut(short: String) {
shortcuts.value[short]?.let { _shortcuts.value[short]?.let {
ProcessBuilder(it.split(";")).start() ProcessBuilder(it.split(";")).start()
} }
} }
fun persistToStorage() { fun persistToStorage() {
_shortcuts.value = buildMap { _shortcuts.value = buildMap {
putAll(shortcuts.value.filter { entry -> entry.key.isNotEmpty() }) putAll(_shortcuts.value.filter { entry -> entry.key.isNotEmpty() })
} }.toMutableMap()
BufferedWriter(FileWriter(shortcutsFile)).use { BufferedWriter(FileWriter(shortcutsFile)).use {
it.write( it.write(
Json.Default.encodeToString(shortcuts.value) Json.Default.encodeToString(_shortcuts.value)
) )
} }
} }

View File

@ -2,17 +2,32 @@ package windows
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.* import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.runtime.* import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -52,8 +67,8 @@ fun ShortcutRow(entry: Pair<String, String>) {
modifier = Modifier.fillMaxWidth(0.1f), modifier = Modifier.fillMaxWidth(0.1f),
value = shState.value, value = shState.value,
onValueChange = { onValueChange = {
ShortCutHandler.removeShortcut(shState.value) ShortCutHandler.renameShortcutQuietly(shState.value, it)
ShortCutHandler.addShortcut(it, cmdState.value) shState.value = it
} }
) )
@ -63,7 +78,8 @@ fun ShortcutRow(entry: Pair<String, String>) {
modifier = Modifier.fillMaxWidth(0.85f), modifier = Modifier.fillMaxWidth(0.85f),
value = cmdState.value, value = cmdState.value,
onValueChange = { onValueChange = {
ShortCutHandler.addShortcut(shState.value, it) ShortCutHandler.updateShortcutQuietly(shState.value, it)
cmdState.value = it
}, },
) )
Box( Box(
@ -98,6 +114,10 @@ fun AddFab() {
ShortCutHandler.addShortcut("", "") ShortCutHandler.addShortcut("", "")
} }
) { ) {
Icon(Icons.Default.Add, "add", modifier = Modifier.width(56.dp).height(56.dp).padding(12.dp)) Icon(
Icons.Default.Add,
"add",
modifier = Modifier.width(56.dp).height(56.dp).padding(12.dp)
)
} }
} }