73 lines
1.7 KiB
Python
Executable File
73 lines
1.7 KiB
Python
Executable File
import tornado
|
|
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
|
|
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():
|
|
ip = navpoint.get_ip.get_ip()
|
|
token = secrets.token_urlsafe()
|
|
threading.Thread(
|
|
target=run_in_thread,
|
|
args=(
|
|
ip,
|
|
token,
|
|
),
|
|
daemon=True,
|
|
).start()
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
window.mainloop()
|