Skip to content

Commit

Permalink
RedirectWebView の修正 (#183)
Browse files Browse the repository at this point in the history
Co-authored-by: Syuugo <[email protected]>
  • Loading branch information
areteruhiro and s1204IT authored Oct 8, 2024
1 parent 5d8b75c commit fd52486
Showing 1 changed file with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;
Expand All @@ -24,24 +26,47 @@ public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPa
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Activity activity = (Activity) param.thisObject;
int webViewResId = activity.getResources().getIdentifier("iab_webview", "id", activity.getPackageName());
WebView webView = (WebView) activity.findViewById(webViewResId);
webView.setVisibility(View.GONE);
webView.stopLoading();
Uri uri = Uri.parse(webView.getUrl());
if (limeOptions.openInBrowser.checked) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
activity.startActivity(intent);
} else {
CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.build();
tabsIntent.launchUrl(activity, uri);
View rootView = activity.getWindow().getDecorView().getRootView();
WebView webView = findWebView(rootView);

if (webView != null) {
webView.setVisibility(View.GONE);
webView.stopLoading();

Uri uri = Uri.parse(webView.getUrl());

if (limeOptions.openInBrowser.checked) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
} else {
CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.build();
tabsIntent.launchUrl(activity, uri);
}

activity.finish();

}
activity.finish();
}
}
);
}

private WebView findWebView(View view) {
if (view instanceof WebView) {
return (WebView) view;
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int i = 0; i < group.getChildCount(); i++) {
WebView result = findWebView(group.getChildAt(i));
if (result != null) {
return result;
}
}
}
return null;
}
}

0 comments on commit fd52486

Please sign in to comment.