| 
									
										
										
										
											2022-06-19 17:15:37 +01:00
										 |  |  | // ignore_for_file: avoid_web_libraries_in_flutter
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  | import 'dart:convert'; | 
					
						
							| 
									
										
										
										
											2022-01-25 18:13:11 +08:00
										 |  |  | import 'dart:typed_data'; | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  | import 'dart:js'; | 
					
						
							| 
									
										
										
										
											2022-02-05 04:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 18:29:25 +08:00
										 |  |  | import '../common.dart'; | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  | import 'dart:html'; | 
					
						
							|  |  |  | import 'dart:async'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-03 17:19:25 +08:00
										 |  |  | final List<StreamSubscription<MouseEvent>> mouseListeners = []; | 
					
						
							| 
									
										
										
										
											2022-02-05 04:29:10 +08:00
										 |  |  | final List<StreamSubscription<KeyboardEvent>> keyListeners = []; | 
					
						
							| 
									
										
										
										
											2022-01-25 18:13:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 12:48:16 +08:00
										 |  |  | class PlatformFFI { | 
					
						
							|  |  |  |   static String getByName(String name, [String arg = '']) { | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  |     return context.callMethod('getByName', [name, arg]); | 
					
						
							| 
									
										
										
										
											2022-01-25 18:13:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 12:48:16 +08:00
										 |  |  |   static void setByName(String name, [String value = '']) { | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  |     context.callMethod('setByName', [name, value]); | 
					
						
							| 
									
										
										
										
											2022-01-25 18:13:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 12:48:16 +08:00
										 |  |  |   static Future<Null> init() async { | 
					
						
							|  |  |  |     isWeb = true; | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  |     isDesktop = !context.callMethod('isMobile'); | 
					
						
							|  |  |  |     context.callMethod('init'); | 
					
						
							| 
									
										
										
										
											2022-03-24 20:57:30 +08:00
										 |  |  |     version = getByName('version'); | 
					
						
							| 
									
										
										
										
											2022-01-25 18:13:11 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-19 23:45:44 +08:00
										 |  |  |   static void setEventCallback(void Function(Map<String, dynamic>) fun) { | 
					
						
							| 
									
										
										
										
											2022-05-17 19:59:37 +08:00
										 |  |  |     context["onGlobalEvent"] = (String message) { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         Map<String, dynamic> event = json.decode(message); | 
					
						
							|  |  |  |         fun(event); | 
					
						
							|  |  |  |       } catch (e) { | 
					
						
							|  |  |  |         print('json.decode fail(): $e'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-19 23:45:44 +08:00
										 |  |  |   static void setRgbaCallback(void Function(Uint8List) fun) { | 
					
						
							|  |  |  |     context["onRgba"] = (Uint8List? rgba) { | 
					
						
							|  |  |  |       if (rgba != null) { | 
					
						
							|  |  |  |         fun(rgba); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-25 18:25:25 +08:00
										 |  |  |   static void startDesktopWebListener() { | 
					
						
							| 
									
										
										
										
											2022-02-03 17:19:25 +08:00
										 |  |  |     mouseListeners.add( | 
					
						
							|  |  |  |         window.document.onContextMenu.listen((evt) => evt.preventDefault())); | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static void stopDesktopWebListener() { | 
					
						
							| 
									
										
										
										
											2022-02-03 17:19:25 +08:00
										 |  |  |     mouseListeners.forEach((l) { | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  |       l.cancel(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2022-02-03 17:19:25 +08:00
										 |  |  |     mouseListeners.clear(); | 
					
						
							| 
									
										
										
										
											2022-02-05 04:29:10 +08:00
										 |  |  |     keyListeners.forEach((l) { | 
					
						
							|  |  |  |       l.cancel(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     keyListeners.clear(); | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-10 02:07:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   static void setMethodCallHandler(FMethod callback) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-25 18:25:25 +08:00
										 |  |  |   static Future<bool> invokeMethod(String method, [dynamic arguments]) async { | 
					
						
							| 
									
										
										
										
											2022-02-10 02:07:53 +08:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-03 00:53:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final localeName = window.navigator.language; |