mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Improve background webview reliability
This commit is contained in:
committed by
Arjan Schrijver
parent
aa1e2f6b3a
commit
fc23dcaaaf
+8
@@ -500,6 +500,14 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
if (requestCode == CHILD_ACTIVITY_WATCHFACE_EDITOR) {
|
if (requestCode == CHILD_ACTIVITY_WATCHFACE_EDITOR) {
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
|
if ((mGBDevice.getType() == DeviceType.PEBBLE) && (((PebbleCoordinator) mGBDevice.getDeviceCoordinator()).isBackgroundJsEnabled(mGBDevice))) {
|
||||||
|
Intent startIntent = new Intent(getContext(), ExternalPebbleJSActivity.class);
|
||||||
|
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
|
||||||
|
startIntent.putExtra(ExternalPebbleJSActivity.START_BG_WEBVIEW, true);
|
||||||
|
getContext().startActivity(startIntent);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendOrderToDevice(String concatFilename) {
|
protected void sendOrderToDevice(String concatFilename) {
|
||||||
|
|||||||
+1
-1
@@ -549,7 +549,7 @@ class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
if (mPebbleProtocol.hasAppMessageHandler(appMgmt.uuid)) {
|
if (mPebbleProtocol.hasAppMessageHandler(appMgmt.uuid)) {
|
||||||
WebViewSingleton.getInstance().stopJavascriptInterface();
|
WebViewSingleton.getInstance().stopJavascriptInterface();
|
||||||
} else {
|
} else {
|
||||||
WebViewSingleton.getInstance().runJavascriptInterface(gbDevice, appMgmt.uuid);
|
WebViewSingleton.getInstance().runJavascriptInterface(getContext(), gbDevice, appMgmt.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.MutableContextWrapper;
|
import android.content.MutableContextWrapper;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -33,9 +32,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.JSInterface;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.webview.GBChromeClient;
|
import nodomain.freeyourgadget.gadgetbridge.webview.GBChromeClient;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.webview.GBWebClient;
|
import nodomain.freeyourgadget.gadgetbridge.webview.GBWebClient;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.JSInterface;
|
|
||||||
|
|
||||||
public class WebViewSingleton {
|
public class WebViewSingleton {
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ public class WebViewSingleton {
|
|||||||
private WebViewSingleton() {
|
private WebViewSingleton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void ensureCreated(Activity context) {
|
public static synchronized void ensureCreated(Context context) {
|
||||||
if (instance.webView == null) {
|
if (instance.webView == null) {
|
||||||
instance.contextWrapper = new MutableContextWrapper(context);
|
instance.contextWrapper = new MutableContextWrapper(context);
|
||||||
instance.mainLooper = context.getMainLooper();
|
instance.mainLooper = context.getMainLooper();
|
||||||
@@ -58,6 +57,7 @@ public class WebViewSingleton {
|
|||||||
WebView.setWebContentsDebuggingEnabled(true);
|
WebView.setWebContentsDebuggingEnabled(true);
|
||||||
instance.webView.setWillNotDraw(true);
|
instance.webView.setWillNotDraw(true);
|
||||||
instance.webView.clearCache(true);
|
instance.webView.clearCache(true);
|
||||||
|
instance.webView.resumeTimers();
|
||||||
instance.webView.setWebViewClient(new GBWebClient());
|
instance.webView.setWebViewClient(new GBWebClient());
|
||||||
instance.webView.setWebChromeClient(new GBChromeClient());
|
instance.webView.setWebChromeClient(new GBChromeClient());
|
||||||
WebSettings webSettings = instance.webView.getSettings();
|
WebSettings webSettings = instance.webView.getSettings();
|
||||||
@@ -101,12 +101,9 @@ public class WebViewSingleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runJavascriptInterface(@NonNull Activity context, @NonNull GBDevice device, @NonNull UUID uuid) {
|
public void runJavascriptInterface(@NonNull Context context, @NonNull GBDevice device, @NonNull UUID uuid) {
|
||||||
ensureCreated(context);
|
ensureCreated(context);
|
||||||
runJavascriptInterface(device, uuid);
|
InternetHelperSingleton.INSTANCE.ensureInternetHelperBound();
|
||||||
}
|
|
||||||
|
|
||||||
public void runJavascriptInterface(@NonNull GBDevice device, @NonNull UUID uuid) {
|
|
||||||
if (uuid.equals(currentRunningUUID)) {
|
if (uuid.equals(currentRunningUUID)) {
|
||||||
LOG.debug("WEBVIEW uuid not changed keeping the old context");
|
LOG.debug("WEBVIEW uuid not changed keeping the old context");
|
||||||
} else {
|
} else {
|
||||||
@@ -119,7 +116,6 @@ public class WebViewSingleton {
|
|||||||
webView.addJavascriptInterface(jsInterface, "GBjs");
|
webView.addJavascriptInterface(jsInterface, "GBjs");
|
||||||
webView.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
|
webView.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
|
||||||
});
|
});
|
||||||
InternetHelperSingleton.INSTANCE.ensureInternetHelperBound();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user