Skip to content

Commit b06517f

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 fcf28d2 commit b06517f

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")
@@ -561,7 +561,7 @@ def export_webapps(callback, path):
561561
print(e)
562562
result = "error"
563563

564-
callback(result, "export", path)
564+
GLib.idle_add(callback, result, "export", path)
565565

566566
@_async
567567
def import_webapps(callback, path):
@@ -576,12 +576,15 @@ def import_webapps(callback, path):
576576
if file.startswith("applications/"):
577577
# Rewrite the "Exec" section. It will apply the new paths and will search for browsers
578578
path = os.path.join(base_dir, file)
579-
update_imported_desktop(path)
579+
result = update_imported_desktop(path)
580+
if result == "error":
581+
tar.close()
582+
break
580583
except Exception as e:
581584
print(e)
582585
result = "error"
583586

584-
callback(result, "import", path)
587+
GLib.idle_add(callback, result, "import", path)
585588

586589

587590
def get_all_desktop_files():
@@ -601,35 +604,39 @@ def get_codename(path):
601604
return codename
602605

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

634641
if __name__ == "__main__":
635642
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)