Added Add desktop shortcut option to Linux version

This commit is contained in:
Deniz Şafak
2025-05-09 20:39:28 +03:00
parent 9c997c9616
commit 11caeedef5
2 changed files with 86 additions and 32 deletions
+1
View File
@@ -7,6 +7,7 @@
- Added `Save in a project folder with metadata` option in the book handler, allowing users to save the converted items in a project folder with available metadata files. Useful if you want to work with the converted files in the future, issue mentioned by @Darthagnon in #15 - Added `Save in a project folder with metadata` option in the book handler, allowing users to save the converted items in a project folder with available metadata files. Useful if you want to work with the converted files in the future, issue mentioned by @Darthagnon in #15
- Added `Go to folder` button in input box, allowing users to open the folder containing the converted file. - Added `Go to folder` button in input box, allowing users to open the folder containing the converted file.
- Added `.opus` as output format for generated audio files, which is a more efficient format for audio files. - Added `.opus` as output format for generated audio files, which is a more efficient format for audio files.
- Added `Add desktop shortcut` option to Linux version, allowing users to create a shortcut on their desktop for easy access.
- Added "Playing..." indicator for "Preview" button in the voice mixer. - Added "Playing..." indicator for "Preview" button in the voice mixer.
# v1.0.6 # v1.0.6
+56 -3
View File
@@ -1805,8 +1805,8 @@ class abogen(QWidget):
# Add seperator # Add seperator
menu.addSeparator() menu.addSeparator()
# Add shortcut to desktop (Windows only) # Add shortcut to desktop (Windows or Linux)
if platform.system() == "Windows": if platform.system() == "Windows" or platform.system() == "Linux":
add_shortcut_action = QAction("Create desktop shortcut", self) add_shortcut_action = QAction("Create desktop shortcut", self)
add_shortcut_action.triggered.connect(self.add_shortcut_to_desktop) add_shortcut_action.triggered.connect(self.add_shortcut_to_desktop)
menu.addAction(add_shortcut_action) menu.addAction(add_shortcut_action)
@@ -1885,6 +1885,7 @@ class abogen(QWidget):
from utils import create_process from utils import create_process
try: try:
if platform.system() == "Windows":
# where to put the .lnk # where to put the .lnk
desktop = user_desktop_dir() desktop = user_desktop_dir()
shortcut_path = os.path.join(desktop, "abogen.lnk") shortcut_path = os.path.join(desktop, "abogen.lnk")
@@ -1925,13 +1926,65 @@ class abogen(QWidget):
"Shortcut Error", "Shortcut Error",
f"PowerShell failed with exit code: {proc.returncode}" f"PowerShell failed with exit code: {proc.returncode}"
) )
elif platform.system() == "Linux":
desktop = user_desktop_dir()
if not desktop or not os.path.isdir(desktop): # Fallback if platformdirs fails or path is not a dir
QMessageBox.critical(
self, "Shortcut Error", "Could not determine desktop directory."
)
return
shortcut_path = os.path.join(desktop, "abogen.desktop")
python_dir = os.path.dirname(sys.executable)
# Common path for pip-installed executables on Linux
target = os.path.join(python_dir, "bin", "abogen")
if not os.path.exists(target):
# Fallback for some environments like venv where it might be directly in python_dir
target_fallback = os.path.join(python_dir, "abogen")
if os.path.exists(target_fallback):
target = target_fallback
else:
QMessageBox.critical(
self, "Shortcut Error", f"Could not find abogen executable in common paths:\n{target}\n{target_fallback}"
)
return
icon_path = get_resource_path("abogen.assets", "icon.png")
if not os.path.exists(icon_path):
icon_path = ""
desktop_entry_content = f"""[Desktop Entry]
Version={VERSION}
Name={PROGRAM_NAME}
Comment={PROGRAM_DESCRIPTION}
Exec={target}
Icon={icon_path}
Terminal=false
Type=Application
Categories=AudioVideo;Audio;Utility;
"""
with open(shortcut_path, "w", encoding="utf-8") as f:
f.write(desktop_entry_content)
os.chmod(shortcut_path, 0o755) # Make it executable
QMessageBox.information(
self,
"Shortcut Created",
f"Shortcut created on desktop:\n{shortcut_path}",
)
else:
QMessageBox.information(
self, "Unsupported OS", "Desktop shortcut creation is not supported on this operating system."
)
except Exception as e: except Exception as e:
QMessageBox.critical( QMessageBox.critical(
self, "Shortcut Error", f"Could not create shortcut:\n{e}" self, "Shortcut Error", f"Could not create shortcut:\n{e}"
) )
def toggle_check_updates(self, checked): def toggle_check_updates(self, checked):
self.config["check_updates"] = checked self.config["check_updates"] = checked
save_config(self.config) save_config(self.config)