From fe36735f37ff22a4d7c84185706b244d18692b4e Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Sun, 5 Mar 2023 00:17:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Get=20windo?= =?UTF-8?q?w=20in=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/__init__.py | 12 +++++------- frontend/src/views/InputVideoNumber.vue | 2 +- main.py | 20 ++------------------ 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index b6d0c83..ccdf70d 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,12 +1,10 @@ from bottle import request, response, Bottle, static_file from manager import Manager from json import dumps -from queue import SimpleQueue +import webview manager = Manager() app = Bottle() -action_queue = SimpleQueue() -path_queue = SimpleQueue() @app.get("/") @@ -38,9 +36,9 @@ def download(): return "OK" -@app.post("/path") +@app.get("/path") def get_path(): - path = request.json["path"] - action_queue.put(path) - manager.path = path_queue.get() + result = webview.active_window().create_file_dialog(dialog_type=webview.FOLDER_DIALOG) + if result: + manager.path = result[0] return manager.path diff --git a/frontend/src/views/InputVideoNumber.vue b/frontend/src/views/InputVideoNumber.vue index aaba165..5a8bf90 100644 --- a/frontend/src/views/InputVideoNumber.vue +++ b/frontend/src/views/InputVideoNumber.vue @@ -20,7 +20,7 @@ function sendNVList() { } function get_path() { - axios.post("/path", { path: path.value }).then(({ data }) => { + axios.get("/path").then(({ data }) => { path.value = data; input.value.focus(); }); diff --git a/main.py b/main.py index 2c0bd9b..d98a52d 100755 --- a/main.py +++ b/main.py @@ -4,33 +4,17 @@ import webview import platform from os import _exit from time import sleep -from backend import app, action_queue, path_queue - - -def select_download_path(window): - while True: - path = action_queue.get() - result = window.create_file_dialog(webview.FOLDER_DIALOG) - if result: - path_queue.put(result[0]) - else: - path_queue.put(path) - - -def on_closed(): - sleep(1) - _exit(0) +from backend import app if __name__ == "__main__": window = webview.create_window( "badl - BiliBili Audio Downloader", app, width=500, height=700 ) - window.events.closed += on_closed if os := platform.system() == "Linux": gui = "gtk" elif os == "Windows": gui = "edgehtml" else: gui = "" - webview.start(gui=gui, func=select_download_path, args=(window,)) + webview.start(gui=gui)