-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
117 lines (94 loc) · 3.07 KB
/
main.py
File metadata and controls
117 lines (94 loc) · 3.07 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
FastWinLog - High-performance Windows Event Log Analyzer
Version: 1.0.0
Repository: https://github.com/vam876/FastWinLog
License: BSD-3-Clause
"""
import os
import sys
import threading
import webview
import mimetypes
from time import time
project_root = os.path.dirname(os.path.abspath(__file__))
backend_dir = os.path.join(project_root, 'backend')
if project_root not in sys.path:
sys.path.insert(0, project_root)
if backend_dir not in sys.path:
sys.path.insert(0, backend_dir)
from backend.api.main_api import LogAnalysisApi
mimetypes.init()
mimetypes.add_type('application/javascript', '.js')
mimetypes.add_type('application/javascript', '.mjs')
mimetypes.add_type('text/css', '.css')
def set_interval(interval):
"""Timer decorator for periodic tasks"""
def decorator(function):
def wrapper(*args, **kwargs):
stopped = threading.Event()
def loop():
while not stopped.wait(interval):
function(*args, **kwargs)
t = threading.Thread(target=loop)
t.daemon = True
t.start()
return stopped
return wrapper
return decorator
def get_entrypoint_path(current_file_dir: str) -> str:
"""Get the entry HTML path"""
if getattr(sys, 'frozen', False):
# Running as compiled executable
base_path = sys._MEIPASS
candidates = [
os.path.join(base_path, "frontend", "index.html"),
]
else:
# Running as script
candidates = [
os.path.join(current_file_dir, "frontend", "index.html"),
]
for p in candidates:
abs_path = os.path.abspath(p)
if os.path.exists(abs_path):
return abs_path
raise FileNotFoundError("No index.html found in frontend directory")
def resolve_webview_url(entrypoint: str) -> str:
"""Resolve webview URL"""
print(f"✓ Using static files: {entrypoint}")
return entrypoint
@set_interval(1)
def update_ticker():
"""Update ticker for frontend"""
if len(webview.windows) > 0:
webview.windows[0].evaluate_js('window.pywebview.state && window.pywebview.state.set_ticker("%d")' % time())
if __name__ == '__main__':
print("=" * 60)
print("FastWinLog v1.0.0")
print("=" * 60)
# Initialize API
api = LogAnalysisApi()
# Get entry point
try:
entry = get_entrypoint_path(os.path.dirname(__file__))
url = resolve_webview_url(entry)
except FileNotFoundError as e:
print(f"\n❌ Error: {e}")
sys.exit(1)
# Create window
window = webview.create_window(
'FastWinLog v1.0.0',
url,
js_api=api,
width=1400,
height=900,
resizable=True,
background_color='#1e1e1e',
text_select=True
)
print("\n✓ Application started successfully")
print("=" * 60)
# Start webview
webview.start(debug=False)