feat: 移除 H5 URL 中的品牌参数和缓存参数;更新测试用例以反映更改
This commit is contained in:
@@ -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<String, String>.from(uri.queryParameters)
|
||||
..['flutter_shell'] = '1'
|
||||
..['shell_cache_bust'] = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final queryParameters = Map<String, String>.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);
|
||||
|
||||
@@ -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<H5ShellPage> with WidgetsBindingObserver {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _prepareWebViewForFreshLoad() async {
|
||||
await _configureAndroidNoCache();
|
||||
try {
|
||||
await _controller.clearCache();
|
||||
} catch (_) {
|
||||
// Some WebView implementations can reject cache operations during setup.
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _configureAndroidNoCache() async {
|
||||
final platformController = _controller.platform;
|
||||
if (platformController is! AndroidWebViewController) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _shellWebViewCacheChannel.invokeMethod<void>(
|
||||
'configureNoCache',
|
||||
{'webViewId': platformController.webViewIdentifier},
|
||||
);
|
||||
} catch (_) {
|
||||
// Older shells may not expose the native cache channel yet.
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncShellBranding() {
|
||||
final payload = jsonEncode({
|
||||
'name': widget.shellBranding.appName,
|
||||
@@ -561,12 +529,7 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
||||
});
|
||||
}
|
||||
|
||||
await _prepareWebViewForFreshLoad();
|
||||
|
||||
await _controller.loadRequest(
|
||||
Uri.parse(url),
|
||||
headers: _noCacheHeaders,
|
||||
);
|
||||
await _controller.loadRequest(Uri.parse(url));
|
||||
}
|
||||
|
||||
Future<NavigationDecision> _handleNavigationRequest(
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user