diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json
index 9d2fc194..42739313 100644
--- a/.changelog/lang_zh-Hans.json
+++ b/.changelog/lang_zh-Hans.json
@@ -16,7 +16,7 @@
"notice 模块缺失 getBuilder 等扩展方法的问题 _[`issue #301`](http://issues.autojs6.com/301)_",
"shizuku/shell 等方法无法接受字符串参数的问题 _[`issue #310`](http://issues.autojs6.com/310)_",
"colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_",
- "engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常",
+ "engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常 _[`issue #340`](http://issues.autojs6.com/340)_ _[`issue #339`](http://issues.autojs6.com/339)_",
"floaty.window/floaty.rawWindow 无法在子线程执行的问题",
"floaty.getClip 可能无法正常获取剪切板内容的问题 _[`issue #341`](http://issues.autojs6.com/341)_",
"ui.inflate 返回值丢失 attr/on/click 等原型方法的问题",
@@ -272,7 +272,7 @@
"console.setTouchable 方法 _[`issue #122`](http://issues.autojs6.com/122)_"
],
"fix": [
- "ocr 模块部分方法无法识别区域参数的问题 _[`issue #162`](http://issues.autojs6.com/162)_ _[`issue #175`](http://issues.autojs6.com/175)_",
+ "ocr 模块部分方法无法识别区域参数的问题 _[`issue #162`](http://issues.autojs6.com/162)_ _[`issue #175`](http://issues.autojs6.com/175)_",
"Android 7.x 发现新版本时无法获取版本详情的问题",
"Android 14 申请截图权限时导致应用崩溃的问题",
"主页抽屉快速切换 \"浮动按钮\" 开关时可能导致应用崩溃的问题",
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c88e855f..06e5852d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -255,7 +255,12 @@
-
+
+
+
diff --git a/app/src/main/java/org/autojs/autojs/pluginclient/DevPluginResponseHandler.java b/app/src/main/java/org/autojs/autojs/pluginclient/DevPluginResponseHandler.java
index e052d324..5ed1ea52 100644
--- a/app/src/main/java/org/autojs/autojs/pluginclient/DevPluginResponseHandler.java
+++ b/app/src/main/java/org/autojs/autojs/pluginclient/DevPluginResponseHandler.java
@@ -3,7 +3,6 @@ package org.autojs.autojs.pluginclient;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
-import com.afollestad.materialdialogs.MaterialDialog;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
@@ -18,12 +17,17 @@ import org.autojs.autojs.model.script.Scripts;
import org.autojs.autojs.pio.PFiles;
import org.autojs.autojs.project.ProjectLauncher;
import org.autojs.autojs.script.StringScriptSource;
+import org.autojs.autojs.ui.error.ErrorDialogActivity;
import org.autojs.autojs.util.MD5Utils;
import org.autojs.autojs.util.ViewUtils;
import org.autojs.autojs.util.WorkingDirectoryUtils;
import org.autojs.autojs6.R;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.util.HashMap;
/**
@@ -124,7 +128,19 @@ public class DevPluginResponseHandler implements Handler {
new ProjectLauncher(dir).launch(AutoJs.getInstance().getScriptEngineService());
} catch (Exception e) {
e.printStackTrace();
- ViewUtils.showToast(mContext, R.string.text_invalid_project, true);
+ String message = e.getMessage();
+ if (message == null) {
+ ViewUtils.showToast(mContext, R.string.text_invalid_project, true);
+ } else {
+ // 使用 ErrorDialogActivity 代替直接显示 MaterialDialog
+ // 这样可以避免在非UI线程或Activity不可见状态下调用对话框的问题
+ ErrorDialogActivity.showErrorDialog(
+ mContext.getApplicationContext(),
+ R.string.text_invalid_project,
+ message,
+ R.string.dialog_button_dismiss
+ );
+ }
}
}
@@ -191,11 +207,12 @@ public class DevPluginResponseHandler implements Handler {
var e = err.getMessage();
if (e != null) msg += "\n" + e;
- new MaterialDialog.Builder(mContext)
- .title(R.string.text_failed)
- .content(msg)
- .positiveText(R.string.dialog_button_confirm)
- .show();
+ ErrorDialogActivity.showErrorDialog(
+ mContext.getApplicationContext(),
+ R.string.text_failed,
+ msg,
+ R.string.dialog_button_confirm
+ );
}
);
}
diff --git a/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedRuntimeException.kt b/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedRuntimeException.kt
index f5aefabb..683b4061 100644
--- a/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedRuntimeException.kt
+++ b/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedRuntimeException.kt
@@ -6,7 +6,10 @@ import org.mozilla.javascript.EvaluatorException
// @Hint by SuperMonster003 on Oct 31, 2024.
// ! This class include the exception's code line number when printing the error stack trace.
// ! zh-CN: 当前类可在打印错误堆栈信息时包含异常所在的 code line number (代码行号).
-class WrappedRuntimeException(detailMessage: String, private val causeException: Throwable? = null) : EvaluatorException(detailMessage) {
+class WrappedRuntimeException @JvmOverloads constructor(
+ detailMessage: String,
+ private val causeException: Throwable? = null,
+) : EvaluatorException(detailMessage) {
constructor(causeException: Throwable) : this(causeException.message ?: "", causeException)
diff --git a/app/src/main/java/org/autojs/autojs/ui/error/ErrorDialogActivity.java b/app/src/main/java/org/autojs/autojs/ui/error/ErrorDialogActivity.java
new file mode 100644
index 00000000..a72036d4
--- /dev/null
+++ b/app/src/main/java/org/autojs/autojs/ui/error/ErrorDialogActivity.java
@@ -0,0 +1,71 @@
+package org.autojs.autojs.ui.error;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Window;
+import com.afollestad.materialdialogs.MaterialDialog;
+import org.autojs.autojs.ui.BaseActivity;
+import org.autojs.autojs6.R;
+
+/**
+ * A simple activity to show error dialogs when a context is not available or valid
+ * for showing dialogs directly.
+ */
+public class ErrorDialogActivity extends BaseActivity {
+
+ public static final String EXTRA_TITLE = "title";
+ public static final String EXTRA_MESSAGE = "message";
+ public static final String EXTRA_POSITIVE_BUTTON_TEXT = "positive_button_text";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ // Get extras from intent
+ Intent intent = getIntent();
+ String title = intent.getStringExtra(EXTRA_TITLE);
+ String message = intent.getStringExtra(EXTRA_MESSAGE);
+ String positiveButtonText = intent.getStringExtra(EXTRA_POSITIVE_BUTTON_TEXT);
+
+ // If no positive button text provided, use default dismiss text
+ if (positiveButtonText == null) {
+ positiveButtonText = getString(R.string.dialog_button_dismiss);
+ }
+
+ // Show dialog
+ new MaterialDialog.Builder(this)
+ .title(title)
+ .content(message)
+ .positiveText(positiveButtonText)
+ .positiveColorRes(R.color.dialog_button_default)
+ .cancelable(true)
+ .canceledOnTouchOutside(true)
+ .onPositive((dialog, which) -> finish())
+ .dismissListener(dialog -> finish())
+ .show();
+ }
+
+ /**
+ * Helper method to show an error dialog from any context
+ */
+ public static void showErrorDialog(android.content.Context context, int titleRes, String message) {
+ Intent intent = new Intent(context, ErrorDialogActivity.class);
+ intent.putExtra(EXTRA_TITLE, context.getString(titleRes));
+ intent.putExtra(EXTRA_MESSAGE, message);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(intent);
+ }
+
+ /**
+ * Helper method to show an error dialog from any context with custom positive button text
+ */
+ public static void showErrorDialog(android.content.Context context, int titleRes, String message, int positiveButtonTextRes) {
+ Intent intent = new Intent(context, ErrorDialogActivity.class);
+ intent.putExtra(EXTRA_TITLE, context.getString(titleRes));
+ intent.putExtra(EXTRA_MESSAGE, message);
+ intent.putExtra(EXTRA_POSITIVE_BUTTON_TEXT, context.getString(positiveButtonTextRes));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(intent);
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e8f0b51c..63206876 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,7 +4,7 @@
-
+
]>
diff --git a/version.properties b/version.properties
index 09e1d3ca..24cf87aa 100644
--- a/version.properties
+++ b/version.properties
@@ -1,5 +1,5 @@
-#Sun Apr 13 22:00:48 CST 2025
-BUILD_TIME=1744552848536
+#Mon Apr 14 23:03:48 CST 2025
+BUILD_TIME=1744643028517
COMPILE_SDK_VERSION=35
JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=35
TARGET_SDK_VERSION_INRT=29
-VERSION_BUILD=3137
+VERSION_BUILD=3139
VERSION_NAME=6.6.2 Alpha6
VSCODE_EXT_REQUIRED_VERSION=1.0.8