mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
add samples, fix require()
This commit is contained in:
parent
956f064737
commit
e5ade55519
@ -107,7 +107,7 @@ dependencies {
|
||||
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
|
||||
compile group: 'com.twofortyfouram', name: 'android-plugin-client-sdk-for-locale', version: '[4.0.2, 5.0['
|
||||
compile 'com.android.volley:volley:1.0.0'
|
||||
compile 'com.github.hyb1996:EnhancedFloaty:0.16'
|
||||
compile 'com.github.hyb1996:EnhancedFloaty:0.17'
|
||||
compile 'com.flurry.android:analytics:7.0.0@aar'
|
||||
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
||||
compile 'com.android.support:multidex:1.0.1'
|
||||
|
||||
@ -9,7 +9,7 @@ dialogs.rawInput = function(title, prefill){
|
||||
};
|
||||
|
||||
dialogs.input = function(title, prefill){
|
||||
return eval(rawInput(title, prefill));
|
||||
return eval(dialogs.rawInput(title, prefill) + "");
|
||||
}
|
||||
|
||||
dialogs.prompt = dialogs.rawInput;
|
||||
@ -28,15 +28,18 @@ dialogs.select = function(title, items){
|
||||
return __runtime__.dialogs.select(title, [].slice.call(arguments, 1));
|
||||
}
|
||||
|
||||
dialogs.singleChoice = function(title, index, items){
|
||||
return __runtime__.dialogs.singleChoice(title, index, [].slice.call(arguments, 2));
|
||||
dialogs.singleChoice = function(title, items, index){
|
||||
index = index || 0;
|
||||
return __runtime__.dialogs.singleChoice(title, index, items);
|
||||
}
|
||||
|
||||
dialogs.multiChoice = function(title, index, items){
|
||||
var javaArray = __runtime__.dialogs.multiChoice(title, index, [].slice.call(arguments, 2));
|
||||
var jsArray = {};
|
||||
for each(i in javaArray){
|
||||
jsArray.push(i);
|
||||
dialogs.multiChoice = function(title, items, index){
|
||||
index = index || [];
|
||||
var javaArray = __runtime__.dialogs.multiChoice(title, index, items);
|
||||
var jsArray = [];
|
||||
var len = javaArray.length;
|
||||
for (var i = 0;i < len;i++){
|
||||
jsArray.push(javaArray[i]);
|
||||
}
|
||||
return jsArray;
|
||||
}
|
||||
@ -56,23 +59,3 @@ var confirm = function(title, prefill){
|
||||
var prompt = function(title, prefill){
|
||||
return dialogs.prompt(title, prefill);
|
||||
}
|
||||
/*
|
||||
|
||||
dialogs.rawInput = function(title, prefill){
|
||||
prefill = prefill || "";
|
||||
return __runtime__.dialogs.rawInput(title, prefill);
|
||||
}
|
||||
|
||||
dialogs.input = function(title, prefill){
|
||||
return eval(rawInput(title, prefill));
|
||||
}
|
||||
|
||||
dialogs.alert = function(title, content){
|
||||
__runtime__.dialogs.alert(title, content);
|
||||
}
|
||||
|
||||
dialogs.select = function(title, content){
|
||||
__runtime__.dialogs.alert(title, content);
|
||||
}
|
||||
|
||||
*/
|
||||
3
app/src/main/assets/modules/dialogs.js
Normal file
3
app/src/main/assets/modules/dialogs.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = function(){
|
||||
|
||||
}
|
||||
2
app/src/main/assets/sample/对话框/单选框.js
Normal file
2
app/src/main/assets/sample/对话框/单选框.js
Normal file
@ -0,0 +1,2 @@
|
||||
var sex = dialogs.singleChoice("请选择性别", ["男", "女", "基佬", "女装", "其他"], 2);
|
||||
toast("选择了第" + (sex + 1) + "个选项");
|
||||
7
app/src/main/assets/sample/对话框/多选框.js
Normal file
7
app/src/main/assets/sample/对话框/多选框.js
Normal file
@ -0,0 +1,7 @@
|
||||
var i = dialogs.multiChoice("下列作品出自李贽的是", ["《焚书》", "《西湖寻梦》", "《高太史全集》", "《续焚烧书》", "《藏书》"]);
|
||||
toast("选择了: " + i);
|
||||
if(i.length == 2 && i.toString() == [0, 4].toString()){
|
||||
toast("答对辣");
|
||||
}else{
|
||||
toast("答错辣");
|
||||
}
|
||||
9
app/src/main/assets/sample/对话框/确认框.js
Normal file
9
app/src/main/assets/sample/对话框/确认框.js
Normal file
@ -0,0 +1,9 @@
|
||||
var handsome = confirm("你帅吗?");
|
||||
if(handsome){
|
||||
toast("真不要脸!");
|
||||
toast("真不要脸!");
|
||||
toast("真不要脸!");
|
||||
alert("真不要脸!");
|
||||
}else{
|
||||
toast("嗯");
|
||||
}
|
||||
15
app/src/main/assets/sample/对话框/菜单.js
Normal file
15
app/src/main/assets/sample/对话框/菜单.js
Normal file
@ -0,0 +1,15 @@
|
||||
while(true){
|
||||
var i = dialogs.select("哲学的基本问题是", "社会和自然的关系问题", "思维与存在的关系问题", "政治和经济的关系问题", "实践和理论的关系问题");
|
||||
if(i == -1){
|
||||
toast("猜一下呗");
|
||||
continue;
|
||||
}
|
||||
if(i == 1){
|
||||
toast("答对辣");
|
||||
break;
|
||||
}else{
|
||||
toast("答错辣")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
app/src/main/assets/sample/对话框/输入框.js
Normal file
4
app/src/main/assets/sample/对话框/输入框.js
Normal file
@ -0,0 +1,4 @@
|
||||
var name = rawInput("请输入名字");
|
||||
alert("(•́へ•́╬)", "你好~ " + name);
|
||||
var expr = dialogs.input("请输入简单的算式", "1+1");
|
||||
alert("计算结果为 " + expr);
|
||||
@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.iwebpp.node.NodeContext;
|
||||
import com.iwebpp.node.http.ClientRequest;
|
||||
@ -16,6 +17,7 @@ import com.squareup.leakcanary.LeakCanary;
|
||||
import com.stardust.app.SimpleActivityLifecycleCallbacks;
|
||||
import com.stardust.app.VolumeChangeObserver;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floating_window.OverlayPermissionChecker;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.statics.ScriptStatics;
|
||||
import com.stardust.scriptdroid.tool.CrashHandler;
|
||||
|
||||
@ -95,7 +95,6 @@ public class AutoJs implements AccessibilityBridge {
|
||||
|
||||
private NodeJsJavaScriptEngineManager createScriptEngineManager(Context context) {
|
||||
NodeJsJavaScriptEngineManager manager = new NodeJsJavaScriptEngineManager(context);
|
||||
manager.setRequirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH);
|
||||
try {
|
||||
manager.setInitScript(PFile.read(context.getAssets().open(INIT_SCRIPT_PATH)));
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||
import com.stardust.util.IntentUtil;
|
||||
|
||||
@ -15,9 +21,13 @@ import com.stardust.util.IntentUtil;
|
||||
|
||||
public class FloatingWindowManger {
|
||||
|
||||
private static final String KEY_FLOATING_WINDOW_PERMISSION = "May we go back..I...miss..you..Eating..17.5.9";
|
||||
private static final String TAG = "FloatingWindowManger";
|
||||
|
||||
public static void showHoverMenu() {
|
||||
if (!HoverMenuService.isServiceRunning()) {
|
||||
if (!hasFloatingWindowPermission()) {
|
||||
if (!hasFloatingWindowPermission(App.getApp())) {
|
||||
Toast.makeText(App.getApp(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
goToFloatingWindowPermissionSetting();
|
||||
} else {
|
||||
HoverMenuService.startService(App.getApp());
|
||||
@ -26,33 +36,54 @@ public class FloatingWindowManger {
|
||||
}
|
||||
|
||||
public static void goToFloatingWindowPermissionSetting() {
|
||||
String packageName = App.getApp().getPackageName();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
App.getApp().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
} catch (Exception e) {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
} else {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
private static void goToOverlayPermissionSettings(Context context, String packageName) {
|
||||
try {
|
||||
App.getApp().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + context))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
} catch (Exception e) {
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasFloatingWindowPermission() {
|
||||
public static void checkPermission() {
|
||||
final OverlayPermissionChecker checker = new OverlayPermissionChecker(App.getApp());
|
||||
checker.setCallback(new OverlayPermissionChecker.Callback() {
|
||||
@Override
|
||||
public void onCheckResult(boolean granted) {
|
||||
checker.setCallback(null);
|
||||
Log.d(TAG, "onCheckResult:" + granted);
|
||||
setHasFloatingWindowPermission(App.getApp(), granted);
|
||||
}
|
||||
});
|
||||
checker.check(1500);
|
||||
}
|
||||
|
||||
public static boolean hasFloatingWindowPermission(Context context) {
|
||||
return hasOverlayPermission();
|
||||
}
|
||||
|
||||
private static void setHasFloatingWindowPermission(Context context, boolean has) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(KEY_FLOATING_WINDOW_PERMISSION, has).apply();
|
||||
}
|
||||
|
||||
private static boolean hasOverlayPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return Settings.canDrawOverlays(App.getApp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isFloatingWindowShowing() {
|
||||
public static boolean isHoverMenuShowing() {
|
||||
return HoverMenuService.isServiceRunning();
|
||||
}
|
||||
|
||||
|
||||
public static void hideFloatingWindow() {
|
||||
public static void hideHoverMenu() {
|
||||
if (HoverMenuService.isServiceRunning())
|
||||
App.getApp().stopService(new Intent(App.getApp(), HoverMenuService.class));
|
||||
}
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
package com.stardust.scriptdroid.external.floating_window;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/9.
|
||||
@ -11,41 +25,99 @@ import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
|
||||
public class OverlayPermissionChecker {
|
||||
|
||||
|
||||
public static void addFloaty() {
|
||||
FloatyService.addWindow(new FloatyWindow() {
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
});
|
||||
public interface Callback {
|
||||
void onCheckResult(boolean granted);
|
||||
}
|
||||
|
||||
private static class OnePixelWindow implements FloatyWindow {
|
||||
private OnePixelWindow mOnePixelWindow = new OnePixelWindow();
|
||||
private Callback mCallback;
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private Boolean mCheckResult = null;
|
||||
|
||||
public OverlayPermissionChecker(Context context) {
|
||||
mContext = context;
|
||||
mHandler = new Handler(context.getMainLooper());
|
||||
}
|
||||
|
||||
public void check() {
|
||||
mCheckResult = null;
|
||||
try {
|
||||
FloatyService.addWindow(mOnePixelWindow);
|
||||
mContext.startService(new Intent(mContext, FloatyService.class));
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
onCheckResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void check(int timeOut) {
|
||||
check();
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mCheckResult == null) {
|
||||
onCheckResult(false);
|
||||
}
|
||||
}
|
||||
}, timeOut);
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
private void onCheckResult(boolean b) {
|
||||
mCheckResult = b;
|
||||
if (mCallback != null) {
|
||||
mCallback.onCheckResult(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class OnePixelWindow implements FloatyWindow {
|
||||
|
||||
private View mOnePixelView;
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
|
||||
mWindowManager = windowManager;
|
||||
mOnePixelView = new View(floatyService) {
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
notifyWindowVisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWindowVisibilityChanged(int visibility) {
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
}
|
||||
};
|
||||
mOnePixelView.setWillNotDraw(false);
|
||||
mOnePixelView.setBackgroundColor(Color.RED);
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(10, 10,
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
params.gravity = Gravity.TOP | Gravity.START;
|
||||
windowManager.addView(mOnePixelView, params);
|
||||
}
|
||||
|
||||
private void notifyWindowVisible() {
|
||||
onCheckResult(true);
|
||||
//close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
mWindowManager.removeView(mOnePixelView);
|
||||
FloatyService.removeWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/22.
|
||||
*/
|
||||
@ -35,6 +37,7 @@ public class RunIntentActivity extends Activity {
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String path = getPath(intent);
|
||||
String directoryPath = null;
|
||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||
ScriptSource source = null;
|
||||
if (path == null && script != null) {
|
||||
@ -42,9 +45,13 @@ public class RunIntentActivity extends Activity {
|
||||
} else if (path != null && new PathChecker(this).checkAndToastError(path)) {
|
||||
ScriptSource fileScriptSource = new FileScriptSource(path);
|
||||
source = new SequenceScriptSource(fileScriptSource.getName(), new StringScriptSource(script), fileScriptSource);
|
||||
directoryPath = new File(path).getParent();
|
||||
}
|
||||
if (source != null) {
|
||||
Scripts.run(source);
|
||||
if (directoryPath == null)
|
||||
Scripts.run(source);
|
||||
else
|
||||
Scripts.run(source, directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.stardust.autojs.execution.ExecutionConfig;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||
import com.stardust.autojs.execution.SimpleScriptExecutionListener;
|
||||
@ -81,15 +82,22 @@ public class Scripts {
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptFile file) {
|
||||
return run(new FileScriptSource(file));
|
||||
return run(new FileScriptSource(file), file.getParent());
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptSource source, String directoryPath) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.requirePath(directoryPath, StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(ScriptSource source) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig()
|
||||
.requirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource scriptSource) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(scriptSource, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER);
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource scriptSource, String directoryPath) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(scriptSource, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER,
|
||||
new ExecutionConfig().requirePath(directoryPath, StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
|
||||
public static ScriptExecution run(Context context, Sample file) {
|
||||
@ -97,4 +105,8 @@ public class Scripts {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source);
|
||||
}
|
||||
|
||||
public static ScriptExecution runWithBroadcastSender(ScriptSource source) {
|
||||
return AutoJs.getInstance().getScriptEngineService().execute(source, BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER,
|
||||
new ExecutionConfig().requirePath(StorageScriptProvider.DEFAULT_DIRECTORY_PATH));
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -50,7 +51,6 @@ public class StardustConsole extends AbstractConsole {
|
||||
private ConsoleFloaty mConsoleFloaty;
|
||||
private LogListener mLogListener;
|
||||
private UiHandler mUiHandler;
|
||||
//private volatile VolatileBox<String> mInput = new VolatileBox<>("");
|
||||
private BlockingQueue<String> mInput = new ArrayBlockingQueue<>(1);
|
||||
private ConsoleView mConsoleView;
|
||||
private volatile boolean mShown = false;
|
||||
@ -98,6 +98,10 @@ public class StardustConsole extends AbstractConsole {
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (!FloatingWindowManger.hasFloatingWindowPermission(mUiHandler.getContext())) {
|
||||
FloatingWindowManger.goToFloatingWindowPermissionSetting();
|
||||
mUiHandler.toast(R.string.text_no_floating_window_permission);
|
||||
}
|
||||
startFloatyService();
|
||||
mUiHandler.post(new Runnable() {
|
||||
@Override
|
||||
|
||||
@ -206,11 +206,7 @@ public class EditActivity extends Editor920Activity {
|
||||
private void run() {
|
||||
Snackbar.make(mView, R.string.text_start_running, Snackbar.LENGTH_SHORT).show();
|
||||
setMenuStatus(R.id.run, MenuDef.STATUS_DISABLED);
|
||||
if (mFile != null) {
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new FileScriptSource(mName, mFile));
|
||||
} else {
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new StringScriptSource(mName, mEditorDelegate.getText()));
|
||||
}
|
||||
mScriptExecution = Scripts.runWithBroadcastSender(new FileScriptSource(mName, mFile), mFile.getParent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ public class EditSideMenuFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void syncSwitchState() {
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isFloatingWindowShowing());
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isHoverMenuShowing());
|
||||
}
|
||||
|
||||
private void setUpSwitchCompat() {
|
||||
@ -97,10 +97,10 @@ public class EditSideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_floating_window)
|
||||
private void setFloatingWindowEnable(boolean enable) {
|
||||
if (enable && !FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
if (enable && !FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.showHoverMenu();
|
||||
} else if (!enable && FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
FloatingWindowManger.hideFloatingWindow();
|
||||
} else if (!enable && FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ import com.stardust.app.NotAskAgainDialog;
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
|
||||
@ -88,7 +88,7 @@ public class SlideMenuFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
}, 450);
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isFloatingWindowShowing());
|
||||
mFloatingWindowSwitch.setChecked(FloatingWindowManger.isHoverMenuShowing());
|
||||
}
|
||||
|
||||
private void setUpSwitchCompat() {
|
||||
@ -123,10 +123,10 @@ public class SlideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_floating_window)
|
||||
private void setFloatingWindowEnable(boolean enable) {
|
||||
if (enable && !FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
if (enable && !FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.showHoverMenu();
|
||||
} else if (!enable && FloatingWindowManger.isFloatingWindowShowing()) {
|
||||
FloatingWindowManger.hideFloatingWindow();
|
||||
} else if (!enable && FloatingWindowManger.isHoverMenuShowing()) {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,11 +15,9 @@ if(__engine_name__ == "rhino"){
|
||||
|
||||
|
||||
var __asGlobal__ = function(obj, functions){
|
||||
__runtime__.console.log(functions);
|
||||
var len = functions.length;
|
||||
for(var i = 0; i < len; i++) {
|
||||
var funcName = functions[i];
|
||||
__runtime__.console.log(funcName);
|
||||
this[funcName] = obj[funcName].bind(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,10 @@ module.exports = function(__runtime__, scope){
|
||||
console.assertTrue(value, message);
|
||||
}
|
||||
|
||||
console.input = function(data, param){
|
||||
return eval(console.rawInput.call(console, [].slice(arguments)) + "");
|
||||
}
|
||||
|
||||
scope.print = console.log.bind(console);
|
||||
|
||||
scope.log = scope.print;
|
||||
|
||||
@ -142,6 +142,10 @@ public class ScriptEngineService {
|
||||
return execute(new ScriptExecutionTask(source, listener, config));
|
||||
}
|
||||
|
||||
public ScriptExecution execute(ScriptSource source, ExecutionConfig config) {
|
||||
return execute(new ScriptExecutionTask(source, null, config));
|
||||
}
|
||||
|
||||
public ScriptExecution execute(ScriptSource source, ScriptExecutionListener listener) {
|
||||
return execute(source, listener, ExecutionConfig.getDefault());
|
||||
}
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
package com.stardust.autojs.engine;
|
||||
|
||||
import org.mozilla.javascript.commonjs.module.provider.ModuleSource;
|
||||
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/9.
|
||||
*/
|
||||
|
||||
public class AssetAndUrlModuleSourceProvider extends UrlModuleSourceProvider {
|
||||
|
||||
private static final String MODULES_PATH = "modules";
|
||||
private android.content.Context mContext;
|
||||
private List<String> mModules;
|
||||
private final URI mBaseURI = URI.create("file:///android_asset/modules");
|
||||
|
||||
public AssetAndUrlModuleSourceProvider(android.content.Context context, List<URI> list) {
|
||||
super(list, null);
|
||||
mContext = context;
|
||||
try {
|
||||
mModules = Arrays.asList(mContext.getAssets().list(MODULES_PATH));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ModuleSource loadFromPrivilegedLocations(String moduleId, Object validator) throws IOException, URISyntaxException {
|
||||
String moduleIdWithExtension = moduleId;
|
||||
if (!moduleIdWithExtension.endsWith(".js")) {
|
||||
moduleIdWithExtension += ".js";
|
||||
}
|
||||
if (mModules.contains(moduleIdWithExtension)) {
|
||||
return new ModuleSource(new InputStreamReader(mContext.getAssets().open(MODULES_PATH + "/" + moduleIdWithExtension)), null,
|
||||
URI.create(moduleIdWithExtension), mBaseURI, validator);
|
||||
}
|
||||
return super.loadFromPrivilegedLocations(moduleId, validator);
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,6 @@ public class NodeJsJavaScriptEngineManager extends RhinoJavaScriptEngineManager
|
||||
@Override
|
||||
protected NodeJsJavaScriptEngine createEngineInner() {
|
||||
NodeJsJavaScriptEngine engine = new NodeJsJavaScriptEngine(this);
|
||||
initRequireBuilder(engine.getContext(), engine.getScriptable());
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
||||
@ -13,10 +13,15 @@ import org.mozilla.javascript.ContextFactory;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.commonjs.module.RequireBuilder;
|
||||
import org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -29,6 +34,7 @@ public class RhinoJavaScriptEngine implements ScriptEngine {
|
||||
private static final String LOG_TAG = "RhinoJavaScriptEngine";
|
||||
|
||||
private static int contextCount = 0;
|
||||
private String[] mRequirePath = new String[0];
|
||||
|
||||
private Context mContext;
|
||||
private Scriptable mScriptable;
|
||||
@ -94,9 +100,28 @@ public class RhinoJavaScriptEngine implements ScriptEngine {
|
||||
public void init() {
|
||||
ScriptableObject.putProperty(mScriptable, "__engine_name__", "rhino");
|
||||
ScriptableObject.putProperty(mScriptable, "__engine__", this);
|
||||
mRequirePath = (String[]) getTag("__require_path__");
|
||||
initRequireBuilder(mContext, mScriptable);
|
||||
mContext.evaluateString(mScriptable, mEngineManager.getInitScript().getScript(), "<init>", 1, null);
|
||||
}
|
||||
|
||||
public void setRequirePath(String... requirePath) {
|
||||
setTag("__require_path__", requirePath);
|
||||
}
|
||||
|
||||
void initRequireBuilder(Context context, Scriptable scope) {
|
||||
List<URI> list = new ArrayList<>();
|
||||
for (String path : mRequirePath) {
|
||||
list.add(new File(path).toURI());
|
||||
}
|
||||
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(getEngineManager().getContext(), list);
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
|
||||
.setSandboxed(false)
|
||||
.createRequire(context, scope)
|
||||
.install(scope);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -31,7 +32,6 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
|
||||
private String[] mFunctions;
|
||||
|
||||
private String mRequirePath = "";
|
||||
private ScriptSource mCustomInitScript;
|
||||
private ScriptSource mInitScript;
|
||||
|
||||
@ -41,7 +41,6 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
|
||||
protected RhinoJavaScriptEngine createEngineInner() {
|
||||
RhinoJavaScriptEngine engine = new RhinoJavaScriptEngine(this);
|
||||
initRequireBuilder(engine.getContext(), engine.getScriptable());
|
||||
return engine;
|
||||
}
|
||||
|
||||
@ -77,20 +76,6 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
return mInitScript;
|
||||
}
|
||||
|
||||
public void setRequirePath(String requirePath) {
|
||||
mRequirePath = requirePath;
|
||||
}
|
||||
|
||||
void initRequireBuilder(Context context, Scriptable scope) {
|
||||
List<URI> list = Collections.singletonList(new File(mRequirePath).toURI());
|
||||
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(getContext(), list);
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
|
||||
.setSandboxed(false)
|
||||
.createRequire(context, scope)
|
||||
.install(scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGlobalFunctions() {
|
||||
if (mFunctions == null)
|
||||
@ -114,36 +99,5 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
}
|
||||
|
||||
|
||||
private static class AssetAndUrlModuleSourceProvider extends UrlModuleSourceProvider {
|
||||
|
||||
private static final String MODULES_PATH = "modules";
|
||||
private android.content.Context mContext;
|
||||
private List<String> mModules;
|
||||
private final URI mBaseURI = URI.create("file:///android_asset/modules");
|
||||
|
||||
public AssetAndUrlModuleSourceProvider(android.content.Context context, List<URI> list) {
|
||||
super(list, null);
|
||||
mContext = context;
|
||||
try {
|
||||
mModules = Arrays.asList(mContext.getAssets().list(MODULES_PATH));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ModuleSource loadFromPrivilegedLocations(String moduleId, Object validator) throws IOException, URISyntaxException {
|
||||
String moduleIdWithExtension = moduleId;
|
||||
if (!moduleIdWithExtension.endsWith(".js")) {
|
||||
moduleIdWithExtension += ".js";
|
||||
}
|
||||
if (mModules.contains(moduleIdWithExtension)) {
|
||||
return new ModuleSource(new InputStreamReader(mContext.getAssets().open(MODULES_PATH + "/" + moduleIdWithExtension)), null,
|
||||
URI.create(moduleIdWithExtension), mBaseURI, validator);
|
||||
}
|
||||
return super.loadFromPrivilegedLocations(moduleId, validator);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class ExecutionConfig implements Serializable {
|
||||
|
||||
private String[] mRequirePath = new String[0];
|
||||
private static final ExecutionConfig DEFAULT = new ExecutionConfig();
|
||||
|
||||
public static ExecutionConfig getDefault() {
|
||||
@ -20,4 +21,12 @@ public class ExecutionConfig implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExecutionConfig requirePath(String... requirePath) {
|
||||
mRequirePath = requirePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getRequirePath() {
|
||||
return mRequirePath;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.stardust.autojs.execution;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
@ -53,6 +54,7 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
runtime.ensureAccessibilityServiceEnabled();
|
||||
}
|
||||
engine.put("__runtime__", runtime);
|
||||
engine.setTag("__require_path__", getConfig().getRequirePath());
|
||||
engine.init();
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,7 @@ public class ScriptExecuteActivity extends Activity {
|
||||
private void prepare() {
|
||||
mScriptEngine.put("activity", this);
|
||||
mScriptEngine.put("__runtime__", execution.getRuntime());
|
||||
mScriptEngine.setTag("__require_path__", execution.getConfig().getRequirePath());
|
||||
mScriptEngine.init();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user