diff --git a/frappe/hooks.py b/frappe/hooks.py index 28ba377793..070e7f5ba0 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -35,6 +35,7 @@ app_include_css = [ "desk.bundle.css", "report.bundle.css", ] +app_include_icons = ["frappe/public/icons/timeless/icons.svg"] doctype_js = { "Web Page": "public/js/frappe/utils/web_template.js", diff --git a/frappe/public/icons/timeless/test.svg b/frappe/public/icons/timeless/test.svg new file mode 100644 index 0000000000..9563c827fd --- /dev/null +++ b/frappe/public/icons/timeless/test.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/frappe/public/js/frappe/form/controls/icon.js b/frappe/public/js/frappe/form/controls/icon.js index 89abb82114..f3386ed813 100644 --- a/frappe/public/js/frappe/form/controls/icon.js +++ b/frappe/public/js/frappe/form/controls/icon.js @@ -10,7 +10,7 @@ frappe.ui.form.ControlIcon = class ControlIcon extends frappe.ui.form.ControlDat get_all_icons() { frappe.symbols = []; - $("#frappe-symbols > symbol[id]").each(function () { + $("#all-symbols > svg > symbol[id]").each(function () { this.id.includes("icon-") && frappe.symbols.push(this.id.replace("icon-", "")); }); } diff --git a/frappe/tests/test_website.py b/frappe/tests/test_website.py index b7b33b3531..279252865c 100644 --- a/frappe/tests/test_website.py +++ b/frappe/tests/test_website.py @@ -391,6 +391,27 @@ class TestWebsite(FrappeTestCase): delattr(frappe.local, "request") frappe.set_user("Guest") + def test_include_icons(self): + from frappe import get_hooks + + TEST_ICONS_PATH = "frappe/public/icons/timeless/test.svg" + + def patched_get_hooks(*args, **kwargs): + return_value = get_hooks(*args, **kwargs) + if isinstance(return_value, dict) and "app_include_icons" in return_value: + return_value.app_include_icons.append(TEST_ICONS_PATH) + return return_value + + with patch.object(frappe, "get_hooks", patched_get_hooks): + frappe.set_user("Administrator") + + set_request(method="GET", path="/app") + content = get_response_content("/app") + # icon is available in a symbol tag + self.assertIn('id="icon-TEST-ONLY"', content) + delattr(frappe.local, "request") + frappe.set_user("Guest") + def patched_get_hooks(hook, value): def wrapper(*args, **kwargs): diff --git a/frappe/utils/boilerplate.py b/frappe/utils/boilerplate.py index 85bf3d6f8c..f3a9d39190 100644 --- a/frappe/utils/boilerplate.py +++ b/frappe/utils/boilerplate.py @@ -365,6 +365,11 @@ app_license = "{app_license}" # doctype_tree_js = {{"doctype" : "public/js/doctype_tree.js"}} # doctype_calendar_js = {{"doctype" : "public/js/doctype_calendar.js"}} +# Svg Icons +# ------------------ +# include app icons in desk +# app_include_icons = "{app_name}/public/icons.svg" + # Home Pages # ---------- diff --git a/frappe/www/app.html b/frappe/www/app.html index ceceaf3219..14399bc2d5 100644 --- a/frappe/www/app.html +++ b/frappe/www/app.html @@ -25,7 +25,11 @@ {%- endfor -%} - {% include "public/icons/timeless/icons.svg" %} +
+ {%- for path in include_icons -%} + {%- include path ignore missing -%} + {%- endfor -%} +
{% include "templates/includes/splash_screen.html" %}
diff --git a/frappe/www/app.py b/frappe/www/app.py index 37628d1ab2..38c97fd481 100644 --- a/frappe/www/app.py +++ b/frappe/www/app.py @@ -44,6 +44,7 @@ def get_context(context): include_js = hooks.get("app_include_js", []) + frappe.conf.get("app_include_js", []) include_css = hooks.get("app_include_css", []) + frappe.conf.get("app_include_css", []) + include_icons = hooks.get("app_include_icons", []) context.update( { @@ -51,6 +52,7 @@ def get_context(context): "build_version": frappe.utils.get_build_version(), "include_js": include_js, "include_css": include_css, + "include_icons": include_icons, "layout_direction": "rtl" if is_rtl() else "ltr", "lang": frappe.local.lang, "sounds": hooks["sounds"],