mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-05 16:15:43 +00:00
Wait for Android native views to close before clearing profiles
This commit is contained in:
1 parent
d642ae5018
commit
d58135db9f
2 files changed
+27
-1
No files matched your search
+25
-1
@@ -15,7 +15,11 @@ import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
// Internal host bridge: profile creation and proxy completion precede navigation.
|
||||
final class GopeedProfiles {
|
||||
public final class GopeedProfiles {
|
||||
private static final java.util.Map<android.webkit.WebView, String> views = new java.util.IdentityHashMap<>();
|
||||
|
||||
public static void viewCreated(android.webkit.WebView view, String id) { views.put(view, id); }
|
||||
public static void viewDestroyed(android.webkit.WebView view) { views.remove(view); }
|
||||
private static SharedPreferences preferences;
|
||||
private static final Set<String> cleared = new HashSet<>();
|
||||
private static final String DELETIONS = "pendingDeletions";
|
||||
@@ -47,6 +51,26 @@ final class GopeedProfiles {
|
||||
}
|
||||
|
||||
static void remove(MethodCall call, MethodChannel.Result result) {
|
||||
waitForViews(call, result, 100);
|
||||
}
|
||||
|
||||
private static void waitForViews(MethodCall call, MethodChannel.Result result, int attempts) {
|
||||
String id = call.argument("gopeedProfileId");
|
||||
if (views.containsValue(id)) {
|
||||
if (attempts <= 0) {
|
||||
result.error("PROFILE_REMOVE_FAILED", "WebView pages have not finished closing", null);
|
||||
return;
|
||||
}
|
||||
// The plugin destroys WebViews asynchronously after about:blank loads.
|
||||
// Wait for actual native destruction, not just Dart widget disposal.
|
||||
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(
|
||||
() -> waitForViews(call, result, attempts - 1), 100);
|
||||
return;
|
||||
}
|
||||
removeData(call, result);
|
||||
}
|
||||
|
||||
private static void removeData(MethodCall call, MethodChannel.Result result) {
|
||||
if (!WebViewFeature.isFeatureSupported(WebViewFeature.MULTI_PROFILE)) {
|
||||
result.error("UNAVAILABLE", "Android WebView profile removal is unavailable", null);
|
||||
return;
|
||||
|
||||
+2
@@ -195,6 +195,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
||||
super(context, containerView, customSettings.useHybridComposition);
|
||||
if (!customSettings.gopeedProfileId.isEmpty()) {
|
||||
WebViewCompat.setProfile(this, customSettings.gopeedProfileId);
|
||||
com.pichillilorenzo.flutter_inappwebview_android.GopeedProfiles.viewCreated(this, customSettings.gopeedProfileId);
|
||||
}
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
@@ -2107,5 +2108,6 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
com.pichillilorenzo.flutter_inappwebview_android.GopeedProfiles.viewDestroyed(this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user