-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
49 lines (42 loc) · 1.38 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
import eel_api
import eel
import psutil
import subprocess
import argparse
WEB_FILES_PATH = 'vite-project'
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
"--mode",
choices=("dev", "prod"),
default="prod",
help="Launch the app in development (Vite HMR) or production mode"
)
args = parser.parse_args()
if args.mode == 'dev':
npm_process = subprocess.Popen(
"npm run dev".split(),
cwd=WEB_FILES_PATH
)
print(
"It can take a few seconds to launch the eel window, please wait..."
)
eel.init(WEB_FILES_PATH)
def on_eel_close(page, sockets):
print("Closing npm process...")
process = psutil.Process(npm_process.pid)
for child in process.children(recursive=True):
child.terminate()
npm_process.terminate()
npm_process.wait()
exit()
eel.start(
{"port": 5173, "host": "localhost", "port_eel": 8000},
close_callback=on_eel_close,
)
elif args.mode == 'prod':
if 0 != subprocess.call("npm run build".split(), cwd=WEB_FILES_PATH):
print("An error occurred during the build, please check the logs")
exit(1)
eel.init(f"{WEB_FILES_PATH}/dist")
eel.start('index.html')