All checks were successful
ci/woodpecker/push/check_format Pipeline was successful
95 lines
2.6 KiB
Python
Executable file
95 lines
2.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Copyright (c) 2024 zhbaor <zhbaor@zhaozuohong.vip>
|
|
|
|
This file is part of mower-ng (https://git.zhaozuohong.vip/mower-ng/mower-ng).
|
|
|
|
Mower-ng is free software: you may copy, redistribute and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, version 3 or later.
|
|
|
|
This file is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
import json
|
|
import mimetypes
|
|
|
|
import webview
|
|
|
|
mimetypes.add_type("text/html", ".html")
|
|
mimetypes.add_type("text/css", ".css")
|
|
mimetypes.add_type("application/javascript", ".js")
|
|
|
|
|
|
class Api:
|
|
def __init__(self):
|
|
try:
|
|
with open("instances.json", "r", encoding="utf-8") as f:
|
|
self.instances = json.load(f)
|
|
except Exception:
|
|
self.instances = []
|
|
self.save()
|
|
|
|
def save(self):
|
|
with open("instances.json", "w", encoding="utf-8") as f:
|
|
json.dump(self.instances, f, ensure_ascii=False)
|
|
|
|
def get_instances(self):
|
|
return self.instances
|
|
|
|
def add(self, name, path):
|
|
self.instances.append({"name": name, "path": path})
|
|
self.save()
|
|
|
|
def remove(self, idx):
|
|
del self.instances[idx]
|
|
self.save()
|
|
|
|
def rename(self, idx, name):
|
|
self.instances[idx]["name"] = name
|
|
self.save()
|
|
|
|
def select_path(self, idx):
|
|
window = webview.active_window()
|
|
folder = window.create_file_dialog(dialog_type=webview.FOLDER_DIALOG)
|
|
if folder is None:
|
|
return None
|
|
if not isinstance(folder, str):
|
|
folder = folder[0]
|
|
self.instances[idx]["path"] = folder
|
|
self.save()
|
|
return folder
|
|
|
|
def start(self, idx):
|
|
import sys
|
|
from pathlib import Path
|
|
from subprocess import Popen
|
|
|
|
Popen(
|
|
[sys.executable, "webview_ui.py", self.instances[idx]["path"]],
|
|
cwd=Path(__file__).parent,
|
|
)
|
|
|
|
|
|
def jump_to_index(window):
|
|
window.load_url("/manager/index.html")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
api = Api()
|
|
window = webview.create_window(
|
|
title="多开管理器",
|
|
url="ui/dist/index.html",
|
|
js_api=api,
|
|
min_size=(400, 500),
|
|
width=400,
|
|
height=500,
|
|
)
|
|
webview.start(jump_to_index, window, http_server=True)
|