-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (57 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import flet
from flet_core import TemplateRoute
from win32api import GetLastError
from win32event import CreateMutex
from winerror import ERROR_ALREADY_EXISTS
import resources
from dialogs.already_running import AlreadyRunningDialog
from dialogs.new_version import NewVersionDialog
from dialogs.not_installed import NotInstalledDialog
from utils.misc import get_wiresock_bin, get_latest_version
from views.edit import EditView
from views.main import MainView
def check_startup(page: flet.Page) -> bool:
handle = CreateMutex(None, True, 'Global\\WireSockGUI')
if GetLastError() == ERROR_ALREADY_EXISTS: # works only when exe builder
handle.Detach()
dlg = AlreadyRunningDialog()
page.dialog = dlg
page.update()
return False
if not get_wiresock_bin():
dlg = NotInstalledDialog()
page.dialog = dlg
page.update()
return False
latest_version = get_latest_version()
if latest_version:
dlg = NewVersionDialog(latest_version)
page.dialog = dlg
page.update()
return True
def on_route_change(route: flet.RouteChangeEvent):
template_route = TemplateRoute(route.route)
route.page.views.clear()
route.page.views.append(
flet.View(
"/",
[MainView()],
padding=flet.padding.all(0)
)
)
if template_route.match("/edit/:config_name"):
route.page.views.append(
flet.View(
"/edit",
[EditView(getattr(template_route, "config_name"))],
scroll=flet.ScrollMode.AUTO
)
)
route.page.update()
def main(page: flet.Page):
page.title = resources.APP_TITLE
page.on_route_change = on_route_change
if check_startup(page):
page.go(page.route)
if __name__ == '__main__':
flet.app(main)