初步代替几个bat脚本的功能
This commit is contained in:
commit
d0fbc89012
19 changed files with 4002 additions and 0 deletions
57
main.py
Normal file
57
main.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, STDOUT, Popen
|
||||
|
||||
import webview
|
||||
|
||||
config_path = Path("launcher.json")
|
||||
|
||||
try:
|
||||
with config_path.open("r") as f:
|
||||
config = json.load(f)
|
||||
except Exception:
|
||||
config = {
|
||||
"page": "init",
|
||||
"branch": "slow",
|
||||
}
|
||||
|
||||
|
||||
def custom_event(name, data):
|
||||
data = json.dumps({name: data})
|
||||
js = f"var event = new CustomEvent('log', {{detail: {data}}}); window.dispatchEvent(event);"
|
||||
window.evaluate_js(js)
|
||||
|
||||
|
||||
class Api:
|
||||
def get_branch(self):
|
||||
return config["branch"]
|
||||
|
||||
def set_branch(self, branch):
|
||||
config["branch"] = branch
|
||||
|
||||
def get_page(self):
|
||||
return config["page"]
|
||||
|
||||
def set_page(self, page):
|
||||
config["page"] = page
|
||||
|
||||
def run(self, command, cwd=None):
|
||||
with Popen(
|
||||
os.path.normpath(command),
|
||||
stdout=PIPE,
|
||||
stderr=STDOUT,
|
||||
shell=True,
|
||||
bufsize=1,
|
||||
text=True,
|
||||
cwd=cwd,
|
||||
) as p:
|
||||
for line in p.stdout:
|
||||
custom_event("log", line)
|
||||
|
||||
|
||||
window = webview.create_window("mower-ng launcher", "dist/index.html", 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