参考mower的conf配置
This commit is contained in:
parent
01c4bee95e
commit
3aad1fe8ff
11 changed files with 199 additions and 67 deletions
47
launcher.py
47
launcher.py
|
@ -7,6 +7,7 @@ from subprocess import CREATE_NO_WINDOW, PIPE, STDOUT, Popen
|
|||
import requests
|
||||
import webview
|
||||
|
||||
from launcher import config
|
||||
from log import logger
|
||||
import shutil
|
||||
import os
|
||||
|
@ -17,26 +18,12 @@ mimetypes.add_type("application/javascript", ".js")
|
|||
|
||||
version = "v0.2"
|
||||
|
||||
config = {
|
||||
"page": "init",
|
||||
"branch": "slow",
|
||||
"mirror": "aliyun",
|
||||
}
|
||||
config_path = Path("launcher.json")
|
||||
|
||||
get_new_version_url = (
|
||||
"https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
||||
)
|
||||
|
||||
upgrade_script_name = "upgrade.bat"
|
||||
|
||||
try:
|
||||
with config_path.open("r") as f:
|
||||
user_config = json.load(f)
|
||||
config.update(user_config)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def custom_event(data):
|
||||
data = json.dumps({"log": data})
|
||||
|
@ -65,23 +52,15 @@ command_list = {
|
|||
|
||||
|
||||
class Api:
|
||||
def get_branch(self):
|
||||
return config["branch"]
|
||||
|
||||
def set_branch(self, branch):
|
||||
config["branch"] = branch
|
||||
def load_config(self):
|
||||
logger.info("读取配置文件")
|
||||
return config.conf.model_dump()
|
||||
|
||||
def get_page(self):
|
||||
return config["page"]
|
||||
|
||||
def set_page(self, page):
|
||||
config["page"] = page
|
||||
|
||||
def get_mirror(self):
|
||||
return config["mirror"]
|
||||
|
||||
def set_mirror(self, mirror):
|
||||
config["mirror"] = mirror
|
||||
def save_config(self, conf):
|
||||
logger.info(f"更新配置文件{conf}")
|
||||
config.conf = config.Conf(**conf)
|
||||
config.save_conf()
|
||||
|
||||
def get_version(self):
|
||||
return version
|
||||
|
@ -144,7 +123,7 @@ class Api:
|
|||
custom_event(command + "\n")
|
||||
try:
|
||||
with Popen(
|
||||
command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0
|
||||
command, stdout=PIPE, stderr=STDOUT, shell=True, cwd=cwd, bufsize=0
|
||||
) as p:
|
||||
for data in p.stdout:
|
||||
try:
|
||||
|
@ -163,11 +142,9 @@ class Api:
|
|||
if Path(upgrade_script_name).exists():
|
||||
os.remove(upgrade_script_name)
|
||||
|
||||
# url = "ui/dist/index.html"
|
||||
url = "http://localhost:5173/"
|
||||
window = webview.create_window(
|
||||
f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api()
|
||||
f"mower-ng launcher {version}", url, js_api=Api()
|
||||
)
|
||||
# window = webview.create_window(f"mower-ng launcher {version}", "http://localhost:5173/", js_api=Api())
|
||||
webview.start()
|
||||
|
||||
with config_path.open("w") as f:
|
||||
json.dump(config, f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue