fix: prevent operations with files that no longer exist
This commit is contained in:
@@ -84,6 +84,13 @@ class MenuApp(App[None]):
|
|||||||
self.current_index = 0
|
self.current_index = 0
|
||||||
self.display_current_file()
|
self.display_current_file()
|
||||||
|
|
||||||
|
def assert_current_file_exists(self) -> bool:
|
||||||
|
"""Check if the current file exists and update the status label accordingly."""
|
||||||
|
if not self.current_file or not self.current_file.exists():
|
||||||
|
self.query_one("#status", Label).update(f"❌ File '{self.current_file}' not found")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def display_current_file(self) -> None:
|
def display_current_file(self) -> None:
|
||||||
"""Display the current file based on current_index."""
|
"""Display the current file based on current_index."""
|
||||||
if not self.usable_files or self.current_index >= len(self.usable_files):
|
if not self.usable_files or self.current_index >= len(self.usable_files):
|
||||||
@@ -123,6 +130,9 @@ class MenuApp(App[None]):
|
|||||||
if not self.current_file:
|
if not self.current_file:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.assert_current_file_exists():
|
||||||
|
return
|
||||||
|
|
||||||
self.query_one("#status", Label).update(f"📝 Open {self.current_file}")
|
self.query_one("#status", Label).update(f"📝 Open {self.current_file}")
|
||||||
try:
|
try:
|
||||||
if self.use_geeqie and str(self.current_file).lower().endswith(tuple(IMG_EXTENSIONS)):
|
if self.use_geeqie and str(self.current_file).lower().endswith(tuple(IMG_EXTENSIONS)):
|
||||||
@@ -139,6 +149,9 @@ class MenuApp(App[None]):
|
|||||||
if not self.current_file:
|
if not self.current_file:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.assert_current_file_exists():
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.query_one("#status", Label).update(f"⏳ Uploading {self.current_file.name} to webhook...")
|
self.query_one("#status", Label).update(f"⏳ Uploading {self.current_file.name} to webhook...")
|
||||||
upload_file(self.current_file)
|
upload_file(self.current_file)
|
||||||
@@ -151,6 +164,9 @@ class MenuApp(App[None]):
|
|||||||
if not self.current_file or self.current_index >= len(self.usable_files):
|
if not self.current_file or self.current_index >= len(self.usable_files):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.assert_current_file_exists():
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.current_file.unlink()
|
self.current_file.unlink()
|
||||||
_ = self.usable_files.pop(self.current_index)
|
_ = self.usable_files.pop(self.current_index)
|
||||||
@@ -172,6 +188,9 @@ class MenuApp(App[None]):
|
|||||||
if not self.current_file or self.current_index >= len(self.usable_files):
|
if not self.current_file or self.current_index >= len(self.usable_files):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.assert_current_file_exists():
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
move_file_to_move_folder(self.current_file)
|
move_file_to_move_folder(self.current_file)
|
||||||
_ = self.usable_files.pop(self.current_index)
|
_ = self.usable_files.pop(self.current_index)
|
||||||
@@ -193,6 +212,9 @@ class MenuApp(App[None]):
|
|||||||
if not self.current_file:
|
if not self.current_file:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.assert_current_file_exists():
|
||||||
|
return
|
||||||
|
|
||||||
open_file_in_dolphin(self.current_file)
|
open_file_in_dolphin(self.current_file)
|
||||||
self.query_one("#status", Label).update("📂 Opened file in folder")
|
self.query_one("#status", Label).update("📂 Opened file in folder")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user