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); });