部分修改 备份
This commit is contained in:
parent
bda8bb5570
commit
b6a1e84658
|
|
@ -1,19 +1,50 @@
|
|||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:web_synchronization_tool/main_page.dart';
|
||||
import 'package:web_synchronization_tool/windows/windows_main_page.dart';
|
||||
import 'package:webview_windows/webview_windows.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
// await InAppWebViewController.setWebContentsDebuggingEnabled(true);
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
center: true, backgroundColor: Colors.white,// fullScreen: true,//, title: '赢佳'
|
||||
// skipTaskbar: true, //跳过任务栏,任务栏无显示
|
||||
// titleBarStyle: TitleBarStyle.hidden, //隐藏顶部标题栏
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
//允许调整窗口大小
|
||||
windowManager.setResizable(false);
|
||||
|
||||
const double width = 1920;
|
||||
const double height = 1000;
|
||||
//设置最小大小
|
||||
const windowSize = Size(width, height);
|
||||
windowManager.setSize(windowSize);
|
||||
appWindow.minSize = windowSize;
|
||||
windowManager.center();
|
||||
windowManager.focus();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:web_synchronization_tool/windows/windowsJs.dart';
|
||||
import 'package:webview_windows/webview_windows.dart';
|
||||
|
||||
class SynchronizationWebTool{
|
||||
|
||||
/// 主控
|
||||
late WebviewController mainController;
|
||||
/// 受控
|
||||
List<WebviewController> childController = [];
|
||||
|
||||
/// 点击同步
|
||||
clickSynchronization(double x,double y){
|
||||
for (var controller in childController) {
|
||||
controller.executeScript(WindowsJs.clickJs(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
/// 输入
|
||||
input(int value){
|
||||
mainController.executeScript(WindowsJs.inputJs(value));
|
||||
for (var controller in childController) {
|
||||
controller.executeScript(WindowsJs.inputJs(value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,56 +1,81 @@
|
|||
class WindowsJs {
|
||||
/// 点击监听
|
||||
static String clickEventJs = '''
|
||||
document.addEventListener('click', function(event) {
|
||||
var x = event.clientX;
|
||||
var y = event.clientY;
|
||||
document.addEventListener("click", function (event) {
|
||||
var x = event.clientX;
|
||||
var y = event.clientY;
|
||||
|
||||
var value = {"x":x,"y":y};
|
||||
window.chrome.webview.postMessage(value);
|
||||
|
||||
// 检查点击的元素是否有类名为 'btn'
|
||||
if (event.target.classList.contains('btn')) {
|
||||
var click = { 'x': x, 'y': y };
|
||||
// var value = { click: click };
|
||||
|
||||
// 发送消息
|
||||
window.chrome.webview.postMessage(click);
|
||||
|
||||
// 检查点击的元素是否有类名为 'btn'
|
||||
if (event.target.classList.contains("btn")) {
|
||||
// 获取按钮上显示的文本内容
|
||||
var buttonText = event.target.innerText;
|
||||
|
||||
var btn = {"x":"成功获取到btn","y":buttonText};
|
||||
window.chrome.webview.postMessage(btn);
|
||||
|
||||
// 阻止默认的链接跳转行为
|
||||
event.preventDefault();
|
||||
|
||||
// 在当前窗口打开目标地址
|
||||
window.location.href = "http://www.df6831.com/game/";
|
||||
|
||||
|
||||
if (buttonText == "进入游戏") {
|
||||
var btn = { x: "成功获取到btn", y: buttonText };
|
||||
window.chrome.webview.postMessage(btn);
|
||||
|
||||
// 阻止默认的链接跳转行为
|
||||
event.preventDefault();
|
||||
|
||||
var newUrl = this.href; // 获取点击链接的跳转地址
|
||||
|
||||
// 在当前窗口打开目标地址
|
||||
// window.location.href = "http://www.df6831.com/game/";
|
||||
window.location.href = newUrl;
|
||||
window.chrome.webview.postMessage({url:newUrl}});
|
||||
}
|
||||
}
|
||||
|
||||
});''';
|
||||
});
|
||||
''';
|
||||
|
||||
/// 模拟点击
|
||||
static String clickJs(int x, int y) {
|
||||
static String clickJs(double x, double y) {
|
||||
return 'document.elementFromPoint($x, $y).click();';
|
||||
}
|
||||
|
||||
/// 输入
|
||||
static String inputJsString(int value) {
|
||||
static String inputJs(int value) {
|
||||
return '''
|
||||
var inputEvent = new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
var inputElement = document.querySelector(".input");
|
||||
var inputElement = document.querySelector(".bet-money");
|
||||
inputElement.value = "$value";
|
||||
inputElement.dispatchEvent(inputEvent);
|
||||
''';
|
||||
}
|
||||
|
||||
static String zoom(int zoom){
|
||||
assert(zoom >= 1 && zoom <= 100, 'zoom 1 到 100');
|
||||
|
||||
/// 监听加载,在加载完成后缩放
|
||||
static String onloadScale(int scale){
|
||||
assert(scale >= 1 && scale <= 100, 'zoom 1 到 100');
|
||||
return '''
|
||||
// document.body.style.zoom = "$zoom%";
|
||||
window.onload = function () {
|
||||
// 修改页面缩放比例为0.5(50%)
|
||||
document.body.style.transformOrigin = 'top left';
|
||||
document.body.style.transform = 'scale(${scale / 100})';
|
||||
};
|
||||
''';
|
||||
}
|
||||
|
||||
|
||||
/// 修改缩放
|
||||
static String scale(int scale){
|
||||
assert(scale >= 1 && scale <= 100, 'zoom 1 到 100');
|
||||
return '''
|
||||
// document.body.style.zoom = "$scale%";
|
||||
document.body.style.transformOrigin = 'top left';
|
||||
document.body.style.transform = 'scale(${zoom / 100})';
|
||||
document.body.style.transform = 'scale(${scale / 100})';
|
||||
''';
|
||||
}
|
||||
|
||||
static String message = 'window.chrome.webview.postMessage({x:3333}});';
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import 'package:web_synchronization_tool/windows/windowsJs.dart';
|
|||
import 'windows_web_page.dart';
|
||||
import 'package:webview_windows/webview_windows.dart';
|
||||
|
||||
import '../JavaScriptString.dart';
|
||||
|
||||
class WindowsPage extends StatefulWidget {
|
||||
const WindowsPage({super.key});
|
||||
|
||||
|
|
@ -30,10 +28,6 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
await mainController.initialize();
|
||||
await controller.initialize();
|
||||
|
||||
mainController.clearCache();
|
||||
mainController.clearCookies();
|
||||
controller.clearCache();
|
||||
controller.clearCookies();
|
||||
|
||||
mainController.loadUrl('http://www.df6831.com/');
|
||||
controller.loadUrl('http://www.df6831.com/');
|
||||
|
|
@ -49,7 +43,7 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
/// 通道消息
|
||||
mainController.webMessage.listen((event) {
|
||||
print('mainController listen -- $event');
|
||||
controller.executeScript(WindowsJs.clickJs(event['x'], event['y']));
|
||||
// controller.executeScript(WindowsJs.clickJs(event['x'], event['y']));
|
||||
});
|
||||
|
||||
/// 通道消息
|
||||
|
|
@ -61,8 +55,10 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
}
|
||||
|
||||
/// 注入点击监听
|
||||
addClickEventJS() {
|
||||
mainController.addScriptToExecuteOnDocumentCreated(WindowsJs.clickEventJs);
|
||||
addClickEventJS() async {
|
||||
ScriptID? scriptId = await mainController.addScriptToExecuteOnDocumentCreated(WindowsJs.clickEventJs);
|
||||
// mainController.addScriptToExecuteOnDocumentCreated(WindowsJs.onloadScale(70));
|
||||
// mainController.removeScriptToExecuteOnDocumentCreated(scriptId?? '');
|
||||
controller.addScriptToExecuteOnDocumentCreated(WindowsJs.clickEventJs);
|
||||
}
|
||||
|
||||
|
|
@ -87,8 +83,8 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
child: const Text('模拟点击测试')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
mainController.executeScript(WindowsJs.inputJsString(45));
|
||||
controller.executeScript(WindowsJs.inputJsString(45));
|
||||
mainController.executeScript(WindowsJs.inputJs(45));
|
||||
controller.executeScript(WindowsJs.inputJs(45));
|
||||
},
|
||||
child: const Text('模拟输入测试')),
|
||||
TextButton(
|
||||
|
|
@ -98,8 +94,8 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
child: const Text('跳转首页')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
mainController.executeScript(WindowsJs.zoom(70));
|
||||
controller.executeScript(WindowsJs.zoom(40));
|
||||
mainController.executeScript(WindowsJs.scale(70));
|
||||
controller.executeScript(WindowsJs.scale(40));
|
||||
},
|
||||
child: const Text('缩放')),
|
||||
TextButton(
|
||||
|
|
@ -113,7 +109,11 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
mainController.clearCache();
|
||||
},
|
||||
child: const Text('清除缓存')),
|
||||
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
mainController.executeScript(WindowsJs.message);
|
||||
},
|
||||
child: const Text('发送消息')),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -128,14 +128,14 @@ class _WindowsPageState extends State<WindowsPage> {
|
|||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 1000,
|
||||
width: 1350,
|
||||
height: 1000,
|
||||
child: WindowsWebWidget(
|
||||
controller: mainController,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 500,
|
||||
width: 550,
|
||||
height:400,
|
||||
child: WindowsWebWidget(
|
||||
controller: controller,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ dependencies:
|
|||
cupertino_icons: ^1.0.2
|
||||
webview_windows:
|
||||
path: ../flutter-webview-windows-main
|
||||
window_manager:
|
||||
bitsdojo_window: ^0.1.6
|
||||
window_manager: ^0.3.7
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Reference in New Issue