2024-04-02 11:02:06 +08:00
|
|
|
|
|
|
|
|
import 'dart:ffi';
|
|
|
|
|
|
2024-04-03 14:36:36 +08:00
|
|
|
import 'package:web_synchronization_tool/windows/socket_tool.dart';
|
2024-04-02 11:02:06 +08:00
|
|
|
import 'package:web_synchronization_tool/windows/windowsJs.dart';
|
|
|
|
|
import 'package:webview_windows/webview_windows.dart';
|
|
|
|
|
|
|
|
|
|
class SynchronizationWebTool{
|
|
|
|
|
|
2024-04-02 20:29:52 +08:00
|
|
|
// 私有构造函数
|
|
|
|
|
SynchronizationWebTool._();
|
|
|
|
|
// 私有静态变量,保存类的唯一实例
|
|
|
|
|
static SynchronizationWebTool? _instance;
|
|
|
|
|
|
|
|
|
|
// 公开的静态方法,返回类的唯一实例
|
|
|
|
|
static SynchronizationWebTool getInstance() {
|
|
|
|
|
_instance ??= SynchronizationWebTool._();
|
|
|
|
|
return _instance!;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 11:02:06 +08:00
|
|
|
/// 受控
|
2024-04-02 20:29:52 +08:00
|
|
|
List<WebviewController> _childControllers = [];
|
|
|
|
|
|
2024-04-03 12:54:07 +08:00
|
|
|
/// 设置控制器时 注入js
|
2024-04-02 20:29:52 +08:00
|
|
|
setChildController(List<WebviewController> childControllers){
|
|
|
|
|
|
2024-04-07 16:05:10 +08:00
|
|
|
// for (var controller in childControllers) {
|
|
|
|
|
// controller.addScriptToExecuteOnDocumentCreated(WindowsJs.clickEventJs);
|
|
|
|
|
// // controller.addScriptToExecuteOnDocumentCreated(WindowsJs.onloadZoom(90));
|
|
|
|
|
// }
|
2024-04-02 20:29:52 +08:00
|
|
|
|
2024-04-04 14:27:52 +08:00
|
|
|
_childControllers = childControllers;
|
2024-04-02 20:29:52 +08:00
|
|
|
|
2024-04-03 10:37:41 +08:00
|
|
|
// 滚动监听
|
2024-04-03 12:54:07 +08:00
|
|
|
// mainController.addScriptToExecuteOnDocumentCreated(WindowsJs.scrollEventJs);
|
2024-04-03 10:37:41 +08:00
|
|
|
|
2024-04-02 20:29:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<WebviewController> get childController{
|
|
|
|
|
return _childControllers;
|
|
|
|
|
}
|
2024-04-02 11:02:06 +08:00
|
|
|
|
|
|
|
|
/// 点击同步
|
2024-04-03 18:27:31 +08:00
|
|
|
clickSynchronization(int x,int y){
|
2024-04-02 11:02:06 +08:00
|
|
|
for (var controller in childController) {
|
|
|
|
|
controller.executeScript(WindowsJs.clickJs(x, y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 14:36:36 +08:00
|
|
|
|
2024-04-03 10:37:41 +08:00
|
|
|
/// 滚动同步
|
|
|
|
|
scrollSynchronization(int y){
|
|
|
|
|
for (var controller in childController) {
|
|
|
|
|
controller.executeScript(WindowsJs.scrollTo(y) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 11:02:06 +08:00
|
|
|
/// 输入
|
2024-04-03 14:36:36 +08:00
|
|
|
input(List<int> values){
|
|
|
|
|
for (int i =0;i<childController.length;i++){
|
|
|
|
|
WebviewController controller = childController[i];
|
|
|
|
|
controller.executeScript(WindowsJs.inputJs(values[i]));
|
2024-04-02 11:02:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|