Add other types of JSEngine
This commit is contained in:
parent
c7252613a2
commit
ce892a31bf
@ -46,7 +46,7 @@ task clean(type: Delete) {
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('version.properties').newDataInputStream())
|
||||
ext {
|
||||
UseWebViewOnly = true
|
||||
UseWebViewOnly = false
|
||||
Version = properties.version
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@ import java.util.concurrent.Executors;
|
||||
import pub.doric.async.AsyncCall;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.engine.DoricJSEngine;
|
||||
import pub.doric.engine.DoricWebShellJSEngine;
|
||||
import pub.doric.engine.DoricWebViewJSEngine;
|
||||
import pub.doric.performance.DoricPerformanceProfile;
|
||||
import pub.doric.utils.DoricConstant;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
@ -38,13 +40,19 @@ import pub.doric.utils.ThreadMode;
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class DoricNativeDriver implements IDoricDriver {
|
||||
private final DoricJSEngine doricJSEngine;
|
||||
public enum JSEngineType {
|
||||
JSE,
|
||||
WebView,
|
||||
WebShell
|
||||
}
|
||||
|
||||
private DoricJSEngine doricJSEngine;
|
||||
private Handler mJSHandler;
|
||||
private final ExecutorService mBridgeExecutor;
|
||||
private final Handler mUIHandler;
|
||||
private final Handler mJSHandler;
|
||||
|
||||
public DoricNativeDriver() {
|
||||
doricJSEngine = new DoricJSEngine();
|
||||
doricJSEngine = new DoricWebShellJSEngine();
|
||||
mBridgeExecutor = Executors.newCachedThreadPool();
|
||||
mUIHandler = new Handler(Looper.getMainLooper());
|
||||
mJSHandler = doricJSEngine.getJSHandler();
|
||||
@ -194,4 +202,30 @@ public class DoricNativeDriver implements IDoricDriver {
|
||||
public DoricRegistry getRegistry() {
|
||||
return doricJSEngine.getRegistry();
|
||||
}
|
||||
|
||||
public JSEngineType getJSEngineType() {
|
||||
if (doricJSEngine instanceof DoricWebShellJSEngine) {
|
||||
return JSEngineType.WebShell;
|
||||
}
|
||||
if (doricJSEngine instanceof DoricWebViewJSEngine) {
|
||||
return JSEngineType.WebView;
|
||||
}
|
||||
return JSEngineType.JSE;
|
||||
}
|
||||
|
||||
public void switchJSEngine(JSEngineType type) {
|
||||
if (getJSEngineType() == type) {
|
||||
return;
|
||||
}
|
||||
doricJSEngine.teardown();
|
||||
mJSHandler.removeCallbacksAndMessages(null);
|
||||
if (type == JSEngineType.WebView) {
|
||||
doricJSEngine = new DoricWebViewJSEngine();
|
||||
} else if (type == JSEngineType.WebShell) {
|
||||
doricJSEngine = new DoricWebShellJSEngine();
|
||||
} else {
|
||||
doricJSEngine = new DoricJSEngine();
|
||||
}
|
||||
mJSHandler = doricJSEngine.getJSHandler();
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,13 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
try {
|
||||
mDoricJSE = new DoricNativeJSExecutor();
|
||||
} catch (Throwable e) {
|
||||
//In case some unexpected errors happened
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||
loadBuiltinJS("doric-web.js");
|
||||
} else {
|
||||
mDoricJSE = new DoricWebShellJSExecutor(Doric.application());
|
||||
//loadBuiltinJS("doric-web.js");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.engine;
|
||||
|
||||
import pub.doric.Doric;
|
||||
|
||||
/**
|
||||
* @Description: This uses DoricWebShellJSExecutor directly
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2021/11/9
|
||||
*/
|
||||
public class DoricWebShellJSEngine extends DoricJSEngine {
|
||||
@Override
|
||||
protected void initJSEngine() {
|
||||
mDoricJSE = new DoricWebShellJSExecutor(Doric.application());
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.engine;
|
||||
|
||||
import pub.doric.Doric;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
/**
|
||||
* @Description: This uses DoricWebViewJSExecutor directly
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2021/11/9
|
||||
*/
|
||||
public class DoricWebViewJSEngine extends DoricJSEngine {
|
||||
@Override
|
||||
protected void initJSEngine() {
|
||||
mDoricJSE = new DoricWebViewJSExecutor(Doric.application());
|
||||
String assetName = "doric-web.js";
|
||||
String script = DoricUtils.readAssetFile(assetName);
|
||||
mDoricJSE.loadJS(script, "Assets://" + assetName);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user