-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
683 lines (565 loc) · 26.6 KB
/
gui.py
File metadata and controls
683 lines (565 loc) · 26.6 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
import sys
import socket
import os
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QLabel, QPushButton, QCheckBox,
QLineEdit, QFileDialog, QSystemTrayIcon, QMenu,
QMessageBox, QComboBox)
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QSize, QSharedMemory
from PyQt6.QtGui import QIcon, QAction, QPixmap, QPainter, QColor
import uvicorn
from config import Config
from notifications import NotificationManager
from server import ShareServer
from translations import Translator
import autostart
class ServerThread(QThread):
"""Thread separato per eseguire il server FastAPI"""
def __init__(self, app, port):
super().__init__()
self.app = app
self.port = port
self.should_stop = False
def run(self):
config = uvicorn.Config(
self.app,
host="0.0.0.0",
port=self.port,
log_level="info"
)
server = uvicorn.Server(config)
server.run()
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Redirigi stdout/stderr per evitare crash in modalità windowed
import os
if not sys.stdout or not sys.stderr:
# Se stdout/stderr non esistono (modalità windowed), redirigili a un file
# Determina la directory del progetto
if getattr(sys, 'frozen', False):
# Se eseguito come .exe, usa la directory dell'eseguibile
app_dir = os.path.dirname(sys.executable)
else:
# Se eseguito come script, usa la directory del file
app_dir = os.path.dirname(os.path.abspath(__file__))
# Crea la cartella logs se non esiste
log_dir = os.path.join(app_dir, "logs")
os.makedirs(log_dir, exist_ok=True)
sys.stdout = open(os.path.join(log_dir, "ios_shareeasy_stdout.log"), "w", encoding="utf-8")
sys.stderr = open(os.path.join(log_dir, "ios_shareeasy_stderr.log"), "w", encoding="utf-8")
self.config = Config()
# Carica la lingua salvata o usa italiano di default
saved_lang = self.config.get("language") or "it"
self.translator = Translator(saved_lang)
self.notification_manager = NotificationManager()
self.server_thread = None
self.init_ui()
self.start_server()
# Mostra il dialogo di benvenuto al primo avvio
self.show_first_run_welcome()
def get_local_ip(self):
"""Ottiene l'IP locale"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
except Exception:
return "127.0.0.1"
def init_ui(self):
self.setWindowTitle(self.translator("window_title"))
self.setMinimumSize(500, 450)
# Imposta l'icona dell'applicazione (per la finestra e la taskbar)
self.set_app_icon()
# Setup tray icon
self.setup_tray_icon()
# Widget centrale
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
# Header con titolo e selezione lingua
header_layout = QHBoxLayout()
# Titolo
title = QLabel(self.translator("title"))
title.setStyleSheet("font-size: 24px; font-weight: bold; margin: 20px;")
header_layout.addWidget(title)
header_layout.addStretch()
# Selezione lingua
lang_label = QLabel("🌐")
lang_label.setStyleSheet("font-size: 18px;")
header_layout.addWidget(lang_label)
self.language_combo = QComboBox()
self.language_combo.addItem("🇮🇹 Italiano", "it")
self.language_combo.addItem("🇬🇧 English", "en")
self.language_combo.setCurrentIndex(0 if self.translator.language == "it" else 1)
self.language_combo.currentIndexChanged.connect(self.change_language)
self.language_combo.setMaximumWidth(150)
header_layout.addWidget(self.language_combo)
layout.addLayout(header_layout)
# URL completo con pulsanti
url_layout = QHBoxLayout()
self.url_label = QLabel(self.translator("server_url"))
self.url_label.setStyleSheet("font-weight: bold;")
self.url_value = QLabel(f"http://{self.get_local_ip()}:{self.config.get('port')}/share")
self.url_value.setStyleSheet("font-size: 14px; color: #009900; padding: 10px;")
self.url_value.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
url_layout.addWidget(self.url_label)
url_layout.addWidget(self.url_value)
# Pulsante copia URL
self.copy_url_btn = QPushButton(self.translator("copy_url"))
self.copy_url_btn.setMaximumWidth(140)
self.copy_url_btn.clicked.connect(self.copy_url)
url_layout.addWidget(self.copy_url_btn)
url_layout.addStretch()
layout.addLayout(url_layout)
# Warning per la shortcut
self.url_warning = QLabel(self.translator("url_warning"))
self.url_warning.setStyleSheet("color: #ff6600; font-size: 11px; padding: 5px 10px; background-color: #fff3e0; border-radius: 3px;")
self.url_warning.setWordWrap(True)
layout.addWidget(self.url_warning)
layout.addSpacing(20)
# Checkbox per funzionalità
self.copy_checkbox = QCheckBox(self.translator("enable_copy"))
self.copy_checkbox.setChecked(self.config.get("copy_enabled"))
self.copy_checkbox.stateChanged.connect(self.toggle_copy)
layout.addWidget(self.copy_checkbox)
self.file_checkbox = QCheckBox(self.translator("enable_file"))
self.file_checkbox.setChecked(self.config.get("file_enabled"))
self.file_checkbox.stateChanged.connect(self.toggle_file)
layout.addWidget(self.file_checkbox)
self.notification_checkbox = QCheckBox(self.translator("enable_notifications"))
self.notification_checkbox.setChecked(self.config.get("notifications_enabled"))
self.notification_checkbox.stateChanged.connect(self.toggle_notifications)
layout.addWidget(self.notification_checkbox)
self.autostart_checkbox = QCheckBox(self.translator("enable_autostart"))
self.autostart_checkbox.setChecked(autostart.is_autostart_enabled())
self.autostart_checkbox.stateChanged.connect(self.toggle_autostart)
layout.addWidget(self.autostart_checkbox)
self.hide_tray_checkbox = QCheckBox(self.translator("hide_tray_icon"))
self.hide_tray_checkbox.setChecked(self.config.get("hide_tray_icon"))
self.hide_tray_checkbox.stateChanged.connect(self.toggle_tray_icon)
layout.addWidget(self.hide_tray_checkbox)
self.detailed_notifications_checkbox = QCheckBox(self.translator("detailed_notifications"))
self.detailed_notifications_checkbox.setChecked(self.config.get("detailed_notifications"))
self.detailed_notifications_checkbox.stateChanged.connect(self.toggle_detailed_notifications)
layout.addWidget(self.detailed_notifications_checkbox)
self.start_minimized_checkbox = QCheckBox(self.translator("start_minimized"))
self.start_minimized_checkbox.setChecked(self.config.get("start_minimized"))
self.start_minimized_checkbox.stateChanged.connect(self.toggle_start_minimized)
layout.addWidget(self.start_minimized_checkbox)
layout.addSpacing(20)
# Path di salvataggio file
self.path_label = QLabel(self.translator("save_path_label"))
self.path_label.setStyleSheet("font-weight: bold;")
layout.addWidget(self.path_label)
path_layout = QHBoxLayout()
self.path_input = QLineEdit(self.config.get("save_path"))
self.path_input.setReadOnly(True)
path_layout.addWidget(self.path_input)
self.browse_btn = QPushButton(self.translator("browse"))
self.browse_btn.clicked.connect(self.browse_folder)
path_layout.addWidget(self.browse_btn)
layout.addLayout(path_layout)
layout.addStretch()
# Info GitHub
github_layout = QHBoxLayout()
self.github_info_label = QLabel(self.translator("github_info"))
self.github_info_label.setStyleSheet("color: #666; font-size: 10px;")
github_layout.addWidget(self.github_info_label)
self.github_link = QPushButton("⭐ GitHub")
self.github_link.setStyleSheet("color: #0066cc; border: none; text-decoration: underline; font-size: 10px;")
self.github_link.setCursor(Qt.CursorShape.PointingHandCursor)
self.github_link.clicked.connect(self.open_github)
self.github_link.setMaximumWidth(80)
github_layout.addWidget(self.github_link)
github_layout.addStretch()
layout.addLayout(github_layout)
layout.addSpacing(10)
# Pulsanti azione
buttons_layout = QHBoxLayout()
self.open_folder_btn = QPushButton(self.translator("open_folder"))
self.open_folder_btn.clicked.connect(self.open_save_folder)
buttons_layout.addWidget(self.open_folder_btn)
self.info_btn = QPushButton(self.translator("info_button"))
self.info_btn.clicked.connect(self.show_about)
buttons_layout.addWidget(self.info_btn)
self.minimize_btn = QPushButton(self.translator("minimize"))
self.minimize_btn.clicked.connect(self.minimize_to_tray)
buttons_layout.addWidget(self.minimize_btn)
layout.addLayout(buttons_layout)
# Status bar
self.statusBar().showMessage(self.translator("server_running"))
def set_app_icon(self):
"""Imposta l'icona dell'applicazione per finestra e taskbar"""
# Determina la directory del progetto
if getattr(sys, 'frozen', False):
# PyInstaller crea una cartella temporanea e memorizza il percorso in _MEIPASS
if hasattr(sys, '_MEIPASS'):
app_dir = sys._MEIPASS
else:
app_dir = os.path.dirname(sys.executable)
else:
app_dir = os.path.dirname(os.path.abspath(__file__))
icon_path = os.path.join(app_dir, "icons", "icon.ico")
if os.path.exists(icon_path):
# Usa l'icona .ico se esiste
icon = QIcon(icon_path)
self.setWindowIcon(icon)
QApplication.instance().setWindowIcon(icon)
else:
# Fallback: crea icona personalizzata
icon = self.create_fallback_icon()
self.setWindowIcon(icon)
QApplication.instance().setWindowIcon(icon)
def create_fallback_icon(self):
"""Crea un'icona di fallback se icon.ico non esiste"""
pixmap = QPixmap(64, 64)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
# Disegna un cerchio blu
painter.setBrush(QColor(0, 122, 255))
painter.setPen(Qt.PenStyle.NoPen)
painter.drawEllipse(2, 2, 60, 60)
# Disegna le lettere "SE" in bianco
painter.setPen(QColor(255, 255, 255))
from PyQt6.QtGui import QFont
font = QFont("Arial", 24, QFont.Weight.Bold)
painter.setFont(font)
painter.drawText(pixmap.rect(), Qt.AlignmentFlag.AlignCenter, "SE")
painter.end()
return QIcon(pixmap)
def setup_tray_icon(self):
"""Configura l'icona nella system tray"""
# Determina la directory del progetto
if getattr(sys, 'frozen', False):
# PyInstaller crea una cartella temporanea e memorizza il percorso in _MEIPASS
if hasattr(sys, '_MEIPASS'):
app_dir = sys._MEIPASS
else:
app_dir = os.path.dirname(sys.executable)
else:
app_dir = os.path.dirname(os.path.abspath(__file__))
icon_path = os.path.join(app_dir, "icons", "icon.ico")
# Usa icon.ico se esiste, altrimenti crea icona personalizzata
if os.path.exists(icon_path):
icon = QIcon(icon_path)
else:
icon = self.create_fallback_icon()
self.tray_icon = QSystemTrayIcon(icon, self)
# Menu del tray
tray_menu = QMenu()
self.show_action = QAction(self.translator("tray_show"), self)
self.show_action.triggered.connect(self.show_window)
tray_menu.addAction(self.show_action)
self.quit_action = QAction(self.translator("tray_quit"), self)
self.quit_action.triggered.connect(self.quit_application)
tray_menu.addAction(self.quit_action)
self.tray_icon.setContextMenu(tray_menu)
self.tray_icon.setToolTip(self.translator("tray_tooltip"))
self.tray_icon.activated.connect(self.tray_icon_activated)
# NON mostrare/nascondere qui, lo facciamo in run_gui dopo aver controllato start_minimized
def tray_icon_activated(self, reason):
"""Gestisce il click sull'icona del tray"""
if reason == QSystemTrayIcon.ActivationReason.DoubleClick:
self.show_window()
def closeEvent(self, event):
"""Minimizza nella tray invece di chiudere"""
event.ignore()
self.hide()
# Mostra temporaneamente l'icona se era nascosta
if self.config.get("hide_tray_icon"):
self.tray_icon.show()
# Mostra il messaggio
self.tray_icon.showMessage(
self.translator("tray_message_title"),
self.translator("tray_message_text"),
QSystemTrayIcon.MessageIcon.Information,
2000
)
def minimize_to_tray(self):
"""Gestisce la minimizzazione della finestra nella system tray"""
self.hide()
# Mostra temporaneamente l'icona se era nascosta
if self.config.get("hide_tray_icon"):
self.tray_icon.show()
# Mostra il messaggio
self.tray_icon.showMessage(
self.translator("tray_message_title"),
self.translator("tray_message_text"),
QSystemTrayIcon.MessageIcon.Information,
2000
)
def show_window(self):
"""Mostra la finestra e nasconde l'icona se necessario"""
self.show()
self.activateWindow()
# Nascondi l'icona se l'opzione è attiva
if self.config.get("hide_tray_icon"):
self.tray_icon.hide()
def quit_application(self):
"""Chiude completamente l'applicazione"""
QApplication.quit()
def start_server(self):
"""Avvia il server FastAPI"""
share_server = ShareServer(self.config, self.notification_manager, self.translator)
self.server_thread = ServerThread(share_server.app, self.config.get("port"))
self.server_thread.start()
def toggle_copy(self, state):
enabled = state == Qt.CheckState.Checked.value
self.config.set("copy_enabled", enabled)
def toggle_file(self, state):
enabled = state == Qt.CheckState.Checked.value
self.config.set("file_enabled", enabled)
def toggle_notifications(self, state):
enabled = state == Qt.CheckState.Checked.value
self.config.set("notifications_enabled", enabled)
def toggle_autostart(self, state):
enabled = state == Qt.CheckState.Checked.value
if enabled:
if autostart.enable_autostart():
self.config.set("autostart_enabled", True)
else:
self.autostart_checkbox.setChecked(False)
else:
if autostart.disable_autostart():
self.config.set("autostart_enabled", False)
else:
self.autostart_checkbox.setChecked(True)
def toggle_tray_icon(self, state):
"""Mostra o nascondi l'icona nella system tray"""
hide = state == Qt.CheckState.Checked.value
self.config.set("hide_tray_icon", hide)
if hide:
self.tray_icon.hide()
else:
self.tray_icon.show()
def toggle_detailed_notifications(self, state):
"""Abilita/disabilita notifiche dettagliate"""
enabled = state == Qt.CheckState.Checked.value
self.config.set("detailed_notifications", enabled)
def toggle_start_minimized(self, state):
"""Abilita/disabilita avvio ridotto a icona"""
enabled = state == Qt.CheckState.Checked.value
self.config.set("start_minimized", enabled)
# Se attiva "avvia ridotto a icona", assicurati che l'icona sia visibile
# altrimenti l'app diventa inaccessibile
if enabled and self.config.get("hide_tray_icon"):
self.hide_tray_checkbox.setChecked(False)
self.config.set("hide_tray_icon", False)
self.tray_icon.show()
QMessageBox.information(
self,
"iOS-ShareEasy",
"L'icona nella barra delle applicazioni è stata automaticamente riattivata.\n\n"
"Quando avvii l'app ridotta a icona, l'icona deve essere visibile "
"per permetterti di accedere all'applicazione." if self.translator.language == "it" else
"The system tray icon has been automatically re-enabled.\n\n"
"When starting minimized, the tray icon must be visible "
"to allow you to access the application."
)
def browse_folder(self):
folder = QFileDialog.getExistingDirectory(
self,
self.translator("select_folder"),
self.config.get("save_path")
)
if folder:
self.path_input.setText(folder)
self.config.set("save_path", folder)
def open_save_folder(self):
import os
os.startfile(self.config.get("save_path"))
def open_github(self):
"""Apre il repository GitHub nel browser"""
import webbrowser
webbrowser.open("https://github.com/spectreDeveloper/iOS-ShareEasy")
def show_about(self):
"""Mostra il dialog About con informazioni sul progetto"""
msg = QMessageBox(self)
msg.setWindowTitle(self.translator("about_title"))
msg.setTextFormat(Qt.TextFormat.RichText)
msg.setText(self.translator("about_text"))
msg.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
# Connetti i link HTML al browser
def open_link(url):
import webbrowser
webbrowser.open(url.toString())
# Cerca il QTextBrowser nel dialog e connetti linkActivated
for widget in msg.findChildren(QLabel):
if hasattr(widget, 'linkActivated'):
widget.linkActivated.connect(open_link)
msg.exec()
def show_first_run_welcome(self):
"""Mostra il dialogo di benvenuto al primo avvio"""
# Controlla se è il primo avvio
if not self.config.get("first_run"):
return
# Controlla se siamo in esecuzione come .exe
if not getattr(sys, 'frozen', False):
# Se siamo in modalità sviluppo, non mostrare il messaggio
self.config.set("first_run", False)
return
# Controlla se siamo già in Program Files
exe_path = sys.executable
if "Program Files" in exe_path or "Program Files (x86)" in exe_path:
# Già in Program Files, non mostrare il messaggio
self.config.set("first_run", False)
return
# Mostra il dialogo di benvenuto
msg = QMessageBox(self)
msg.setWindowTitle(self.translator("welcome_title"))
msg.setTextFormat(Qt.TextFormat.RichText)
msg.setText(self.translator("welcome_message"))
msg.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.setIcon(QMessageBox.Icon.Information)
# Connetti i link HTML al browser
def open_link(url):
import webbrowser
webbrowser.open(url.toString())
# Cerca il QTextBrowser nel dialog e connetti linkActivated
for widget in msg.findChildren(QLabel):
if hasattr(widget, 'linkActivated'):
widget.linkActivated.connect(open_link)
msg.exec()
# Segna che non è più il primo avvio
self.config.set("first_run", False)
def copy_url(self):
"""Copia l'URL negli appunti"""
import pyperclip
url = f"http://{self.get_local_ip()}:{self.config.get('port')}/share"
pyperclip.copy(url)
self.statusBar().showMessage(self.translator("url_copied"), 3000)
QMessageBox.information(
self,
self.translator("url_copied_title"),
self.translator("url_copied_message", url=url)
)
def change_language(self, index):
"""Cambia la lingua dell'interfaccia"""
lang_code = self.language_combo.itemData(index)
self.translator.set_language(lang_code)
self.config.set("language", lang_code)
# Aggiorna tutte le stringhe dell'interfaccia
self.setWindowTitle(self.translator("window_title"))
self.url_label.setText(self.translator("server_url"))
self.copy_url_btn.setText(self.translator("copy_url"))
self.url_warning.setText(self.translator("url_warning"))
self.copy_checkbox.setText(self.translator("enable_copy"))
self.file_checkbox.setText(self.translator("enable_file"))
self.notification_checkbox.setText(self.translator("enable_notifications"))
self.autostart_checkbox.setText(self.translator("enable_autostart"))
self.hide_tray_checkbox.setText(self.translator("hide_tray_icon"))
self.detailed_notifications_checkbox.setText(self.translator("detailed_notifications"))
self.start_minimized_checkbox.setText(self.translator("start_minimized"))
self.path_label.setText(self.translator("save_path_label"))
self.browse_btn.setText(self.translator("browse"))
self.open_folder_btn.setText(self.translator("open_folder"))
self.info_btn.setText(self.translator("info_button"))
self.minimize_btn.setText(self.translator("minimize"))
self.statusBar().showMessage(self.translator("server_running"))
self.github_info_label.setText(self.translator("github_info"))
# Aggiorna tray menu
self.show_action.setText(self.translator("tray_show"))
self.quit_action.setText(self.translator("tray_quit"))
self.tray_icon.setToolTip(self.translator("tray_tooltip"))
def run_gui():
import os
from datetime import datetime
# Funzione di log interno
log_file = os.path.join(os.path.expanduser("~"), "ios_shareeasy_error.log")
def log(msg):
try:
with open(log_file, 'a', encoding='utf-8') as f:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"[{timestamp}] [GUI] {msg}\n")
except:
pass
log("run_gui() started")
# Crea l'applicazione con una lista vuota se sys.argv causa problemi
try:
argv = sys.argv if sys.argv else ['']
log(f"argv = {argv}")
except Exception as e:
log(f"Error getting argv: {e}")
argv = ['']
log("Creating QApplication...")
try:
app = QApplication(argv)
log("QApplication created successfully")
except Exception as e:
log(f"ERROR creating QApplication: {e}")
raise
log("Setting app properties...")
app.setQuitOnLastWindowClosed(False)
app.setApplicationName("iOS-ShareEasy")
app.setOrganizationName("spectreDeveloper")
log("App properties set")
# Implementa single instance usando QSharedMemory
log("Checking for existing instance...")
shared_memory = QSharedMemory("iOS-ShareEasy-SingleInstance")
if shared_memory.attach():
# Un'altra istanza è già in esecuzione
log("Another instance is already running")
QMessageBox.warning(
None,
"iOS-ShareEasy",
"iOS-ShareEasy è già in esecuzione!\n\nControlla l'icona nella system tray.",
QMessageBox.StandardButton.Ok
)
return 0
if not shared_memory.create(1):
log("Failed to create shared memory")
QMessageBox.critical(
None,
"iOS-ShareEasy - Errore",
"Impossibile avviare l'applicazione.\nUn'altra istanza potrebbe essere già in esecuzione.",
QMessageBox.StandardButton.Ok
)
return 1
log("Single instance check passed")
log("Creating MainWindow...")
try:
window = MainWindow()
log("MainWindow created successfully")
except Exception as e:
log(f"ERROR creating MainWindow: {e}")
import traceback
log(f"Traceback: {traceback.format_exc()}")
raise
log("Checking if should start minimized...")
try:
# Controlla se avviare minimizzato
if window.config.get("start_minimized"):
log("Starting minimized to tray")
# Quando si avvia minimizzato, SEMPRE mostrare l'icona nella tray
# altrimenti l'app diventa invisibile e inaccessibile
window.tray_icon.show()
window.tray_icon.showMessage(
window.translator("tray_message_title"),
window.translator("tray_message_text"),
QSystemTrayIcon.MessageIcon.Information,
2000
)
else:
log("Showing window...")
window.show()
log("Window shown successfully")
# Se la finestra è visibile, rispetta l'impostazione hide_tray_icon
if not window.config.get("hide_tray_icon"):
window.tray_icon.show()
except Exception as e:
log(f"ERROR showing window: {e}")
raise
log("Starting event loop...")
try:
return_code = app.exec()
log(f"Event loop ended with code: {return_code}")
return return_code
except Exception as e:
log(f"ERROR in event loop: {e}")
raise