90 lines
2.2 KiB
Python
Executable File
90 lines
2.2 KiB
Python
Executable File
import tornado.web
|
|
import navpoint.get_ip
|
|
import navpoint.content
|
|
import asyncio
|
|
import secrets
|
|
import threading
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
import pyqrcode
|
|
import navpoint.fix_path
|
|
|
|
|
|
class PostHandler(tornado.web.RequestHandler):
|
|
def get(self):
|
|
self.write(
|
|
"<!DOCTYPE html><html><head><title>Navpoint</title></head><body><h1>Navpoint</h1><p>The Navpoint desktop app is working, but you need to scan the QR code from the Navpoint mobile app, not open it in your browser.</p></body></html>"
|
|
)
|
|
|
|
def post(self):
|
|
navpoint.content.content = self.request.body
|
|
intercom.put(
|
|
"Updated",
|
|
navpoint.content.content.decode("utf-8")
|
|
.split("<description>")[1]
|
|
.split("</description>")[0],
|
|
)
|
|
self.write("Navpoint")
|
|
|
|
|
|
async def main_phone(ip, token):
|
|
app = tornado.web.Application(
|
|
[
|
|
(r"/" + token, PostHandler),
|
|
]
|
|
)
|
|
app.listen(8888, address=ip)
|
|
await asyncio.Event().wait()
|
|
|
|
|
|
def run_in_thread(ip, token):
|
|
asyncio.run(main_phone(ip, token))
|
|
|
|
|
|
def run():
|
|
def new_data(purpose, content):
|
|
if purpose == "Updated":
|
|
updated.config(text="Last updated: " + content)
|
|
|
|
ip = navpoint.get_ip.get_ip()
|
|
token = secrets.token_urlsafe()
|
|
|
|
link = f"http://{ip}:8888/{token}"
|
|
|
|
window = tk.Tk(className="navpoint")
|
|
window.title("Navpoint")
|
|
window.resizable(width=False, height=False)
|
|
|
|
label = tk.Label(window, text="QR code here...")
|
|
label.pack()
|
|
|
|
updated = ttk.Label(window, text="Waiting for location")
|
|
updated.pack()
|
|
|
|
image = tk.BitmapImage(
|
|
data=pyqrcode.create(link).xbm(scale=int(window.winfo_fpixels("2m")))
|
|
)
|
|
image.config(background="white")
|
|
image.config(foreground="black")
|
|
|
|
label.config(image=image)
|
|
|
|
try:
|
|
window.iconbitmap(navpoint.fix_path.fix_path("icon.ico"))
|
|
except tk.TclError:
|
|
pass
|
|
|
|
global intercom
|
|
intercom = navpoint.intercom.Intercom(window, new_data)
|
|
|
|
threading.Thread(
|
|
target=run_in_thread,
|
|
args=(
|
|
ip,
|
|
token,
|
|
),
|
|
daemon=True,
|
|
).start()
|
|
|
|
window.mainloop()
|