fix: resolve UI freeze by separating pystray and tkinter event loops
This commit is contained in:
@@ -42,14 +42,33 @@ class TrayApp:
|
|||||||
self.icon = pystray.Icon("GitMonitor", image, "Git Monitor", menu)
|
self.icon = pystray.Icon("GitMonitor", image, "Git Monitor", menu)
|
||||||
|
|
||||||
def select_repository(self, icon=None, item=None):
|
def select_repository(self, icon=None, item=None):
|
||||||
# Open folder dialog in a separate thread or use the hidden root
|
logger.info("Opening folder selection dialog...")
|
||||||
# tkinter dialogs need to run in the main thread or with care
|
# Use a temporary function to run in a way that doesn't block
|
||||||
repo_path = filedialog.askdirectory(title="Select Git Repository Folder")
|
def ask_folder():
|
||||||
if repo_path:
|
try:
|
||||||
logger.info(f"User selected repository: {repo_path}")
|
# Ensure the root window is focused and on top
|
||||||
if git_manager.load_repository(repo_path):
|
self.root.deiconify()
|
||||||
config.repository_path = repo_path
|
self.root.attributes("-topmost", True)
|
||||||
self.start_monitoring(repo_path)
|
|
||||||
|
repo_path = filedialog.askdirectory(
|
||||||
|
parent=self.root,
|
||||||
|
title="Select Git Repository Folder"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.root.withdraw()
|
||||||
|
|
||||||
|
if repo_path:
|
||||||
|
logger.info(f"User selected repository: {repo_path}")
|
||||||
|
if git_manager.load_repository(repo_path):
|
||||||
|
config.repository_path = repo_path
|
||||||
|
self.start_monitoring(repo_path)
|
||||||
|
else:
|
||||||
|
logger.info("Folder selection cancelled by user.")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in folder selection: {e}")
|
||||||
|
|
||||||
|
# Schedule the dialog to run
|
||||||
|
self.root.after(0, ask_folder)
|
||||||
|
|
||||||
def start_monitoring(self, path):
|
def start_monitoring(self, path):
|
||||||
if self.watcher:
|
if self.watcher:
|
||||||
@@ -75,7 +94,10 @@ class TrayApp:
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.create_icon()
|
self.create_icon()
|
||||||
self.icon.run()
|
# Run pystray in a separate thread
|
||||||
|
threading.Thread(target=self.icon.run, daemon=True).start()
|
||||||
|
# Keep the main thread for tkinter mainloop to handle dialogs
|
||||||
|
self.root.mainloop()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = TrayApp()
|
app = TrayApp()
|
||||||
|
|||||||
Reference in New Issue
Block a user