From 1a6e105edf44c438cb0eafac5130fdb485ffa825 Mon Sep 17 00:00:00 2001 From: Gust Date: Wed, 9 Oct 2024 00:05:22 +0800 Subject: [PATCH] add open other app in script lib --- .../src/main/java/org/mini/glfm/Glfm.java | 19 +++++++ .../java/org/mini/gui/gscript/Stdlib.java | 50 +++++++++++++++++++ extlib/xgui/src/main/resource/res/lang.json | 5 ++ .../src/main/resource/res/ui/AppManager.xml | 29 ++++++----- minijvm/c/jvm/jvm_util.c | 2 +- 5 files changed, 92 insertions(+), 13 deletions(-) diff --git a/desktop/glfw_gui/java/src/main/java/org/mini/glfm/Glfm.java b/desktop/glfw_gui/java/src/main/java/org/mini/glfm/Glfm.java index 14e9d71f..218cc7b6 100644 --- a/desktop/glfw_gui/java/src/main/java/org/mini/glfm/Glfm.java +++ b/desktop/glfw_gui/java/src/main/java/org/mini/glfm/Glfm.java @@ -297,6 +297,25 @@ public static boolean glfmExtensionSupported(String extension) { } public static int glfmOpenOtherApp(byte[] cStyleURL, byte[] cStyleMore, int detectAppInstalled) { + try { + String url = new String(cStyleURL, "utf-8"); + String more = new String(cStyleMore, "utf-8"); + String osName = System.getProperty("os.name", "");// 获取操作系统的名字 + if (osName.startsWith("Mac OS")) { + // Mac OS + if (more.length() > 0) { + Runtime.getRuntime().exec("open " + url + " " + more); + } else { + Runtime.getRuntime().exec("open " + url); + } + } else if (osName.startsWith("Windows")) { + // Windows + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + } + + } catch (Exception e) { + e.printStackTrace(); + } return 1; } diff --git a/extlib/xgui/src/main/java/org/mini/gui/gscript/Stdlib.java b/extlib/xgui/src/main/java/org/mini/gui/gscript/Stdlib.java index 59798ae0..e4ef758f 100644 --- a/extlib/xgui/src/main/java/org/mini/gui/gscript/Stdlib.java +++ b/extlib/xgui/src/main/java/org/mini/gui/gscript/Stdlib.java @@ -2,6 +2,7 @@ import org.mini.crypt.XorCrypt; import org.mini.glfm.Glfm; +import org.mini.glwrap.GLUtil; import org.mini.gui.GCallBack; import org.mini.reflect.ReflectMethod; @@ -10,6 +11,7 @@ import java.lang.reflect.Method; import java.net.URLDecoder; import java.net.URLEncoder; +import java.security.MessageDigest; import java.util.Random; import java.util.ArrayList; @@ -66,8 +68,11 @@ public Stdlib(Interpreter inp) { methodNames.put("setbit".toLowerCase(), this::setbit);//设整数第n位 methodNames.put("encrypt".toLowerCase(), this::encrypt);//加密 str= encrypt(str,key) methodNames.put("decrypt".toLowerCase(), this::decrypt);//解密 str= decrypt(str,key) + methodNames.put("md5".toLowerCase(), this::md5);//md5 str= md5(str) 返回32位字符串(16字节串) + methodNames.put("sha1".toLowerCase(), this::sha1);//sha1 str= sha1(str) 返回40位字符串(20字节串) methodNames.put("remoteMethodCall".toLowerCase(), this::remoteMethodCall);//远程调用 methodNames.put("buyAppleProductById".toLowerCase(), this::buyAppleProductById);//远程调用 + methodNames.put("openOtherApp".toLowerCase(), this::openOtherApp);//打开其他应用 } @@ -675,6 +680,39 @@ private DataType decrypt(ArrayList para) { return Interpreter.getCachedStr(""); } + public static String byteArrayToHex(byte[] a) { + StringBuilder sb = new StringBuilder(a.length * 2); + for (byte b : a) + sb.append(String.format("%02x", b & 0xff)); + return sb.toString(); + } + + private DataType md5(ArrayList para) { + try { + String str = Interpreter.popBackStr(para); + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(str.getBytes("utf-8")); + String str1 = (byteArrayToHex(md.digest())); + return Interpreter.getCachedStr(str1); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private DataType sha1(ArrayList para) { + try { + String str = Interpreter.popBackStr(para); + MessageDigest md = MessageDigest.getInstance("SHA-1"); + md.update(str.getBytes("utf-8")); + String str1 = (byteArrayToHex(md.digest())); + return Interpreter.getCachedStr(str1); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + private DataType remoteMethodCall(ArrayList para) { try { String str = Interpreter.popBackStr(para); @@ -697,4 +735,16 @@ private DataType buyAppleProductById(ArrayList para) { return null; } + private DataType openOtherApp(ArrayList para) { + try { + String urlstr = Interpreter.popBackStr(para); + String moreStr = Interpreter.popBackStr(para); + int detectAppInstalled = Interpreter.popBackInt(para); + Glfm.glfmOpenOtherApp(GLUtil.toCstyleBytes(urlstr), GLUtil.toCstyleBytes(moreStr), detectAppInstalled); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + } diff --git a/extlib/xgui/src/main/resource/res/lang.json b/extlib/xgui/src/main/resource/res/lang.json index b793e62d..9f8b4b2b 100644 --- a/extlib/xgui/src/main/resource/res/lang.json +++ b/extlib/xgui/src/main/resource/res/lang.json @@ -319,6 +319,11 @@ "Fail", "失败", "失敗" + ], + "STR_UPDATE": [ + "Update", + "检测更新", + "检测更新" ] } } \ No newline at end of file diff --git a/extlib/xgui/src/main/resource/res/ui/AppManager.xml b/extlib/xgui/src/main/resource/res/ui/AppManager.xml index e08092ad..c5d38b91 100644 --- a/extlib/xgui/src/main/resource/res/ui/AppManager.xml +++ b/extlib/xgui/src/main/resource/res/ui/AppManager.xml @@ -40,6 +40,7 @@ setEnv("SHOP_URL",urls[3]) setEnv("PAY_URL",urls[4]) setEnv("PLUGIN_URL",urls[5]) + setEnv("UPDATE_URL",urls[6]) println("urls:\n"+urls) else showMsg("onPolicyRequestBack:"+code+","+msg) @@ -112,6 +113,14 @@ openPage(s3,"") ret + sub checkUpdate() + url=getEnv("UPDATE_URL")+"?"+ getQueryPara() + if(strlen(url)>0) + openOtherApp(url,"",0) ' 第一个为 url,第二个为参数,第三个为检测是否App 存在,0为不检测,1为检测 + eif + ret + + ]]> @@ -197,8 +206,7 @@ - +
@@ -225,14 +233,10 @@ - - - - + + + + @@ -251,8 +255,7 @@ -