@@ -527,28 +527,31 @@ object AssistsCore {
527527 gesture : GestureDescription ,
528528 nonTouchableWindowDelay : Long = 100,
529529 ): Boolean {
530- val completableDeferred = CompletableDeferred <Boolean >()
530+ return runCatching {
531+ val completableDeferred = CompletableDeferred <Boolean >()
531532
532- val gestureResultCallback = object : AccessibilityService .GestureResultCallback () {
533- override fun onCompleted (gestureDescription : GestureDescription ? ) {
534- CoroutineWrapper .launch { AssistsWindowManager .touchableByAll() }
535- completableDeferred.complete(true )
536- }
533+ val gestureResultCallback = object : AccessibilityService .GestureResultCallback () {
534+ override fun onCompleted (gestureDescription : GestureDescription ? ) {
535+ CoroutineWrapper .launch { AssistsWindowManager .touchableByAll() }
536+ completableDeferred.complete(true )
537+ }
537538
538- override fun onCancelled (gestureDescription : GestureDescription ? ) {
539- CoroutineWrapper .launch { AssistsWindowManager .touchableByAll() }
540- completableDeferred.complete(false )
539+ override fun onCancelled (gestureDescription : GestureDescription ? ) {
540+ CoroutineWrapper .launch { AssistsWindowManager .touchableByAll() }
541+ completableDeferred.complete(false )
542+ }
541543 }
542- }
543- val runResult = AssistsService .instance?.let {
544- AssistsWindowManager .nonTouchableByAll()
545- delay(nonTouchableWindowDelay)
546- runMain { it.dispatchGesture(gesture, gestureResultCallback, null ) }
547- } ? : let {
548- return false
549- }
550- if (! runResult) return false
551- return completableDeferred.await()
544+ val runResult = AssistsService .instance?.let {
545+ AssistsWindowManager .nonTouchableByAll()
546+ delay(nonTouchableWindowDelay)
547+ runMain { it.dispatchGesture(gesture, gestureResultCallback, null ) }
548+ } ? : let {
549+ return false
550+ }
551+ if (! runResult) return false
552+ return @runCatching completableDeferred.await()
553+ }.getOrDefault(false )
554+
552555 }
553556
554557 /* *
@@ -565,10 +568,12 @@ object AssistsCore {
565568 startTime : Long ,
566569 duration : Long ,
567570 ): Boolean {
568- val path = Path ()
569- path.moveTo(startLocation[0 ], startLocation[1 ])
570- path.lineTo(endLocation[0 ], endLocation[1 ])
571- return gesture(path, startTime, duration)
571+ return runCatching {
572+ val path = Path ()
573+ path.moveTo(startLocation[0 ], startLocation[1 ])
574+ path.lineTo(endLocation[0 ], endLocation[1 ])
575+ return @runCatching gesture(path, startTime, duration)
576+ }.getOrDefault(false )
572577 }
573578
574579 /* *
@@ -583,26 +588,29 @@ object AssistsCore {
583588 startTime : Long ,
584589 duration : Long ,
585590 ): Boolean {
586- val builder = GestureDescription .Builder ()
587- val strokeDescription = GestureDescription .StrokeDescription (path, startTime, duration)
588- val gestureDescription = builder.addStroke(strokeDescription).build()
589- val deferred = CompletableDeferred <Boolean >()
590- val runResult = runMain {
591- return @runMain AssistsService .instance?.dispatchGesture(gestureDescription, object : AccessibilityService .GestureResultCallback () {
592- override fun onCompleted (gestureDescription : GestureDescription ) {
593- deferred.complete(true )
594- }
595-
596- override fun onCancelled (gestureDescription : GestureDescription ) {
597- deferred.complete(false )
591+ return runCatching {
592+ val builder = GestureDescription .Builder ()
593+ val strokeDescription = GestureDescription .StrokeDescription (path, startTime, duration)
594+ val gestureDescription = builder.addStroke(strokeDescription).build()
595+ val deferred = CompletableDeferred <Boolean >()
596+ val runResult = runMain {
597+ return @runMain AssistsService .instance?.dispatchGesture(gestureDescription, object : AccessibilityService .GestureResultCallback () {
598+ override fun onCompleted (gestureDescription : GestureDescription ) {
599+ deferred.complete(true )
600+ }
601+
602+ override fun onCancelled (gestureDescription : GestureDescription ) {
603+ deferred.complete(false )
604+ }
605+ }, null ) ? : let {
606+ return @runMain false
598607 }
599- }, null ) ? : let {
600- return @runMain false
601608 }
602- }
603- if (! runResult) return false
604- val result = deferred.await()
605- return result
609+ if (! runResult) return false
610+ val result = deferred.await()
611+ return result
612+ }.getOrDefault(false )
613+
606614 }
607615
608616 /* *
@@ -674,18 +682,20 @@ object AssistsCore {
674682 switchWindowIntervalDelay : Long = 250,
675683 duration : Long = 25
676684 ): Boolean {
677- runMain { AssistsWindowManager .nonTouchableByAll() }
678- delay(switchWindowIntervalDelay)
679- val rect = getBoundsInScreen()
680- val result = gesture(
681- floatArrayOf(rect.left.toFloat() + offsetX, rect.top.toFloat() + offsetY),
682- floatArrayOf(rect.left.toFloat() + offsetX, rect.top.toFloat() + offsetY),
683- 0 ,
684- duration,
685- )
686- delay(switchWindowIntervalDelay)
687- runMain { AssistsWindowManager .touchableByAll() }
688- return result
685+ return runCatching {
686+ runMain { AssistsWindowManager .nonTouchableByAll() }
687+ delay(switchWindowIntervalDelay)
688+ val rect = getBoundsInScreen()
689+ val result = gesture(
690+ floatArrayOf(rect.left.toFloat() + offsetX, rect.top.toFloat() + offsetY),
691+ floatArrayOf(rect.left.toFloat() + offsetX, rect.top.toFloat() + offsetY),
692+ 0 ,
693+ duration,
694+ )
695+ delay(switchWindowIntervalDelay)
696+ runMain { AssistsWindowManager .touchableByAll() }
697+ return @runCatching result
698+ }.getOrDefault(false )
689699 }
690700
691701 /* *
@@ -704,18 +714,20 @@ object AssistsCore {
704714 clickDuration : Long = 25,
705715 clickInterval : Long = 25,
706716 ): Boolean {
707- AssistsWindowManager .nonTouchableByAll()
708- delay(switchWindowIntervalDelay)
709- val bounds = getBoundsInScreen()
710-
711- val x = bounds.centerX().toFloat() + offsetX
712- val y = bounds.centerY().toFloat() + offsetY
713-
714- AssistsCore .gestureClick(x, y, clickDuration)
715- delay(clickInterval)
716- AssistsCore .gestureClick(x, y, clickDuration)
717- AssistsWindowManager .touchableByAll()
718- return true
717+ return runCatching {
718+ AssistsWindowManager .nonTouchableByAll()
719+ delay(switchWindowIntervalDelay)
720+ val bounds = getBoundsInScreen()
721+
722+ val x = bounds.centerX().toFloat() + offsetX
723+ val y = bounds.centerY().toFloat() + offsetY
724+
725+ AssistsCore .gestureClick(x, y, clickDuration)
726+ delay(clickInterval)
727+ AssistsCore .gestureClick(x, y, clickDuration)
728+ AssistsWindowManager .touchableByAll()
729+ return @runCatching true
730+ }.getOrDefault(true )
719731 }
720732
721733 /* *
0 commit comments