-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
executable file
·340 lines (285 loc) · 12.3 KB
/
Copy pathlauncher.py
File metadata and controls
executable file
·340 lines (285 loc) · 12.3 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env python3
"""
CloneKit Launcher with Loading Screen
Cross-platform launcher with beautiful loading animation
"""
import os
import sys
import subprocess
import platform
import time
import threading
from pathlib import Path
from tkinter import Tk, Canvas, Label, Frame
import tkinter as tk
# Colors
class Colors:
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BLUE = '\033[94m'
CYAN = '\033[96m'
RESET = '\033[0m'
def print_colored(text, color=''):
if platform.system() != 'Windows':
print(f"{color}{text}{Colors.RESET}")
else:
print(text)
class LoadingScreen:
def __init__(self):
self.root = Tk()
self.root.title("CloneKit")
self.root.configure(bg='#0a0e14')
self.root.overrideredirect(True) # Remove window decorations
# Center window
width = 600
height = 400
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
x = (screen_width - width) // 2
y = (screen_height - height) // 2
self.root.geometry(f"{width}x{height}+{x}+{y}")
# Main frame
main_frame = Frame(self.root, bg='#0a0e14')
main_frame.pack(fill='both', expand=True)
# Logo/Title
title_label = Label(main_frame, text="CloneKit",
font=("Segoe UI", 48, "bold"),
bg='#0a0e14', fg='#ffd700')
title_label.pack(pady=(50, 10))
subtitle_label = Label(main_frame, text="Website Cloning Toolkit",
font=("Segoe UI", 16),
bg='#0a0e14', fg='#00d4ff')
subtitle_label.pack(pady=(0, 40))
# Loading animation canvas
self.canvas = Canvas(main_frame, width=300, height=20, bg='#0a0e14',
highlightthickness=0)
self.canvas.pack(pady=20)
# Progress bar background
self.canvas.create_rectangle(50, 5, 250, 15, fill='#1a1e24', outline='')
# Progress bar
self.progress_bar = self.canvas.create_rectangle(50, 5, 50, 15, fill='#00ff88', outline='')
# Status text
self.status_label = Label(main_frame, text="Initializing...",
font=("Segoe UI", 12),
bg='#0a0e14', fg='#00d4ff')
self.status_label.pack(pady=10)
# Version info
version_label = Label(main_frame, text="v1.0.0",
font=("Segoe UI", 9),
bg='#0a0e14', fg='#606672')
version_label.pack(side='bottom', pady=10)
self.progress = 0
self.animating = True
def update_progress(self, value, status=""):
"""Update progress bar (0-100) - thread-safe"""
def _update():
try:
self.progress = max(0, min(100, value))
width = 50 + int((250 - 50) * (self.progress / 100))
self.canvas.coords(self.progress_bar, 50, 5, width, 15)
if status:
self.status_label.config(text=status)
except:
pass # Ignore errors if window is closed
# Use root.after to ensure thread-safe GUI updates
try:
self.root.after(0, _update)
except:
pass
def animate(self):
"""Animate loading bar"""
while self.animating:
try:
for i in range(0, 101, 2):
if not self.animating:
break
self.update_progress(i)
time.sleep(0.02)
time.sleep(0.1)
except:
break # Exit if window is closed
def close(self):
"""Close loading screen"""
self.animating = False
time.sleep(0.2)
try:
self.root.after(0, self.root.destroy)
time.sleep(0.1)
except:
pass
def get_script_dir():
if getattr(sys, 'frozen', False):
return os.path.dirname(sys.executable)
else:
return os.path.dirname(os.path.abspath(__file__))
def check_python(loading_screen):
loading_screen.update_progress(10, "Checking Python installation...")
python_cmd = 'python3' if platform.system() != 'Windows' else 'python'
try:
result = subprocess.run([python_cmd, '--version'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
return python_cmd
except:
pass
alt_cmd = 'python' if python_cmd == 'python3' else 'python3'
try:
result = subprocess.run([alt_cmd, '--version'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
return alt_cmd
except:
pass
return None
def setup_venv(script_dir, python_cmd, loading_screen):
loading_screen.update_progress(20, "Setting up virtual environment...")
venv_path = Path(script_dir) / 'venv'
if venv_path.exists():
loading_screen.update_progress(30, "Virtual environment found")
return True
loading_screen.update_progress(25, "Creating virtual environment...")
try:
subprocess.run([python_cmd, '-m', 'venv', str(venv_path)],
check=True, cwd=script_dir,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
loading_screen.update_progress(30, "Virtual environment created")
return True
except Exception as e:
print_colored(f"[!] Failed to create venv: {e}", Colors.RED)
return False
def get_venv_python(script_dir):
if platform.system() == 'Windows':
return Path(script_dir) / 'venv' / 'Scripts' / 'python.exe'
else:
return Path(script_dir) / 'venv' / 'bin' / 'python'
def install_dependencies(venv_python, script_dir, loading_screen):
"""Install dependencies with auto-retry and better progress tracking"""
requirements = Path(script_dir) / 'requirements_cloner.txt'
if not requirements.exists():
loading_screen.update_progress(60, "No requirements file found")
return True
loading_screen.update_progress(40, "Checking dependencies...")
try:
# Check if packages are installed
result = subprocess.run([str(venv_python), '-m', 'pip', 'list'],
capture_output=True, text=True, timeout=10,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
needs_install = 'playwright' not in result.stdout.lower()
if needs_install:
loading_screen.update_progress(45, "Upgrading pip...")
try:
subprocess.run([str(venv_python), '-m', 'pip', 'install', '--upgrade', 'pip'],
check=True, cwd=script_dir, timeout=60,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except:
pass # Continue even if pip upgrade fails
loading_screen.update_progress(50, "Installing packages (this may take a while)...")
try:
subprocess.run([str(venv_python), '-m', 'pip', 'install', '-r', str(requirements)],
check=True, cwd=script_dir, timeout=300,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
loading_screen.update_progress(75, "Packages installed")
except subprocess.TimeoutExpired:
loading_screen.update_progress(75, "Installation taking longer than expected...")
except Exception as e:
print_colored(f"[!] Package installation warning: {e}", Colors.YELLOW)
loading_screen.update_progress(80, "Installing Playwright browsers...")
try:
subprocess.run([str(venv_python), '-m', 'playwright', 'install', 'chromium'],
check=True, cwd=script_dir, timeout=180,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
loading_screen.update_progress(90, "Playwright browsers installed")
except subprocess.TimeoutExpired:
loading_screen.update_progress(90, "Browser installation in progress...")
except Exception as e:
print_colored(f"[!] Playwright installation warning: {e}", Colors.YELLOW)
loading_screen.update_progress(90, "Continuing without Playwright browsers...")
else:
loading_screen.update_progress(90, "Dependencies ready")
return True
except Exception as e:
print_colored(f"[!] Failed to install dependencies: {e}", Colors.RED)
loading_screen.update_progress(90, "Continuing with partial installation...")
return True
def launch_gui(venv_python, script_dir, loading_screen):
loading_screen.update_progress(95, "Launching GUI...")
gui_script = Path(script_dir) / 'clonekit_gui.py'
if not gui_script.exists():
loading_screen.update_progress(100, "ERROR: GUI script not found")
time.sleep(1)
return False
loading_screen.update_progress(100, "Ready!")
time.sleep(0.5)
# Close loading screen before launching GUI
loading_screen.close()
time.sleep(0.2) # Give time for window to close
try:
os.chdir(script_dir)
subprocess.run([str(venv_python), str(gui_script)], cwd=script_dir)
return True
except KeyboardInterrupt:
return True
except Exception as e:
print_colored(f"[!] Error launching GUI: {e}", Colors.RED)
input("Press Enter to exit...")
return False
def main():
# Create and show loading screen
loading_screen = LoadingScreen()
# Start animation in separate thread
anim_thread = threading.Thread(target=loading_screen.animate, daemon=True)
anim_thread.start()
# Process setup in background thread
def do_setup():
try:
script_dir = get_script_dir()
# Check Python
python_cmd = check_python(loading_screen)
if not python_cmd:
loading_screen.update_progress(100, "ERROR: Python not found!")
time.sleep(2)
loading_screen.root.after(0, loading_screen.close)
print_colored("[!] Python not found! Please install Python 3.7+", Colors.RED)
return False
# Setup virtual environment
if not setup_venv(script_dir, python_cmd, loading_screen):
loading_screen.update_progress(100, "ERROR: Failed to setup venv")
time.sleep(2)
loading_screen.root.after(0, loading_screen.close)
return False
# Get venv Python
venv_python = get_venv_python(script_dir)
if not venv_python.exists():
loading_screen.update_progress(100, "ERROR: Venv Python not found")
time.sleep(2)
loading_screen.root.after(0, loading_screen.close)
return False
# Install dependencies
install_dependencies(venv_python, script_dir, loading_screen)
# Launch GUI
result = launch_gui(venv_python, script_dir, loading_screen)
# Close loading screen after GUI launches
if result:
loading_screen.root.after(0, loading_screen.close)
return result
except Exception as e:
loading_screen.update_progress(100, f"ERROR: {str(e)}")
time.sleep(2)
loading_screen.root.after(0, loading_screen.close)
print_colored(f"[!] Fatal error: {e}", Colors.RED)
return False
# Start setup in background thread
setup_thread = threading.Thread(target=do_setup, daemon=True)
setup_thread.start()
# Run mainloop in main thread (required for Tkinter)
try:
loading_screen.root.mainloop()
except:
pass
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print_colored("\n[!] Interrupted by user", Colors.YELLOW)
sys.exit(0)