/// 약속: 앱의 모든 웹 뷰에 프록시를 거는 곳 ([WebProxy] 가 부른다). /// 입력 = 프록시 주소 ('' = 없앰) · Tor 처럼 localhost 까지 프록시로 보낼지. 출력 없음. 오류 = 기기가 거절하면 그 예외. /// [active] 가 false 인 기기 (Windows - 웹 뷰마다 따로 건다) 에서는 [WebProxy] 가 아무것도 하지 않는다 library; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import '../services/platform_info.dart'; abstract class WebViewProxyTarget { /// 이 기기에서 앱 전체 웹 뷰 프록시를 쓰는지 bool get active; Future set(String url, {required bool removeImplicitRules}); /// 이 기기에 맞는 것 (Android: androidx.webkit ProxyController, 아니면 쓰지 않음) factory WebViewProxyTarget.forPlatform(PlatformInfo platform) => platform.isAndroid ? const AndroidWebViewProxy() : const NoWebViewProxy(); } /// Android: androidx.webkit ProxyController - 앱의 모든 웹 뷰에 한꺼번에 걸린다 class AndroidWebViewProxy implements WebViewProxyTarget { const AndroidWebViewProxy(); @override bool get active => true; @override Future set(String url, {required bool removeImplicitRules}) async { final pc = ProxyController.instance(); if (url.isEmpty) { await pc.clearProxyOverride(); } else { await pc.setProxyOverride( settings: ProxySettings(proxyRules: [ProxyRule(url: url)], removeImplicitRules: removeImplicitRules)); } } } /// 앱 전체 웹 뷰 프록시가 없는 기기 (Windows) class NoWebViewProxy implements WebViewProxyTarget { const NoWebViewProxy(); @override bool get active => false; @override Future set(String url, {required bool removeImplicitRules}) async {} }