From c97a8a3084db2effcd547345d750451204a51d9f Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Thu, 8 Jun 2023 22:13:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E8=AE=BE=E7=BD=AE=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0WebView=E7=9B=B8=E5=85=B3=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=9B=E4=BF=9D=E5=AD=98=E7=AA=97=E5=8F=A3=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/templates/conf.yml | 6 ++++- server.py | 3 +-- webview_ui.py | 43 +++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/arknights_mower/templates/conf.yml b/arknights_mower/templates/conf.yml index 33790782f..495ff20fd 100644 --- a/arknights_mower/templates/conf.yml +++ b/arknights_mower/templates/conf.yml @@ -51,4 +51,8 @@ maa_mall_buy: 招聘许可,龙门币 maa_recruit_only_4: false maa_recruitment_time: false maa_rg_sleep_max: 8:30 -maa_rg_sleep_min: 9:30 \ No newline at end of file +maa_rg_sleep_min: 9:30 +webview: + port: 58000 + width: 1100 + height: 780 diff --git a/server.py b/server.py index d74c95c10..f48cd6bfe 100755 --- a/server.py +++ b/server.py @@ -49,9 +49,8 @@ def load_config(): conf = load_conf() return conf else: - conf = request.json + conf.update(request.json) save_conf(conf) - conf = load_conf() return f"New config saved!" diff --git a/webview_ui.py b/webview_ui.py index b89046082..460ffa6d2 100755 --- a/webview_ui.py +++ b/webview_ui.py @@ -6,20 +6,49 @@ import os import multiprocessing +from arknights_mower.utils.conf import load_conf, save_conf -def start_server(app): - app.run(host="127.0.0.1", port="8000") + +def start_server(app, port): + app.run(host="127.0.0.1", port=port) + + +def on_resized(w, h): + global width + global height + + width = w + height = h if __name__ == "__main__": multiprocessing.freeze_support() - webview.create_window( + conf = load_conf() + + port = conf["webview"]["port"] + + global width + global height + + width = conf["webview"]["width"] + height = conf["webview"]["height"] + + window = webview.create_window( "Mower Web UI in WebView (尚不完善,测试用途,谨慎使用)", - "http://127.0.0.1:8000", - width=1200, - height=900, + f"http://127.0.0.1:{port}", + width=width, + height=height, ) - webview.start(start_server, app) + + window.events.resized += on_resized + + webview.start(start_server, (app, port)) + + + conf = load_conf() + conf["webview"]["width"] = width + conf["webview"]["height"] = height + save_conf(conf) os._exit(0)