Skip to content

Commit 1f16845

Browse files
committed
feature "import/export" (4th iteration)
- bug fix: application crash It now uses GLib.idle_add() to prevent the "Segmentation fault (core dumped)" error in GTK3 - try catch in update_imported_desktop()
1 parent e9dd83c commit 1f16845

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

usr/lib/webapp-manager/common.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def wrapper(*args):
5050
_ = gettext.gettext
5151

5252
# Constants
53-
ICE_DIR = os.path.expanduser("~/.local/share/ice")
54-
APPS_DIR = os.path.expanduser("~/.local/share/applications")
53+
ICE_DIR = os.path.expanduser("/home/jannik/Programmieren/Python/LinuxMint/Local_Files/ice")
54+
APPS_DIR = os.path.expanduser("/home/jannik/Programmieren/Python/LinuxMint/Local_Files/applications")
5555
PROFILES_DIR = os.path.join(ICE_DIR, "profiles")
5656
FIREFOX_PROFILES_DIR = os.path.join(ICE_DIR, "firefox")
5757
FIREFOX_FLATPAK_PROFILES_DIR = os.path.expanduser("~/.var/app/org.mozilla.firefox/data/ice/firefox")
@@ -567,7 +567,7 @@ def export_webapps(callback, path):
567567
print(e)
568568
result = "error"
569569

570-
callback(result, "export", path)
570+
GLib.idle_add(callback, result, "export", path)
571571

572572
@_async
573573
def import_webapps(callback, path):
@@ -582,12 +582,15 @@ def import_webapps(callback, path):
582582
if file.startswith("applications/"):
583583
# Rewrite the "Exec" section. It will apply the new paths and will search for browsers
584584
path = os.path.join(base_dir, file)
585-
update_imported_desktop(path)
585+
result = update_imported_desktop(path)
586+
if result == "error":
587+
tar.close()
588+
break
586589
except Exception as e:
587590
print(e)
588591
result = "error"
589592

590-
callback(result, "import", path)
593+
GLib.idle_add(callback, result, "import", path)
591594

592595

593596
def get_all_desktop_files():
@@ -607,35 +610,39 @@ def get_codename(path):
607610
return codename
608611

609612
def update_imported_desktop(path):
610-
webapp = WebAppLauncher(path, get_codename(path))
611-
if "/" in webapp.icon:
612-
# Update Icon Path
613-
iconpath = os.path.join(ICONS_DIR, os.path.basename(webapp.icon))
614-
else:
615-
iconpath = webapp.icon
616-
617-
# Check if the browser is installed
618-
browsers = WebAppManager.get_supported_browsers()
619-
configured_browser = next((browser for browser in browsers if browser.name == webapp.web_browser), None)
620-
if os.path.exists(configured_browser.test_path) == False:
621-
# If the browser is not installed, search another browser.
622-
# 1. Sort browsers by same browser type
623-
# 2. Sort the browsers by similarity of the name of the missing browser
624-
similar_browsers = browsers
625-
similar_browsers.sort(key=lambda browser: (
626-
browser.browser_type == configured_browser.browser_type,
627-
configured_browser.name.split(" ")[0].lower() not in browser.name.lower()
628-
))
629-
configured_browser = None
630-
for browser in similar_browsers:
631-
if os.path.exists(browser.test_path):
632-
configured_browser = browser
633-
break
634-
635-
print(webapp.web_browser, "-Browser not installed")
636-
637-
WebAppManager.edit_webapp(WebAppManager, path, webapp.name, configured_browser, webapp.url, iconpath, webapp.category,
638-
webapp.custom_parameters, webapp.codename, webapp.isolate_profile, webapp.navbar, webapp.privatewindow)
613+
try:
614+
webapp = WebAppLauncher(path, get_codename(path))
615+
if "/" in webapp.icon:
616+
# Update Icon Path
617+
iconpath = os.path.join(ICONS_DIR, os.path.basename(webapp.icon))
618+
else:
619+
iconpath = webapp.icon
620+
621+
# Check if the browser is installed
622+
browsers = WebAppManager.get_supported_browsers()
623+
configured_browser = next((browser for browser in browsers if browser.name == webapp.web_browser), None)
624+
if os.path.exists(configured_browser.test_path) == False:
625+
# If the browser is not installed, search another browser.
626+
# 1. Sort browsers by same browser type
627+
# 2. Sort the browsers by similarity of the name of the missing browser
628+
similar_browsers = browsers
629+
similar_browsers.sort(key=lambda browser: (
630+
browser.browser_type == configured_browser.browser_type,
631+
configured_browser.name.split(" ")[0].lower() not in browser.name.lower()
632+
))
633+
configured_browser = None
634+
for browser in similar_browsers:
635+
if os.path.exists(browser.test_path):
636+
configured_browser = browser
637+
break
638+
639+
print(webapp.web_browser, "-Browser not installed")
640+
641+
WebAppManager.edit_webapp(WebAppManager, path, webapp.name, configured_browser, webapp.url, iconpath, webapp.category,
642+
webapp.custom_parameters, webapp.codename, webapp.isolate_profile, webapp.navbar, webapp.privatewindow)
643+
return "ok"
644+
except:
645+
return "error"
639646

640647
if __name__ == "__main__":
641648
download_favicon(sys.argv[1])

usr/lib/webapp-manager/webapp-manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def show_ei_result(self, result, task, path):
588588
# This dialog box gives users the option to open the containing directory.
589589
title = _("Export completed!")
590590
button_text = _("Open Containing Folder")
591-
dialog = Gtk.Dialog(title, self.window, None, (button_text, 10, Gtk.STOCK_OK, Gtk.ButtonsType.OK))
591+
dialog = Gtk.Dialog(title, self.window, None, (button_text, 10, Gtk.STOCK_OK, Gtk.ResponseType.OK))
592592
dialog.get_content_area().add(Gtk.Label(label=_("WebApps have been exported successfully.")))
593593
dialog.show_all()
594594
result = dialog.run()

0 commit comments

Comments
 (0)