Skip to content

Commit

Permalink
add open other app in script lib
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed Oct 8, 2024
1 parent c85dc90 commit 1a6e105
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 13 deletions.
19 changes: 19 additions & 0 deletions desktop/glfw_gui/java/src/main/java/org/mini/glfm/Glfm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
50 changes: 50 additions & 0 deletions extlib/xgui/src/main/java/org/mini/gui/gscript/Stdlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);//打开其他应用
}


Expand Down Expand Up @@ -675,6 +680,39 @@ private DataType decrypt(ArrayList<DataType> 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<DataType> 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<DataType> 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<DataType> para) {
try {
String str = Interpreter.popBackStr(para);
Expand All @@ -697,4 +735,16 @@ private DataType buyAppleProductById(ArrayList<DataType> para) {
return null;
}

private DataType openOtherApp(ArrayList<DataType> 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;
}

}
5 changes: 5 additions & 0 deletions extlib/xgui/src/main/resource/res/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@
"Fail",
"失败",
"失敗"
],
"STR_UPDATE": [
"Update",
"检测更新",
"检测更新"
]
}
}
29 changes: 17 additions & 12 deletions extlib/xgui/src/main/resource/res/ui/AppManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
]]>
</script>
<tr h="{STATEBAR_HEIGHT}" w="100%">
Expand Down Expand Up @@ -197,8 +206,7 @@
<label w="75%" h="30" align="left,vcenter">{STR_INSTALL_FROM_LOCAL}</label>
<button name="BT_LOCALFILE" w="25%" h="30" preicon="📁">{BROWSE_FILE}</button>
<label w="100%" h="20"></label>
<label name="LAB_WEBSRV" w="75%" h="30" align="left,vcenter">{STR_START_WEB_SRV_FOR_UPLOAD}
</label>
<label name="LAB_WEBSRV" w="75%" h="30" align="left,vcenter">{STR_START_WEB_SRV_FOR_UPLOAD}</label>
<button name="BT_STARTWEB" w="25%" h="30" preicon="📤">{STR_START}</button>
<label w="100%" h="20"></label>
<br/>
Expand All @@ -225,14 +233,10 @@
<td w="float" h="100%">
</td>
<td w="200" h="100%">
<button name="BT_DISCOVERY_BACK" w="50" h="30" preicon=""
onclick="prevPage()"></button>
<button name="BT_DISCOVERY_FORWARD" w="50" h="30" preicon=""
onclick="nextPage()"></button>
<button name="BT_DISCOVERY_REFRESH" w="50" h="30" preicon="🔄"
onclick="refreshPage()"></button>
<button name="BT_DISCOVERY_HOME" w="50" h="30" preicon=""
onclick="showHome()"></button>
<button name="BT_DISCOVERY_BACK" w="50" h="30" preicon="" onclick="prevPage()"></button>
<button name="BT_DISCOVERY_FORWARD" w="50" h="30" preicon="" onclick="nextPage()"></button>
<button name="BT_DISCOVERY_REFRESH" w="50" h="30" preicon="🔄" onclick="refreshPage()"></button>
<button name="BT_DISCOVERY_HOME" w="50" h="30" preicon="" onclick="showHome()"></button>
</td>
<td w="float" h="100%">
</td>
Expand All @@ -251,8 +255,7 @@
</td>
<td w="20"></td>
<td w="float" bgcolor="55558020">
<label name="LAB_USERNAME" onclick='showProfile()' w="100%" h="80" color="bb8844ff"
fontsize="18" align="hcenter,vcenter">{SIGN_IN} &gt;
<label name="LAB_USERNAME" onclick='showProfile()' w="100%" h="80" color="bb8844ff" fontsize="18" align="hcenter,vcenter">{SIGN_IN} &gt;
</label>
</td>
</tr>
Expand All @@ -261,6 +264,8 @@
<br/>
<button name="BT_SETTING" w="100%" h="40" preicon="">{SETTING}</button>
<br/>
<button name="BT_UPDATING" w="100%" h="40" onclick="checkUpdate()" preicon="">{STR_UPDATE}</button>
<br/>
<label></label>
</viewport>
</panel>
Expand Down
2 changes: 1 addition & 1 deletion minijvm/c/jvm/jvm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ s32 sys_properties_load(MiniJVM *jvm) {
sys_properties_set_c(jvm, "path.separator", PATHSEPARATOR);
//modify os para
#if __JVM_OS_MAC__
sys_properties_set_c(jvm, "os.name", "Mac");
sys_properties_set_c(jvm, "os.name", "Mac OS");
sys_properties_set_c(jvm, "file.separator", "/");
sys_properties_set_c(jvm, "line.separator", "\n");
sys_properties_set_c(jvm, "XstartOnFirstThread", "1");
Expand Down

0 comments on commit 1a6e105

Please sign in to comment.