Skip to content

Commit

Permalink
fixed error when application folder does not exists yes
Browse files Browse the repository at this point in the history
  • Loading branch information
mijorus committed Sep 3, 2023
1 parent a1bce88 commit 38f8502
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/providers/AppImageProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __init__(self):

self.extraction_folder = GLib.get_tmp_dir() + '/it.mijorus.gearlever/appimages'
self.user_desktop_files_path = f'{GLib.get_home_dir()}/.local/share/applications'
self.user_local_share_path = f'{GLib.get_home_dir()}/.local/share/'


def list_installed(self) -> List[AppImageListElement]:
default_folder_path = self._get_appimages_default_destination_path()
Expand Down Expand Up @@ -229,6 +231,7 @@ def install_file(self, el: AppImageListElement):
safe_app_name = 'gearlever_' + extracted_appimage.desktop_entry.getName()

safe_app_name = re.sub(r"[^A-Za-z0-9_]+", "", safe_app_name).lower() + '_' + extracted_appimage.md5[0:6] + '.appimage'
app_name_without_ext = re.sub(r'(_\d+)?\.appimage', '', safe_app_name)

append_file_ext = True
if extracted_appimage.desktop_entry and get_gsettings().get_boolean('exec-as-name-for-terminal-apps') and extracted_appimage.desktop_entry.getTerminal():
Expand All @@ -240,7 +243,7 @@ def install_file(self, el: AppImageListElement):

i = 1
while safe_app_name in os.listdir(self._get_appimages_default_destination_path()):
safe_app_name = re.sub(r'(_\d+)?\.appimage', '', safe_app_name) + f'_{i}' + ('.appimage' if append_file_ext else '')
safe_app_name = app_name_without_ext + f'_{i}' + ('.appimage' if append_file_ext else '')
i += 1

dest_appimage_file = Gio.File.new_for_path(appimages_destination_path + '/' + safe_app_name)
Expand All @@ -263,11 +266,11 @@ def install_file(self, el: AppImageListElement):
if not os.path.exists(f'{appimages_destination_path}/.icons'):
os.mkdir(f'{appimages_destination_path}/.icons')

dest_appimage_icon_file = Gio.File.new_for_path(f'{appimages_destination_path}/.icons/{safe_app_name}')
dest_appimage_icon_file = Gio.File.new_for_path(f'{appimages_destination_path}/.icons/{app_name_without_ext}')
gio_copy(icon_file, dest_appimage_icon_file)

# Move .desktop file to its default location
dest_destop_file_path = f'{self.user_desktop_files_path}/{safe_app_name}.desktop'
dest_destop_file_path = f'{self.user_desktop_files_path}/{app_name_without_ext}.desktop'
dest_destop_file_path = dest_destop_file_path.replace(' ', '_')

with open(extracted_appimage.desktop_file.get_path(), 'r') as dskt_file:
Expand Down Expand Up @@ -327,6 +330,9 @@ def install_file(self, el: AppImageListElement):
)

# finally, write the new .desktop file
if (not os.path.exists(self.user_desktop_files_path)) and os.path.exists(self.user_local_share_path):
os.mkdir(self.user_desktop_files_path)

with open(dest_destop_file_path, 'w+') as desktop_file_python_dest:
desktop_file_python_dest.write(desktop_file_content)

Expand Down

0 comments on commit 38f8502

Please sign in to comment.