diff --git a/dzgui/config/freedesktop.py b/dzgui/config/freedesktop.py index 6ae7ba8..edad06f 100644 --- a/dzgui/config/freedesktop.py +++ b/dzgui/config/freedesktop.py @@ -1,10 +1,15 @@ +import stat import textwrap from pathlib import Path +from dzgui.const.constants import APP_NAME from dzgui.util.dirs import copy_dzgui_to_xdg_data, find_icon_resource, make_parents +def get_share_path(exe_path: Path) -> Path: + return exe_path.parent.parent + def write_desktop_file(exe_path: Path) -> None: icon = find_icon_resource() @@ -21,13 +26,17 @@ def write_desktop_file(exe_path: Path) -> None: copy_dzgui_to_xdg_data(exe_path) - share_path = exe_path.parent.parent - file = share_path.joinpath("applications/dzgui.desktop") - make_parents(file) - file.write_text(textwrap.dedent(template)) + share_path = get_share_path(exe_path) + desktop_file = share_path.joinpath("applications/dzgui.desktop") + make_parents(desktop_file) + desktop_file.write_text(textwrap.dedent(template)) + desktop_file.chmod(desktop_file.stat().st_mode | stat.S_IEXEC) + return desktop_file -def write_desktop_shortcut(exe_path: Path) -> None: - # TODO: symlink the above, /Desktop - # TODO: dynamically link to prior option in UI - pass +def write_desktop_shortcut(desktop_file: Path) -> None: + # NOTE: necessarily depends on the above (UI blocks creation without XDG entry first) + link = Path.home().joinpath(f"Desktop/{APP_NAME}.desktop") + if link.exists(): + link.unlink() + link.symlink_to(desktop_file)