Skip to content

Commit

Permalink
fix(abcdecoder):修复非mac平台下拖动问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Dec 12, 2024
1 parent 48069fa commit fea66d7
Showing 1 changed file with 53 additions and 40 deletions.
93 changes: 53 additions & 40 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,51 +39,64 @@ import java.net.URI
@Composable
fun AbcdeFrame(appState: AppState, content:@Composable ()->Unit) {
var draggingData by remember { mutableStateOf<List<SelectedFile>?>(null) }
Surface {
Box(
Modifier.fillMaxSize().dragAndDropTarget(
shouldStartDragAndDrop = {
it.dragData() is DragData.FilesList
},
object :DragAndDropTarget{
override fun onDrop(event: DragAndDropEvent): Boolean {
val dragData = event.dragData()
if (dragData is DragData.FilesList) {
draggingData = runCatching {
dragData.readFiles().mapNotNull { s ->
SelectedFile.fromOrNull(File(URI(s)))
?.takeIf { it.valid() }
}
}.onFailure {
it.printStackTrace()
}.getOrNull()
}
draggingData?.forEach{
appState.open(it)
}
draggingData = null
return true
}
Surface(Modifier.dragAndDropTarget(
shouldStartDragAndDrop = {
it.dragData() is DragData.FilesList
},
object :DragAndDropTarget{
override fun onDrop(event: DragAndDropEvent): Boolean {
println("onDrop")

override fun onEntered(event: DragAndDropEvent) {
val dragData = event.dragData()
if (dragData is DragData.FilesList) {
draggingData = runCatching {
dragData.readFiles().mapNotNull { s ->
SelectedFile.fromOrNull(File(URI(s)))
?.takeIf { it.valid() }
}
}.onFailure {
it.printStackTrace()
}.getOrNull()
}
val dragData = event.dragData()
if (dragData is DragData.FilesList) {
draggingData = runCatching {
dragData.readFiles().mapNotNull { s ->
SelectedFile.fromOrNull(File(URI(s)))
?.takeIf { it.valid() }
}
}.onFailure {
it.printStackTrace()
}.getOrNull()
}
draggingData?.forEach{
appState.open(it)
}
draggingData = null
return true
}

override fun onExited(event: DragAndDropEvent) {
draggingData = null
override fun onEntered(event: DragAndDropEvent) {
println("onEntered")
}

override fun onExited(event: DragAndDropEvent) {
println("onExited")
draggingData = null
}

override fun onEnded(event: DragAndDropEvent) {
println("onEnded")
draggingData = null
}

override fun onStarted(event: DragAndDropEvent) {
println("onStarted")
val dragData = event.dragData()
if (dragData is DragData.FilesList) {
draggingData = runCatching {
dragData.readFiles().mapNotNull { s ->
SelectedFile.fromOrNull(File(URI(s)))
?.takeIf { it.valid() }
}
}.onFailure {
it.printStackTrace()
}.getOrNull()
}
}
)){
}
)) {
Box(
Modifier.fillMaxSize()){
val blur by animateDpAsState(if(draggingData != null) 16.dp else 0.dp)
Box(
Modifier.let { if(blur != 0.dp) it.blur(blur) else it }
Expand Down

0 comments on commit fea66d7

Please sign in to comment.