@@ -8,6 +8,7 @@ import android.util.Base64
88import android.view.LayoutInflater
99import android.webkit.JavascriptInterface
1010import android.webkit.WebView
11+ import com.blankj.utilcode.util.AppUtils
1112import com.blankj.utilcode.util.GsonUtils
1213import com.blankj.utilcode.util.LogUtils
1314import com.blankj.utilcode.util.ScreenUtils
@@ -85,30 +86,50 @@ class ASJavascriptInterface(val webView: WebView) {
8586 runCatching {
8687 val request = GsonUtils .fromJson<CallRequest <JsonObject >>(requestJson, object : TypeToken <CallRequest <JsonObject >>() {}.type)
8788 when (request.method) {
89+ CallMethod .getAppInfo -> {
90+ val packageName = request.arguments?.get(" packageName" )?.asString ? : " "
91+ CoroutineWrapper .launch {
92+ runCatching {
93+ val appInfo = AppUtils .getAppInfo(packageName)
94+ callback(CallResponse (code = 0 , data = appInfo, callbackId = request.callbackId))
95+ }.onFailure {
96+ callback(CallResponse (code = 0 , data = JsonObject (), callbackId = request.callbackId))
97+ }
98+ }
99+
100+ }
101+
88102 CallMethod .loadWebViewOverlay -> {
89103 CoroutineWrapper .launch(isMain = true ) {
90- val url = request.arguments?.get(" url" )?.asString ? : " "
91- val initialWidth = request.arguments?.get(" initialWidth" )?.asInt ? : (ScreenUtils .getScreenWidth() * 0.8 ).toInt()
92- val initialHeight = request.arguments?.get(" initialHeight" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
93- val minWidth = request.arguments?.get(" minWidth" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
94- val minHeight = request.arguments?.get(" minHeight" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
95- val initialCenter = request.arguments?.get(" initialCenter" )?.asBoolean ? : true
96-
97- AssistsWindowManager .add(
98- windowWrapper = AssistsWindowWrapper (
99- wmLayoutParams = AssistsWindowManager .createLayoutParams().apply {
100- width = initialWidth
101- height = initialHeight
102- },
103- view = WebFloatingWindowBinding .inflate(LayoutInflater .from(AssistsService .instance)).apply {
104- webView.loadUrl(url)
105- }.root
106- ).apply {
107- this .minWidth = minWidth
108- this .minHeight = minHeight
109- this .initialCenter = initialCenter
110- }
111- )
104+ runCatching {
105+ val url = request.arguments?.get(" url" )?.asString ? : " "
106+ val initialWidth = request.arguments?.get(" initialWidth" )?.asInt ? : (ScreenUtils .getScreenWidth() * 0.8 ).toInt()
107+ val initialHeight = request.arguments?.get(" initialHeight" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
108+ val minWidth = request.arguments?.get(" minWidth" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
109+ val minHeight = request.arguments?.get(" minHeight" )?.asInt ? : (ScreenUtils .getScreenHeight() * 0.5 ).toInt()
110+ val initialCenter = request.arguments?.get(" initialCenter" )?.asBoolean ? : true
111+
112+ AssistsWindowManager .add(
113+ windowWrapper = AssistsWindowWrapper (
114+ wmLayoutParams = AssistsWindowManager .createLayoutParams().apply {
115+ width = initialWidth
116+ height = initialHeight
117+ },
118+ view = WebFloatingWindowBinding .inflate(LayoutInflater .from(AssistsService .instance)).apply {
119+ webView.loadUrl(url)
120+ }.root
121+ ).apply {
122+ this .minWidth = minWidth
123+ this .minHeight = minHeight
124+ this .initialCenter = initialCenter
125+ }
126+ )
127+ }.onSuccess {
128+ callback(CallResponse <Boolean >(code = 0 , data = true , callbackId = request.callbackId))
129+ }.onFailure {
130+ callback(CallResponse <Boolean >(code = - 1 , data = false , callbackId = request.callbackId))
131+ }
132+
112133 }
113134
114135 result = GsonUtils .toJson(CallResponse <JsonObject >(code = 0 , data = JsonObject ().apply {
@@ -233,7 +254,13 @@ class ASJavascriptInterface(val webView: WebView) {
233254
234255 CallMethod .clickByGesture -> {
235256 CoroutineWrapper .launch {
236- AssistsCore .gestureClick(x = request.arguments?.get(" x" )?.asFloat ? : 0f , y = request.arguments?.get(" y" )?.asFloat ? : 0f )
257+ val result =
258+ AssistsCore .gestureClick(x = request.arguments?.get(" x" )?.asFloat ? : 0f , y = request.arguments?.get(" y" )?.asFloat ? : 0f )
259+ if (result) {
260+ callback(CallResponse <Boolean >(code = 0 , data = true , callbackId = request.callbackId))
261+ } else {
262+ callback(CallResponse <Boolean >(code = - 1 , data = false , callbackId = request.callbackId))
263+ }
237264 }
238265 result = GsonUtils .toJson(CallResponse <Boolean >(code = 0 , data = true ))
239266 }
@@ -244,13 +271,17 @@ class ASJavascriptInterface(val webView: WebView) {
244271 val offsetY = request.arguments?.get(" offsetY" )?.asFloat ? : (ScreenUtils .getScreenWidth() * 0.01953f )
245272 val switchWindowIntervalDelay = request.arguments?.get(" switchWindowIntervalDelay" )?.asLong ? : 250
246273 val clickDuration = request.arguments?.get(" clickDuration" )?.asLong ? : 25
247- NodeCacheManager .get(request.node?.nodeId ? : " " )?.nodeGestureClick(
274+ val result = NodeCacheManager .get(request.node?.nodeId ? : " " )?.nodeGestureClick(
248275 offsetX = offsetX,
249276 offsetY = offsetY,
250277 switchWindowIntervalDelay = switchWindowIntervalDelay,
251278 duration = clickDuration
252- )
253- callback(CallResponse <Boolean >(code = 0 , data = true , callbackId = request.callbackId))
279+ ) ? : false
280+ if (result) {
281+ callback(CallResponse <Boolean >(code = 0 , data = true , callbackId = request.callbackId))
282+ } else {
283+ callback(CallResponse <Boolean >(code = - 1 , data = false , callbackId = request.callbackId))
284+ }
254285 }
255286 result = GsonUtils .toJson(CallResponse <JsonObject >(code = 0 , data = JsonObject ().apply {
256287 addProperty(" resultType" , " callback" )
@@ -259,25 +290,30 @@ class ASJavascriptInterface(val webView: WebView) {
259290
260291 CallMethod .doubleClickNodeByGesture -> {
261292 CoroutineWrapper .launch {
262- val offsetX = request.arguments?.get(" offsetX" )?.asFloat ? : (ScreenUtils .getScreenWidth() * 0.01953f )
263- val offsetY = request.arguments?.get(" offsetY" )?.asFloat ? : (ScreenUtils .getScreenWidth() * 0.01953f )
264- val switchWindowIntervalDelay = request.arguments?.get(" switchWindowIntervalDelay" )?.asLong ? : 250
265- val clickDuration = request.arguments?.get(" clickDuration" )?.asLong ? : 25
266- val clickInterval = request.arguments?.get(" clickInterval" )?.asLong ? : 100
267- val bounds = NodeCacheManager .get(request.node?.nodeId ? : " " )?.getBoundsInScreen()
293+ runCatching {
294+ val offsetX = request.arguments?.get(" offsetX" )?.asFloat ? : (ScreenUtils .getScreenWidth() * 0.01953f )
295+ val offsetY = request.arguments?.get(" offsetY" )?.asFloat ? : (ScreenUtils .getScreenWidth() * 0.01953f )
296+ val switchWindowIntervalDelay = request.arguments?.get(" switchWindowIntervalDelay" )?.asLong ? : 250
297+ val clickDuration = request.arguments?.get(" clickDuration" )?.asLong ? : 25
298+ val clickInterval = request.arguments?.get(" clickInterval" )?.asLong ? : 100
299+ val bounds = NodeCacheManager .get(request.node?.nodeId ? : " " )?.getBoundsInScreen()
300+
301+ AssistsWindowManager .nonTouchableByAll()
302+ delay(switchWindowIntervalDelay)
268303
269- AssistsWindowManager .nonTouchableByAll()
270- delay(switchWindowIntervalDelay)
304+ val x = (bounds?.centerX()?.toFloat() ? : 0f ) + offsetX
305+ val y = (bounds?.centerY()?.toFloat() ? : 0f ) + offsetY
271306
272- val x = (bounds?.centerX()?.toFloat() ? : 0f ) + offsetX
273- val y = (bounds?.centerY()?.toFloat() ? : 0f ) + offsetY
307+ AssistsCore .gestureClick(x, y, clickDuration)
308+ delay(clickInterval)
309+ AssistsCore .gestureClick(x, y, clickDuration)
310+ AssistsWindowManager .touchableByAll()
274311
275- AssistsCore .gestureClick(x, y, clickDuration )
276- delay(clickInterval)
277- AssistsCore .gestureClick(x, y, clickDuration )
278- AssistsWindowManager .touchableByAll()
312+ callback( CallResponse < Boolean >(code = 0 , data = true , callbackId = request.callbackId) )
313+ }.onFailure {
314+ callback( CallResponse < Boolean >(code = - 1 , data = false , callbackId = request.callbackId) )
315+ }
279316
280- callback(CallResponse <Boolean >(code = 0 , data = true , callbackId = request.callbackId))
281317 }
282318 result = GsonUtils .toJson(CallResponse <JsonObject >(code = 0 , data = JsonObject ().apply {
283319 addProperty(" resultType" , " callback" )
0 commit comments