desktop support
This commit is contained in:
47
app/desktop.py
Executable file
47
app/desktop.py
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import threading
|
||||
import webview
|
||||
|
||||
import flask
|
||||
|
||||
from pylocal import core, desktop, dev, tick
|
||||
|
||||
core.desktop_mode = True
|
||||
sig_exit = threading.Event()
|
||||
|
||||
argp = argparse.ArgumentParser("seagull")
|
||||
argp.add_argument("-d", "--debug", action="store_true")
|
||||
argo = argp.parse_args()
|
||||
|
||||
@core.app.route("/")
|
||||
def index():
|
||||
if not core.base_context_live:
|
||||
core.render_base_context()
|
||||
core.base_context["scripts"].insert(0, core.app.url_for("static", filename="js/desktop-structuredclone.js"))
|
||||
core.base_context["scripts"].insert(1, core.app.url_for("static", filename="js/seagull-desktop.js"))
|
||||
return flask.render_template("main_page.j2", **core.base_context)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
if sys.platform.startswith("win"):
|
||||
storage_dir = pathlib.Path(os.environ["APPDATA"]) / "seagull"
|
||||
elif sys.platform.startswith("darwin"): # macos
|
||||
storage_dir = pathlib.Path(os.environ["HOME"]) / "Library/Application Support/seagull"
|
||||
else:
|
||||
storage_dir = pathlib.Path(os.environ["HOME"]) / ".local/share/seagull"
|
||||
desktop.path_storagedir = pathlib.Path(storage_dir)
|
||||
|
||||
if argo.debug:
|
||||
desktop.api.debug_mode = True
|
||||
storage_dir.mkdir(exist_ok=True, parents=True)
|
||||
webview.create_window("Seagull Game", core.app, js_api=desktop.api)
|
||||
webview.start(private_mode=False, storage_path=storage_dir.as_posix(), debug=True if argo.debug else False)
|
||||
except KeyboardInterrupt:
|
||||
core.log.info("Goodnight, moon ...")
|
||||
sig_exit.set()
|
||||
sys.exit(0)
|
Reference in New Issue
Block a user