feat: 添加 JavaScript 通道以处理来自 WebView 的消息
This commit is contained in:
@@ -169,6 +169,10 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
||||
},
|
||||
)
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..addJavaScriptChannel(
|
||||
'OpenIMFlutterShell',
|
||||
onMessageReceived: _handleShellBridgeMessage,
|
||||
)
|
||||
..setBackgroundColor(_shellBackground)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
@@ -234,6 +238,22 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
||||
return controller;
|
||||
}
|
||||
|
||||
void _handleShellBridgeMessage(JavaScriptMessage message) {
|
||||
String? type;
|
||||
try {
|
||||
final decoded = jsonDecode(message.message);
|
||||
if (decoded is Map<String, dynamic>) {
|
||||
type = decoded['type'] as String?;
|
||||
}
|
||||
} catch (_) {
|
||||
type = message.message;
|
||||
}
|
||||
|
||||
if (type == 'openAppSettings') {
|
||||
unawaited(openAppSettings());
|
||||
}
|
||||
}
|
||||
|
||||
void _showTransientShellCover() {
|
||||
_shellCoverTimer?.cancel();
|
||||
if (mounted) {
|
||||
|
||||
Reference in New Issue
Block a user