diff --git a/frappe/hooks.py b/frappe/hooks.py index b8c3932fdb..8ad4e53368 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -17,6 +17,7 @@ before_install = "frappe.utils.install.before_install" after_install = "frappe.utils.install.after_install" after_app_install = "frappe.utils.install.auto_generate_icons_and_sidebar" +after_app_uninstall = "frappe.utils.install.delete_desktop_icon" page_js = {"setup-wizard": "public/js/frappe/setup_wizard.js"} diff --git a/frappe/utils/install.py b/frappe/utils/install.py index 3a580d853f..a2af780b65 100644 --- a/frappe/utils/install.py +++ b/frappe/utils/install.py @@ -2,6 +2,8 @@ # License: MIT. See LICENSE import getpass +import click + import frappe from frappe.geo.doctype.country.country import import_country_and_currency from frappe.utils import cint @@ -196,3 +198,20 @@ def auto_generate_icons_and_sidebar(app_name=None): frappe.db.commit() # nosemgrep except Exception as e: print(f"Error creating icons {e}") + + +def delete_desktop_icon(app_name): + frappe.get_hooks(app_name=app_name) + app_title = frappe.get_hooks(app_name=app_name)["app_title"][0] + icons_to_be_deleted = frappe.get_all( + "Desktop Icon", + pluck="name", + or_filters=[ + ["Desktop Icon", "name", "=", app_title], + ["Desktop Icon", "parent_icon", "=", app_title], + ], + ) + print("Deleting Desktop Icons") + for icon in icons_to_be_deleted: + frappe.delete_doc_if_exists("Desktop Icon", icon) + frappe.db.commit()