Compare commits

...

1 Commits

Author SHA1 Message Date
Nathan Kerr
6000adfa15 Add ability to re-enable webview optimizations 2020-08-14 10:34:19 -07:00
2 changed files with 36 additions and 0 deletions

View File

@ -101,6 +101,9 @@ public class BackgroundModeExt extends CordovaPlugin {
case "webview":
disableWebViewOptimizations();
break;
case "enableWebview":
enableWebViewOptimizations();
break;
case "appstart":
openAppStart(args.opt(0));
break;
@ -196,6 +199,31 @@ public class BackgroundModeExt extends CordovaPlugin {
thread.start();
}
private void enableWebViewOptimizations() {
Thread thread = new Thread(){
public void run() {
try {
Thread.sleep(1000);
getApp().runOnUiThread(() -> {
View view = webView.getView();
try {
Class.forName("org.crosswalk.engine.XWalkCordovaView")
.getMethod("onHide")
.invoke(view);
} catch (Exception e){
view.dispatchWindowVisibilityChanged(View.GONE);
}
});
} catch (InterruptedException e) {
// do nothing
}
}
};
thread.start();
}
/**
* Disables battery optimizations for the app.
* Requires permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to function.

View File

@ -164,6 +164,14 @@ exports.disableWebViewOptimizations = function()
}
};
exports.enableWebViewOptimizations = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'enableWebview', []);
}
};
/**
* Disables battery optimazation mode for the app.
*