🧑💻 Get window in backend
This commit is contained in:
parent
cfb0337c69
commit
fe36735f37
3 changed files with 8 additions and 26 deletions
|
@ -1,12 +1,10 @@
|
||||||
from bottle import request, response, Bottle, static_file
|
from bottle import request, response, Bottle, static_file
|
||||||
from manager import Manager
|
from manager import Manager
|
||||||
from json import dumps
|
from json import dumps
|
||||||
from queue import SimpleQueue
|
import webview
|
||||||
|
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
app = Bottle()
|
app = Bottle()
|
||||||
action_queue = SimpleQueue()
|
|
||||||
path_queue = SimpleQueue()
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
@ -38,9 +36,9 @@ def download():
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
|
||||||
@app.post("/path")
|
@app.get("/path")
|
||||||
def get_path():
|
def get_path():
|
||||||
path = request.json["path"]
|
result = webview.active_window().create_file_dialog(dialog_type=webview.FOLDER_DIALOG)
|
||||||
action_queue.put(path)
|
if result:
|
||||||
manager.path = path_queue.get()
|
manager.path = result[0]
|
||||||
return manager.path
|
return manager.path
|
||||||
|
|
|
@ -20,7 +20,7 @@ function sendNVList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_path() {
|
function get_path() {
|
||||||
axios.post("/path", { path: path.value }).then(({ data }) => {
|
axios.get("/path").then(({ data }) => {
|
||||||
path.value = data;
|
path.value = data;
|
||||||
input.value.focus();
|
input.value.focus();
|
||||||
});
|
});
|
||||||
|
|
20
main.py
20
main.py
|
@ -4,33 +4,17 @@ import webview
|
||||||
import platform
|
import platform
|
||||||
from os import _exit
|
from os import _exit
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from backend import app, action_queue, path_queue
|
from backend import app
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
window = webview.create_window(
|
window = webview.create_window(
|
||||||
"badl - BiliBili Audio Downloader", app, width=500, height=700
|
"badl - BiliBili Audio Downloader", app, width=500, height=700
|
||||||
)
|
)
|
||||||
window.events.closed += on_closed
|
|
||||||
if os := platform.system() == "Linux":
|
if os := platform.system() == "Linux":
|
||||||
gui = "gtk"
|
gui = "gtk"
|
||||||
elif os == "Windows":
|
elif os == "Windows":
|
||||||
gui = "edgehtml"
|
gui = "edgehtml"
|
||||||
else:
|
else:
|
||||||
gui = ""
|
gui = ""
|
||||||
webview.start(gui=gui, func=select_download_path, args=(window,))
|
webview.start(gui=gui)
|
||||||
|
|
Loading…
Reference in a new issue