Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新构建工具 #639

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 15
java-version: 17
- name: set up kotlin
uses: fwilhe2/setup-kotlin@main
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: checkout
id: check
uses: actions/checkout@v1
- name: set up JDK 15
- name: set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 15
java-version: 17
- name: Build inrt template
run: |
chmod 777 ./gradlew
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
* autojs 能不能商用,取决于你对于附带的 “ **非商业性使用** ” 的理解和其法律效益。
* 反正本产品不会拿autojs 进行商用。

#### 编译相关:
### 编译相关:
环境要求:`jdk`版本17以上

命令说明:在项目根目录下运行命令,如果使用 Windows powerShell < 7.0,请使用包含 ";" 的命令

##### 本地安装调试版本到设备:
Expand Down
1 change: 1 addition & 0 deletions apkbuilder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
)
}
}
namespace = "com.stardust.autojs.apkbuilder"


}
Expand Down
3 changes: 1 addition & 2 deletions apkbuilder/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stardust.autojs.apkbuilder">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import java.util.*
import java.io.File
import java.util.Properties

plugins {
id("com.android.application")
Expand Down Expand Up @@ -166,6 +165,7 @@ android {
)
)
}
namespace = "org.autojs.autoxjs"

}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.autojs.autoxjs">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
1 change: 1 addition & 0 deletions autojs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ android {
res.srcDirs("src/main/res","src/main/res-i18n")
}
}
namespace = "com.stardust.autojs"
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions autojs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
package="com.stardust.autojs">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let HttpUrl = Packages.okhttp3.HttpUrl;
let MediaType = Packages.okhttp3.MediaType;
let Headers = Packages.okhttp3.Headers;
let InterruptedIOException = java.io.InterruptedIOException

const stream = require("stream");
let EventTarget = require("./EventTarget.js");
Expand All @@ -24,6 +25,7 @@
///////XMLHttpRequest对象
let XMLHttpRequest = function () {
this.responseType = 'text';
this.timeout = 0;
setReadonlyAttribute(this, 'upload', {})
setReadonlyAttribute(this, 'readyState', 0);
setReadonlyAttribute(this, 'status', 0);
Expand Down Expand Up @@ -105,12 +107,7 @@
XMLHttpRequest.prototype.send = function (body) {
atl.addTask();
const xhr = this;
const {
url,
method,
ac,
headers,
} = this._requestData
const { url, method, ac, headers, } = this._requestData
const responseType = xhr.responseType;

const builder = new Request.Builder();
Expand All @@ -120,12 +117,20 @@
let reqBody = parserReqBody(xhr, body);

let request = builder.url(url.build()).method(method, reqBody).build();
let call = XMLHttpRequest._okHttpClient.newCall(request);
let client = XMLHttpRequest._okHttpClient;
if (xhr.timeout > 0) {
client = new OkHttpClient.Builder().callTimeout(xhr.timeout, java.util.concurrent.TimeUnit.MILLISECONDS)
.followRedirects(true).build();
}
let call = client.newCall(request);
setReadonlyAttribute(xhr, '_call', call, false);
call.enqueue({
onFailure(call, e) {
xhr._setReadyState(4);
setReadonlyAttribute(xhr, 'statusText', e.message)
if (e instanceof InterruptedIOException) {
xhr.dispatchEvent(new Event('timeout'));
}
xhr.dispatchEvent(new Event('error'))
xhr.dispatchEvent(new Event('loadend'))
atl.removeTask()
Expand Down
15 changes: 7 additions & 8 deletions autojs/src/main/assets/modules/npm/process.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
const {
EventEmitter
} = require("events");
const es = require("event-stream");

const { EventEmitter } = require("events");
// const es = require("event-stream");

const process = new EventEmitter();

//events.on('exit', process.emit.bind(process, 'exit'))

/*
process.stdout = es.map(function(data, callback) {
console.log(data);
return callback(null, data)
})
/*

process.stdout.end = function() {};
process.stdout.destroy = function(){};
*/

process.stderr = es.map(function(data, callback) {
console.error(data);
return callback(null, data)
})

*/
process.nextTick = setImmediate;
process.env = {}
//log(process);
Expand Down
45 changes: 28 additions & 17 deletions autojs/src/main/assets/modules/npm/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,42 @@ importClass(java.io.OutputStream);
importClass(java.io.InputStream);
importClass(java.io.FileOutputStream);
importClass(java.io.FileInputStream);
importClass(java.util.concurrent.CompletableFuture);

const stream = require("stream-browserify");
let mainThread;

function addTask(fn, callback) {
CompletableFuture.runAsync(function() {
function addTask(th, fn, callback) {
th.setImmediate(function () {
try {
const data = fn();
return setImmediate(callback, null, data)
return mainThread.setImmediate(callback, null, data)
} catch (e) {
//console.error(e)
return setImmediate(callback, e)
return mainThread.setImmediate(callback, e)
}
})
}
function createThread() {
return threads.start(() => {
setInterval(() => { }, 1000)
})
}

stream.fromInputStream = function(inp, options) {
stream.fromInputStream = function (inp, options) {
if (!mainThread) mainThread = threads.currentThread();
if (!(inp instanceof InputStream)) throw TypeError('需要InputStream流');
options = options || {};
options.highWaterMark = options.highWaterMark || (1024 * 64);
options.autoDestroy = true;
options.emitClose = true;
options.destroy = function(e, cb) {
options.destroy = function (e, cb) {
this._inp.close();
runtime.loopers.removeAsyncTask(this._task)
this._thread.interrupt();
return cb(e)
}
options.read = function(size) {
addTask(() => {
options.read = function (size) {
addTask(this._thread, () => {
const buffer = Buffer.alloc(size);
const bytes = buffer.getBytes();
const i = this._inp.read(bytes);
Expand All @@ -49,30 +56,33 @@ stream.fromInputStream = function(inp, options) {
}
const readable = new stream.Readable(options)
setReadonlyAttribute(readable, '_inp', inp, false)
setReadonlyAttribute(readable, '_thread', createThread(), false)
setReadonlyAttribute(readable, '_task', runtime.loopers.createAndAddAsyncTask('stream'), false)
return readable;
}

stream.fromOutputStream = function(out, options) {
stream.fromOutputStream = function (out, options) {
if (!mainThread) mainThread = threads.currentThread();
if (!(out instanceof OutputStream)) throw TypeError('需要OutputStream流');
options = options || {};
options.highWaterMark = options.highWaterMark || (1024 * 64);
options.autoDestroy = true;
options.emitClose = true;
options.destroy = function(e, cb) {
options.destroy = function (e, cb) {
this._out.close();
runtime.loopers.removeAsyncTask(this._task)
this._thread.interrupt();
return cb(e)
}
options.final = function(callback) {
addTask(() => {
options.final = function (callback) {
addTask(this._thread, () => {
this._out.flush();
}, (err) => {
callback();
})
}
options.write = function(chunk, encoding, callback) {
addTask(() => {
options.write = function (chunk, encoding, callback) {
addTask(this._thread, () => {
const buffer = (chunk instanceof Buffer) ? chunk : Buffer.from(chunk, encoding);
const bytes = buffer.getBytes()
this._out.write(bytes, 0, buffer.length);
Expand All @@ -83,16 +93,17 @@ stream.fromOutputStream = function(out, options) {
}
const writable = new stream.Writable(options)
setReadonlyAttribute(writable, '_out', out, false);
setReadonlyAttribute(writable, '_thread', createThread(), false)
setReadonlyAttribute(writable, '_task', runtime.loopers.createAndAddAsyncTask('stream'), false)
return writable;
}
stream.createFileReadStream = function(path, bufferSize) {
stream.createFileReadStream = function (path, bufferSize) {
return stream.fromInputStream(new FileInputStream(
files.path(path)), {
highWaterMark: bufferSize || (256 * 1024)
})
}
stream.createFileWriteStream = function(path, bufferSize) {
stream.createFileWriteStream = function (path, bufferSize) {
return stream.fromOutputStream(new FileOutputStream(
files.path(path)), {
highWaterMark: bufferSize || (256 * 1024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class Loopers(val runtime: ScriptRuntime) {

@Deprecated("使用AsyncTask代替")
fun waitWhenIdle(b: Boolean) {
waitWhenIdle = b
(Thread.currentThread() as? TimerThread)?.let {
it.loopers?.createAndAddAsyncTask("events")
}?: createAndAddAsyncTask("events")
}

fun recycle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.stardust.autojs.core.web.JsBridge

open class JsWebView : WebView {
//val events = EventEmitter()

@RequiresApi(Build.VERSION_CODES.M)
val jsBridge = JsBridge(this)

init {
Expand All @@ -21,7 +21,7 @@ open class JsWebView : WebView {
settings.javaScriptCanOpenWindowsAutomatically = true
settings.domStorageEnabled = true
settings.displayZoomControls = false
webViewClient = JsBridge.SuperWebViewClient()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) webViewClient = JsBridge.SuperWebViewClient()
}

constructor(context: Context) : super(context)
Expand All @@ -32,18 +32,7 @@ open class JsWebView : WebView {
defStyleAttr
)
@RequiresApi(Build.VERSION_CODES.M)
fun injectionJsBridge() {
val context = this.context
val js: String = try {
val inputStream = context.assets.open(JsBridge.sdkPath)
val available = inputStream.available()
val byteArray = ByteArray(available)
inputStream.read(byteArray)
inputStream.close()
String(byteArray)
} catch (e: Exception) {
""
}
jsBridge.evaluateJavascript(js);
fun injectionJsBridge(){
JsBridge.injectionJsBridge(this)
}
}
Loading
Loading