Compare commits
7 Commits
bd2b87fd51
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3206363a88 | |||
| 5d655e4207 | |||
| 692ea1b1ed | |||
| e621ac04f7 | |||
| 7241974d8b | |||
| 10385bb1c2 | |||
| 5f7649867b |
27
gemini.md
27
gemini.md
@@ -10,8 +10,6 @@ The application runs **silently in the background** with a **system tray icon**
|
||||
|
||||
The final application must be packaged using **PyInstaller as a single executable file** with **no console window**.
|
||||
|
||||
---
|
||||
|
||||
# Core Features
|
||||
|
||||
## Background Operation
|
||||
@@ -25,7 +23,6 @@ The tray icon menu must contain:
|
||||
* **Select Repository Folder**
|
||||
* **Exit Application**
|
||||
|
||||
---
|
||||
|
||||
# Git Monitoring Behavior
|
||||
|
||||
@@ -33,7 +30,11 @@ The application monitors a selected folder that contains a **Git repository**.
|
||||
|
||||
Every filesystem change triggers an automatic commit.
|
||||
|
||||
### .gitignore Support
|
||||
The application respects `.gitignore` rules of the repository. Files matched by ignore rules will not trigger any actions or commits.
|
||||
|
||||
The following actions must be detected:
|
||||
...
|
||||
|
||||
* File created
|
||||
* File modified
|
||||
@@ -55,15 +56,13 @@ delete: old_part.nc
|
||||
rename: part_v1.nc -> part_v2.nc
|
||||
```
|
||||
|
||||
### Git Operations
|
||||
Commits must be executed automatically using Git.
|
||||
|
||||
If the directory is not a Git repository, the application should:
|
||||
|
||||
* notify the user
|
||||
* not start monitoring
|
||||
|
||||
---
|
||||
|
||||
# Windows Notifications
|
||||
|
||||
The application should generate **Windows toast notifications** for:
|
||||
@@ -78,6 +77,7 @@ Example notification:
|
||||
```
|
||||
Git Monitor
|
||||
modify: program.nc committed
|
||||
```
|
||||
|
||||
# Logging
|
||||
|
||||
@@ -101,8 +101,6 @@ Logged events:
|
||||
* git commit executed
|
||||
* errors and exceptions
|
||||
|
||||
---
|
||||
|
||||
# System Tray UI
|
||||
|
||||
The application must provide a **tray icon**.
|
||||
@@ -131,8 +129,6 @@ Once selected:
|
||||
|
||||
Stops monitoring and terminates the application.
|
||||
|
||||
---
|
||||
|
||||
# Application Architecture
|
||||
|
||||
The application must be **modular** and structured using classes.
|
||||
@@ -151,8 +147,6 @@ config.py
|
||||
logger.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Modules
|
||||
|
||||
## main.py
|
||||
@@ -171,8 +165,6 @@ Main class:
|
||||
Application
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# tray_app.py
|
||||
|
||||
Handles the **system tray icon and menu**.
|
||||
@@ -204,8 +196,6 @@ stop_monitoring()
|
||||
exit_app()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# file_watcher.py
|
||||
|
||||
Responsible for filesystem monitoring.
|
||||
@@ -237,8 +227,6 @@ on_deleted
|
||||
on_moved
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# git_manager.py
|
||||
|
||||
Handles all Git operations.
|
||||
@@ -274,7 +262,6 @@ Commit format:
|
||||
f"{action}: {file}"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# notifier.py
|
||||
|
||||
@@ -347,8 +334,6 @@ Example:
|
||||
|
||||
The application is fully implemented and tested for Windows 11 background operation.
|
||||
|
||||
---
|
||||
|
||||
# Current Architecture (Finalized)
|
||||
|
||||
The project is structured as a proper Python package to ensure compatibility with PyInstaller and robust path handling.
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import time
|
||||
import os
|
||||
import threading
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from git_monitor.logger import logger
|
||||
from git_monitor.git_manager import git_manager
|
||||
from git_monitor.notifier import notifier
|
||||
|
||||
class RepositoryWatcher:
|
||||
def __init__(self, path):
|
||||
@@ -43,22 +45,35 @@ class GitEventHandler(FileSystemEventHandler):
|
||||
self.handle_event(event, action, custom_file_name=file_name)
|
||||
|
||||
def handle_event(self, event, action, custom_file_name=None):
|
||||
# Ignore .git directory and the log file
|
||||
file_path = event.src_path if action != "rename" else event.dest_path
|
||||
file_name = os.path.basename(file_path)
|
||||
|
||||
# Check if any part of the path is .git
|
||||
if ".git" in file_path.split(os.sep) or file_name == "git_monitor.log":
|
||||
return
|
||||
|
||||
if git_manager.is_ignored(file_path):
|
||||
logger.info(f"Ignored: {file_path} (matches .gitignore)")
|
||||
return
|
||||
|
||||
display_name = custom_file_name if custom_file_name else file_name
|
||||
logger.info(f"File event: {action} on {display_name}")
|
||||
|
||||
logger.info(f"Change detected: {action} on {display_name}")
|
||||
|
||||
repo_root = git_manager.repo_path
|
||||
if repo_root:
|
||||
if custom_file_name:
|
||||
# For renames, we use the custom format provided
|
||||
git_manager.commit_change(action, custom_file_name)
|
||||
else:
|
||||
rel_path = os.path.relpath(file_path, repo_root)
|
||||
rel_path = os.path.relpath(file_path, repo_root) if not custom_file_name else custom_file_name
|
||||
|
||||
# Interactive notification instead of immediate commit
|
||||
def save_now():
|
||||
git_manager.commit_change(action, rel_path)
|
||||
|
||||
def ask_later():
|
||||
logger.info(f"User deferred change: {rel_path} for 5 minutes.")
|
||||
# Reschedule the same event after 5 minutes (300 seconds)
|
||||
threading.Timer(300, self.handle_event, [event, action, custom_file_name]).start()
|
||||
|
||||
notifier.notify_interactive(
|
||||
"Zmiana wykryta!",
|
||||
f"Wykryto zmianę: {action}: {display_name}. Co chcesz zrobić?",
|
||||
on_save=save_now,
|
||||
on_later=ask_later
|
||||
)
|
||||
|
||||
@@ -34,6 +34,18 @@ class GitManager:
|
||||
except (exc.InvalidGitRepositoryError, exc.NoSuchPathError):
|
||||
return False
|
||||
|
||||
def is_ignored(self, file_path):
|
||||
"""Check if a file is ignored by .gitignore rules."""
|
||||
if not self.repo:
|
||||
return False
|
||||
try:
|
||||
# git check-ignore returns the path if it is ignored
|
||||
ignored_files = self.repo.ignored(file_path)
|
||||
return len(ignored_files) > 0
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking ignore status for {file_path}: {e}")
|
||||
return False
|
||||
|
||||
def commit_change(self, action, file_name):
|
||||
if not self.repo:
|
||||
logger.error("No repository loaded for commit.")
|
||||
|
||||
@@ -1,45 +1,93 @@
|
||||
import threading
|
||||
from git_monitor.logger import logger
|
||||
|
||||
# Modern Windows 10/11 toasts with buttons
|
||||
try:
|
||||
from windows_toasts import WindowsToaster, ToastText2, ToastActivatedEventArgs, ToastButton
|
||||
WINDOWS_TOASTS_AVAILABLE = True
|
||||
toaster = WindowsToaster('Git Monitor')
|
||||
except ImportError:
|
||||
logger.warning("windows-toasts not found. Interactive buttons will not be available.")
|
||||
WINDOWS_TOASTS_AVAILABLE = False
|
||||
|
||||
# Fallbacks
|
||||
try:
|
||||
from plyer import notification
|
||||
PLYER_AVAILABLE = True
|
||||
except ImportError:
|
||||
logger.warning("plyer not found. Will try win10toast.")
|
||||
PLYER_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from win10toast import ToastNotifier
|
||||
WIN10TOAST_AVAILABLE = True
|
||||
toaster = ToastNotifier()
|
||||
legacy_toaster = ToastNotifier()
|
||||
except ImportError:
|
||||
WIN10TOAST_AVAILABLE = False
|
||||
|
||||
class Notifier:
|
||||
def notify(self, title, message):
|
||||
"""Simple notification (no buttons)."""
|
||||
logger.info(f"Notification: {title} - {message}")
|
||||
|
||||
# Try plyer first
|
||||
if WINDOWS_TOASTS_AVAILABLE:
|
||||
try:
|
||||
toast = ToastText2()
|
||||
toast.headline = title
|
||||
toast.body = message
|
||||
toaster.show_toast(toast)
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(f"windows-toasts simple notification failed: {e}")
|
||||
|
||||
# Fallback to older libraries
|
||||
if PLYER_AVAILABLE:
|
||||
try:
|
||||
notification.notify(
|
||||
title=title,
|
||||
message=message,
|
||||
app_name="Git Monitor"
|
||||
)
|
||||
notification.notify(title=title, message=message, app_name="Git Monitor")
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(f"Plyer notification failed: {e}. Trying fallback...")
|
||||
except: pass
|
||||
|
||||
# Fallback to win10toast
|
||||
if WIN10TOAST_AVAILABLE:
|
||||
try:
|
||||
# threaded=True prevents blocking the app
|
||||
toaster.show_toast(title, message, duration=5, threaded=True)
|
||||
legacy_toaster.show_toast(title, message, duration=5, threaded=True)
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(f"win10toast notification failed: {e}")
|
||||
except: pass
|
||||
|
||||
# Final fallback to stdout
|
||||
print(f"[{title}] {message}")
|
||||
def notify_interactive(self, title, message, on_save, on_later):
|
||||
"""Interactive notification with 'Save now' and 'Ask in 5 min' buttons."""
|
||||
logger.info(f"Interactive Notification: {title} - {message}")
|
||||
|
||||
if not WINDOWS_TOASTS_AVAILABLE:
|
||||
logger.warning("Interactive notifications not available, performing default action (Save).")
|
||||
on_save()
|
||||
return
|
||||
|
||||
try:
|
||||
toast = ToastText2()
|
||||
toast.headline = title
|
||||
toast.body = message
|
||||
|
||||
# Action buttons
|
||||
toast.AddAction(ToastButton("Zapisz teraz", "save"))
|
||||
toast.AddAction(ToastButton("Zapytaj mnie za 5 min", "later"))
|
||||
|
||||
# Handler for button clicks
|
||||
def on_activated(args: ToastActivatedEventArgs):
|
||||
if args.arguments == "save":
|
||||
logger.info("User clicked 'Zapisz teraz'")
|
||||
on_save()
|
||||
elif args.arguments == "later":
|
||||
logger.info("User clicked 'Zapytaj mnie za 5 min'")
|
||||
on_later()
|
||||
else:
|
||||
# Default click on toast body
|
||||
on_save()
|
||||
|
||||
toast.on_activated = on_activated
|
||||
toaster.show_toast(toast)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Interactive notification error: {e}")
|
||||
# Fallback to immediate save if notification fails
|
||||
on_save()
|
||||
|
||||
notifier = Notifier()
|
||||
|
||||
@@ -4,3 +4,4 @@ pystray
|
||||
Pillow
|
||||
plyer
|
||||
win10toast
|
||||
windows-toasts
|
||||
|
||||
Reference in New Issue
Block a user