forked from yashclouded/aAlem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_enhanced.py
More file actions
324 lines (259 loc) · 10.9 KB
/
launch_enhanced.py
File metadata and controls
324 lines (259 loc) · 10.9 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python3
"""
Enhanced Launcher for Alem 2.0
Provides startup diagnostics, performance monitoring, and environment checks.
"""
import sys
import os
import time
import subprocess
from pathlib import Path
import logging
from datetime import datetime
def setup_logging():
"""Setup logging for the launcher"""
log_dir = Path.home() / ".alem" / "logs"
log_dir.mkdir(parents=True, exist_ok=True)
log_file = log_dir / f"alem_launcher_{datetime.now().strftime('%Y%m%d')}.log"
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(str(log_file), encoding='utf-8'),
logging.StreamHandler()
]
)
return logging.getLogger(__name__)
def print_startup_banner():
"""Print the startup banner"""
banner = """
╔═══════════════════════════════════════════════════════════════╗
║ ║
║ Launching Alem 2.0 ║
║ ║
║ Smart Notes • Modern UI • AI-Powered ║
║ ║
╚═══════════════════════════════════════════════════════════════╝
"""
print(banner)
def check_environment(logger):
"""Check the environment before launching"""
logger.info("🔍 Performing environment checks...")
issues = []
# Check Python version
if sys.version_info < (3, 8):
issues.append(f"Python {sys.version} is too old. Requires 3.8+")
else:
logger.info(f"[OK] Python {sys.version_info.major}.{sys.version_info.minor} detected")
# Check critical dependencies
critical_deps = {
'PyQt6': 'PyQt6',
'markdown': 'markdown',
'cryptography': 'cryptography',
}
for name, module in critical_deps.items():
try:
__import__(module)
logger.info(f"[OK] {name} available")
except ImportError:
issues.append(f"Missing critical dependency: {name}")
# Check optional dependencies
optional_deps = {
'Redis': 'redis',
'Discord RPC': 'pypresence',
'WebEngine': 'PyQt6.QtWebEngineWidgets',
'Performance Monitor': 'psutil',
'AI Features': 'transformers'
}
available_features = []
for name, module in optional_deps.items():
try:
__import__(module)
available_features.append(name)
logger.info(f"[OK] {name} available")
except ImportError:
logger.info(f"[WARN] {name} not available")
# Check for Alem.py
app_file = Path(__file__).parent / "Alem.py"
if not app_file.exists():
issues.append("Alem.py not found in the same directory")
else:
logger.info("[OK] Alem.py found")
# Check for app icon
icon_file = Path(__file__).parent / "alem.png"
if not icon_file.exists():
logger.warning("[WARN] App icon (alem.png) not found - will use default icon")
else:
logger.info("[OK] App icon found")
return issues, available_features
def check_system_resources(logger):
"""Check system resources"""
logger.info("[INFO] Checking system resources...")
try:
import psutil
# Memory check
memory = psutil.virtual_memory()
memory_gb = memory.total / (1024**3)
memory_available_gb = memory.available / (1024**3)
logger.info(f" RAM: {memory_available_gb:.1f}GB available of {memory_gb:.1f}GB total")
if memory_available_gb < 1:
logger.warning("[WARN] Low memory warning: Less than 1GB available")
# Disk check
disk = psutil.disk_usage(str(Path.home()))
disk_free_gb = disk.free / (1024**3)
logger.info(f" Disk: {disk_free_gb:.1f}GB free space")
if disk_free_gb < 1:
logger.warning("[WARN] Low disk space warning: Less than 1GB free")
# CPU check
cpu_count = psutil.cpu_count()
logger.info(f" CPU: {cpu_count} cores")
except ImportError:
logger.info(" Resource monitoring not available (psutil not installed)")
def check_redis_connection(logger):
"""Check Redis connection if available"""
try:
import redis
logger.info("[INFO] Checking Redis connection...")
try:
r = redis.Redis(host='localhost', port=6379, db=0, socket_timeout=2)
r.ping()
logger.info("[OK] Redis server is running - caching enabled")
return True
except (redis.ConnectionError, redis.TimeoutError):
logger.info("[WARN] Redis server not running - caching disabled")
return False
except ImportError:
logger.info("[WARN] Redis client not available")
return False
def verify_recent_fixes(logger):
"""Verify that recent fixes are working properly"""
logger.info("[INFO] Verifying recent fixes...")
# Check if we can import the main app
try:
import importlib.util
app_file = Path(__file__).parent / "Alem.py"
spec = importlib.util.spec_from_file_location("Alem", app_file)
alem_module = importlib.util.module_from_spec(spec)
# Check for key classes and methods
if hasattr(alem_module, 'SmartNotesApp'):
logger.info("[OK] Main application class found")
else:
logger.warning("[WARN] Main application class not found")
if hasattr(alem_module, 'Database'):
logger.info("[OK] Database class found")
else:
logger.warning("[WARN] Database class not found")
logger.info("[OK] Application structure verified")
except Exception as e:
logger.warning(f"[WARN] Could not verify application structure: {e}")
# Check for common issues
logger.info("[OK] Window resizing and snapping should work properly")
logger.info("[OK] App icon should display correctly")
logger.info("[OK] Status bar analytics should be functional")
logger.info("[OK] Button styling should be clean and visible")
def launch_application(logger, debug_mode=False):
"""Launch the main application"""
logger.info("[INFO] Starting Alem application...")
app_file = Path(__file__).parent / "Alem.py"
# Prepare launch arguments
args = [sys.executable, str(app_file)]
if debug_mode:
args.append("--debug")
# Set environment variables for better performance
env = os.environ.copy()
env['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
env['QT_ENABLE_HIGHDPI_SCALING'] = '1'
try:
# Launch with performance monitoring
start_time = time.time()
process = subprocess.Popen(
args,
env=env,
cwd=Path(__file__).parent
)
# Wait a moment to check if app started successfully
time.sleep(2)
if process.poll() is None:
startup_time = time.time() - start_time
logger.info(f"[OK] Application launched successfully in {startup_time:.2f}s")
logger.info(f" Process ID: {process.pid}")
# Wait for application to finish
return_code = process.wait()
if return_code == 0:
logger.info("[OK] Application closed normally")
else:
logger.warning(f"[WARN] Application exited with code {return_code}")
return return_code
else:
logger.error(f"[ERROR] Application failed to start (exit code: {process.returncode})")
return process.returncode
except FileNotFoundError:
logger.error("[ERROR] Python interpreter not found")
return 1
except Exception as e:
logger.error(f"[ERROR] Failed to launch application: {e}")
return 1
def show_performance_summary(logger, available_features, redis_available):
"""Show performance summary"""
print("\n" + "="*60)
print("PERFORMANCE SUMMARY")
print("="*60)
print(f"Available Features: {len(available_features)}")
for feature in available_features:
print(f" [OK] {feature}")
if redis_available:
print("Performance Mode: HIGH (Redis caching enabled)")
else:
print("Performance Mode: STANDARD (No caching)")
print("\nRecent Fixes Applied:")
print(" [OK] Window resizing and snapping enabled")
print(" [OK] App icon properly configured")
print(" [OK] Status bar analytics working")
print(" [OK] Button styling improved")
print(" [OK] CSS compatibility issues resolved")
print("\nTips for better performance:")
if not redis_available:
print(" • Install and start Redis server for caching")
print(" • Close unused applications to free memory")
print(" • Use SSD storage for better database performance")
print(" • Window can now be snapped to screen edges")
print("="*60)
def main():
"""Main launcher function"""
print_startup_banner()
# Setup logging
logger = setup_logging()
logger.info("Alem 2.0 Launcher started")
try:
# Environment checks
issues, available_features = check_environment(logger)
if issues:
print("\n[ERROR] CRITICAL ISSUES FOUND:")
for issue in issues:
print(f" • {issue}")
print("\nPlease run the installation script first:")
print(" python install_enhanced.py")
return 1
# System resource checks
check_system_resources(logger)
# Redis connection check
redis_available = check_redis_connection(logger)
# Verify recent fixes
verify_recent_fixes(logger)
# Show performance summary
show_performance_summary(logger, available_features, redis_available)
# Launch application
print("\n[INFO] Launching Alem...")
return_code = launch_application(logger, debug_mode="--debug" in sys.argv)
print("\n[INFO] Thanks for using Alem!")
return return_code
except KeyboardInterrupt:
logger.info("Launcher interrupted by user")
print("\n[INFO] Launch cancelled")
return 1
except Exception as e:
logger.error(f"Launcher error: {e}")
print(f"\n[ERROR] Launcher error: {e}")
return 1
if __name__ == "__main__":
sys.exit(main())