From 1e19f5f5f8b4b7e012f91955579488f1203a3e47 Mon Sep 17 00:00:00 2001 From: Booker Date: Tue, 26 May 2026 20:20:01 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=20H5=20URL=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=93=81=E7=89=8C=E5=8F=82=E6=95=B0=E5=92=8C?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=8F=82=E6=95=B0=EF=BC=9B=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=BB=A5=E5=8F=8D=E6=98=A0?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/app_config.dart | 8 ++++---- lib/main.dart | 39 +------------------------------------- test/widget_test.dart | 12 ++++++------ 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 74358dd..a7ffad8 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -21,14 +21,14 @@ class AppConfig { final host = environmentHosts.isNotEmpty ? environmentHosts.first : 'h5-im.imharry.work'; - return withFreshShellParams(_normalizeHomeUrl(host)); + return _normalizeHomeUrl(host); } static String withFreshShellParams(String url) { final uri = Uri.parse(url); - final queryParameters = Map.from(uri.queryParameters) - ..['flutter_shell'] = '1' - ..['shell_cache_bust'] = DateTime.now().millisecondsSinceEpoch.toString(); + final queryParameters = Map.from(uri.queryParameters); + queryParameters.remove('flutter_shell'); + queryParameters.remove('shell_cache_bust'); queryParameters.remove('shell_app_name'); queryParameters.remove('shell_app_logo'); final fragmentParameters = Uri.splitQueryString(uri.fragment); diff --git a/lib/main.dart b/lib/main.dart index a77e474..183290d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,15 +15,8 @@ const _shellBackground = Color(0xFFF8FBFF); const _shellAccent = Color(0xFF0089FF); const _shellSubText = Color(0xFF8E9AB0); const _resumeCoverDuration = Duration(milliseconds: 700); -const _noCacheHeaders = { - 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', - 'Pragma': 'no-cache', - 'Expires': '0', -}; const _shellBrandingChannel = MethodChannel('io.openim.flutter.im_webview_app/shell_branding'); -const _shellWebViewCacheChannel = - MethodChannel('io.openim.flutter.im_webview_app/webview_cache'); const _inspectH5SnapshotScript = r''' (() => { const toAbsoluteUrl = (value) => { @@ -468,31 +461,6 @@ class _H5ShellPageState extends State with WidgetsBindingObserver { } } - Future _prepareWebViewForFreshLoad() async { - await _configureAndroidNoCache(); - try { - await _controller.clearCache(); - } catch (_) { - // Some WebView implementations can reject cache operations during setup. - } - } - - Future _configureAndroidNoCache() async { - final platformController = _controller.platform; - if (platformController is! AndroidWebViewController) { - return; - } - - try { - await _shellWebViewCacheChannel.invokeMethod( - 'configureNoCache', - {'webViewId': platformController.webViewIdentifier}, - ); - } catch (_) { - // Older shells may not expose the native cache channel yet. - } - } - Future _syncShellBranding() { final payload = jsonEncode({ 'name': widget.shellBranding.appName, @@ -561,12 +529,7 @@ class _H5ShellPageState extends State with WidgetsBindingObserver { }); } - await _prepareWebViewForFreshLoad(); - - await _controller.loadRequest( - Uri.parse(url), - headers: _noCacheHeaders, - ); + await _controller.loadRequest(Uri.parse(url)); } Future _handleNavigationRequest( diff --git a/test/widget_test.dart b/test/widget_test.dart index f84afba..3cfbcd3 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -11,7 +11,7 @@ void main() { ); }); - test('loads the configured H5 root URL with shell launch params', () { + test('loads the configured H5 root URL without shell URL params', () { const logo = 'data:image/png;base64,abc+/='; final uri = Uri.parse( @@ -21,10 +21,10 @@ void main() { expect(uri.scheme, 'https'); expect(uri.host, 'h5-im.imharry.work'); expect(uri.path, '/'); - expect(uri.queryParameters['flutter_shell'], '1'); + expect(uri.queryParameters.containsKey('flutter_shell'), isFalse); expect(uri.queryParameters.containsKey('shell_app_name'), isFalse); expect(uri.queryParameters.containsKey('shell_app_logo'), isFalse); - expect(uri.queryParameters['shell_cache_bust'], isNotEmpty); + expect(uri.queryParameters.containsKey('shell_cache_bust'), isFalse); expect(uri.toString(), isNot(contains('%25'))); expect(Uri.splitQueryString(uri.fragment).containsKey('shell_app_logo'), isFalse); @@ -34,16 +34,16 @@ void main() { final uri = Uri.parse( AppConfig.withFreshShellParams( 'https://h5-im.imharry.work/login?from=runtime&shell_app_name=Old' - '#shell_app_logo=old', + '&flutter_shell=1&shell_cache_bust=1#shell_app_logo=old', ), ); expect(uri.path, '/login'); expect(uri.queryParameters['from'], 'runtime'); - expect(uri.queryParameters['flutter_shell'], '1'); + expect(uri.queryParameters.containsKey('flutter_shell'), isFalse); expect(uri.queryParameters.containsKey('shell_app_name'), isFalse); expect(uri.queryParameters.containsKey('shell_app_logo'), isFalse); - expect(uri.queryParameters['shell_cache_bust'], isNotEmpty); + expect(uri.queryParameters.containsKey('shell_cache_bust'), isFalse); expect(Uri.splitQueryString(uri.fragment).containsKey('shell_app_logo'), isFalse); });