chore: remove temporary H5 cache diagnostics
This commit is contained in:
143
lib/main.dart
143
lib/main.dart
@@ -11,48 +11,8 @@ import 'config/app_config.dart';
|
||||
const _shellBackground = Color(0xFFF8FBFF);
|
||||
const _shellAccent = Color(0xFF0089FF);
|
||||
const _shellSubText = Color(0xFF8E9AB0);
|
||||
const _showH5DebugOverlay = bool.fromEnvironment(
|
||||
'H5_SHELL_DEBUG',
|
||||
defaultValue: true,
|
||||
);
|
||||
const _shellBrandingChannel =
|
||||
MethodChannel('io.openim.flutter.im_webview_app/shell_branding');
|
||||
const _h5MountedCheckScript = r'''
|
||||
(() => document.body?.classList.contains('app-mounted') === true)();
|
||||
''';
|
||||
const _h5SnapshotScript = r'''
|
||||
(() => {
|
||||
const shrinkAssetUrl = (value) => {
|
||||
try {
|
||||
const absolute = new URL(value, window.location.href).href;
|
||||
const match = absolute.match(/\/assets\/[^?#]+/);
|
||||
return match ? match[0] : absolute;
|
||||
} catch (_) {
|
||||
return value || '';
|
||||
}
|
||||
};
|
||||
|
||||
const scripts = Array.from(document.scripts)
|
||||
.map((script) => script.src)
|
||||
.filter(Boolean)
|
||||
.map(shrinkAssetUrl)
|
||||
.filter((src) => src.includes('/assets/'));
|
||||
const bodyText = (document.body?.innerText || '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.slice(0, 180);
|
||||
let shellBrand = '';
|
||||
try {
|
||||
shellBrand = window.sessionStorage.getItem('OPENIM_FLUTTER_SHELL_BRAND') || '';
|
||||
} catch (_) {}
|
||||
|
||||
return JSON.stringify({
|
||||
href: window.location.href,
|
||||
scripts,
|
||||
bodyText,
|
||||
shellBrand,
|
||||
});
|
||||
})();
|
||||
''';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -137,7 +97,6 @@ class _H5ShellPageState extends State<H5ShellPage> {
|
||||
|
||||
int _progress = 0;
|
||||
String? _loadError;
|
||||
String _h5DebugText = 'H5 loading...';
|
||||
bool _showShellCover = true;
|
||||
bool _shellBrandingLoaded = false;
|
||||
late ShellBranding _shellBranding;
|
||||
@@ -202,9 +161,7 @@ class _H5ShellPageState extends State<H5ShellPage> {
|
||||
|
||||
Future<void> _handlePageFinished() async {
|
||||
await _loadShellBrandingIfNeeded();
|
||||
await _waitForH5Mounted();
|
||||
await _syncShellBranding();
|
||||
await _updateH5DebugSnapshot();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_progress = 100;
|
||||
@@ -247,58 +204,6 @@ class _H5ShellPageState extends State<H5ShellPage> {
|
||||
return _runJavaScriptSafely(script);
|
||||
}
|
||||
|
||||
Future<void> _waitForH5Mounted() async {
|
||||
for (var index = 0; index < 20; index += 1) {
|
||||
try {
|
||||
final result = await _controller.runJavaScriptReturningResult(
|
||||
_h5MountedCheckScript,
|
||||
);
|
||||
if (result == true || result.toString() == 'true') {
|
||||
return;
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _updateH5DebugSnapshot() async {
|
||||
if (!_showH5DebugOverlay) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final result = await _controller.runJavaScriptReturningResult(
|
||||
_h5SnapshotScript,
|
||||
);
|
||||
final snapshot = _decodeJavaScriptStringResult(result);
|
||||
debugPrint('[H5Shell] snapshot: $snapshot');
|
||||
if (mounted) {
|
||||
setState(() => _h5DebugText = snapshot);
|
||||
}
|
||||
} catch (error) {
|
||||
debugPrint('[H5Shell] snapshot failed: $error');
|
||||
if (mounted) {
|
||||
setState(() => _h5DebugText = 'H5 snapshot failed: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _decodeJavaScriptStringResult(Object? result) {
|
||||
if (result == null) {
|
||||
return '';
|
||||
}
|
||||
if (result is String) {
|
||||
try {
|
||||
final decoded = jsonDecode(result);
|
||||
if (decoded is String) {
|
||||
return decoded;
|
||||
}
|
||||
} catch (_) {}
|
||||
return result;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
Future<void> _loadHome() async {
|
||||
await _loadUrl(_freshHomeUrl());
|
||||
}
|
||||
@@ -314,18 +219,9 @@ class _H5ShellPageState extends State<H5ShellPage> {
|
||||
});
|
||||
}
|
||||
|
||||
await _clearWebViewHttpCache();
|
||||
await _controller.loadRequest(Uri.parse(targetUrl));
|
||||
}
|
||||
|
||||
Future<void> _clearWebViewHttpCache() async {
|
||||
try {
|
||||
await _controller.clearCache();
|
||||
} catch (_) {
|
||||
// Some WebView implementations can reject cache operations before first use.
|
||||
}
|
||||
}
|
||||
|
||||
Future<NavigationDecision> _handleNavigationRequest(
|
||||
NavigationRequest request,
|
||||
) async {
|
||||
@@ -392,15 +288,6 @@ class _H5ShellPageState extends State<H5ShellPage> {
|
||||
message: _loadError!,
|
||||
onRetry: () => unawaited(_loadHome()),
|
||||
),
|
||||
if (_showH5DebugOverlay)
|
||||
Positioned(
|
||||
left: 8,
|
||||
right: 8,
|
||||
bottom: 10,
|
||||
child: IgnorePointer(
|
||||
child: _H5DebugOverlay(text: _h5DebugText),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -450,36 +337,6 @@ class _ErrorPanel extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _H5DebugOverlay extends StatelessWidget {
|
||||
const _H5DebugOverlay({required this.text});
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.72),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
child: Text(
|
||||
text,
|
||||
maxLines: 5,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
height: 1.25,
|
||||
letterSpacing: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ShellFallback extends StatelessWidget {
|
||||
const _ShellFallback();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user