refactor: add auto-creation of icons

This commit is contained in:
sokumon 2025-11-13 23:39:11 +05:30
parent d87c43ee63
commit a0caf8e320
6 changed files with 336 additions and 1 deletions

View file

@ -55,7 +55,7 @@ class WorkspaceSidebar(Document):
def delete_file(self):
folder_path = create_directory_on_app_path("workspace_sidebar", self.app)
file_path = os.path.join(folder_path, f"{frappe.scrub(self.title)}.json")
if not os.path.exists(file_path):
if os.path.exists(file_path):
os.remove(file_path)
def on_trash(self):
@ -114,9 +114,30 @@ def create_workspace_sidebar_for_workspaces():
existing_sidebars = frappe.get_all("Workspace Sidebar", pluck="title")
for workspace in all_workspaces:
if workspace not in existing_sidebars:
workspace_doc = frappe.get_doc("Workspace", workspace)
sidebar = frappe.new_doc("Workspace Sidebar")
sidebar.title = workspace
sidebar.header_icon = frappe.db.get_value("Workspace", workspace, "icon")
print("Creating Sidebar Items for", workspace)
shortcuts = workspace_doc.shortcuts
items = []
idx = 1
# Adding the workspace itself as home
workspace_sidebar_item = frappe.new_doc("Workspace Sidebar Item")
workspace_sidebar_item.update(
{"label": "Home", "link_to": workspace, "link_type": "Workspace", "type": "Link", "idx": 0}
)
items.append(workspace_sidebar_item)
# Process Shortcuts
for s in shortcuts:
workspace_sidebar_item = frappe.new_doc("Workspace Sidebar Item")
workspace_sidebar_item.update(
{"label": s.label, "link_to": s.link_to, "link_type": s.type, "type": "Link", "idx": idx}
)
items.append(workspace_sidebar_item)
idx += 1
sidebar.items = items
sidebar.save()

View file

@ -16,6 +16,8 @@ app_email = "developers@frappe.io"
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"
page_js = {"setup-wizard": "public/js/frappe/setup_wizard.js"}
# website

View file

@ -196,6 +196,7 @@ execute:frappe.reload_doc("desk", "doctype", "Form Tour")
execute:frappe.delete_doc('Page', 'recorder', ignore_missing=True, force=True)
frappe.patches.v14_0.modify_value_column_size_for_singles
frappe.integrations.doctype.oauth_bearer_token.patches.clear_old_tokens
execute:frappe.db.truncate("Desktop Icon")
[post_model_sync]
execute:frappe.get_doc('Role', 'Guest').save() # remove desk access
@ -247,3 +248,4 @@ frappe.patches.v14_0.fix_user_settings_collation
execute:frappe.call("frappe.core.doctype.system_settings.system_settings.sync_system_settings")
frappe.patches.v15_0.migrate_to_utm
frappe.patches.v16_0.add_module_deprecation_warning
frappe.patches.v16_0.auto_generate_desktop_icon_and_sidebar

View file

@ -0,0 +1,6 @@
from frappe.utils.install import auto_generate_icons_and_sidebar
def execute():
"""Auto Create desktop icons and workspace sidebars."""
auto_generate_icons_and_sidebar()

View file

@ -176,3 +176,23 @@ def add_standard_navbar_items():
navbar_settings.append("help_dropdown", item)
navbar_settings.save()
def auto_generate_icons_and_sidebar(app_name=None):
"""Auto Create desktop icons and workspace sidebars."""
from frappe.desk.doctype.desktop_icon.desktop_icon import create_desktop_icons
from frappe.desk.doctype.workspace_sidebar.workspace_sidebar import (
create_workspace_sidebar_for_workspaces,
)
try:
print("Creating Desktop Icons")
create_desktop_icons()
print("Creating Workspace Sidebars")
create_workspace_sidebar_for_workspaces()
# Save the generated icons
frappe.db.commit() # nosemgrep
# Save the genreated sidebar links
frappe.db.commit() # nosemgrep
except Exception as e:
print(f"Error creating icons {e}")

View file

@ -0,0 +1,284 @@
{
"app": "frappe",
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar",
"header_icon": "integration",
"idx": 0,
"items": [
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "cable",
"idx": 1,
"indent": 0,
"keep_closed": 0,
"label": "Connected App",
"link_to": "Connected App",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmt975c7e",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "bell-dot",
"idx": 2,
"indent": 0,
"keep_closed": 0,
"label": "Push Notification",
"link_to": "Push Notification Settings",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmrano0gi",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "webhook",
"idx": 3,
"indent": 0,
"keep_closed": 0,
"label": "Webhook",
"link_to": "Webhook",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhm2tp5jog",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"idx": 4,
"indent": 0,
"keep_closed": 0,
"label": "Google",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmkuvdn9e",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Section Break"
},
{
"child": 1,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "contact",
"idx": 5,
"indent": 0,
"keep_closed": 0,
"label": "Google Contacts",
"link_to": "Google Contacts",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmepjlo5h",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 1,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "calendar-days",
"idx": 6,
"indent": 0,
"keep_closed": 0,
"label": "Google Calender",
"link_to": "Google Calendar",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmj2s2clt",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 1,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "settings",
"idx": 7,
"indent": 0,
"keep_closed": 0,
"label": "Google Settings",
"link_to": "Google Settings",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmslt3v07",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"idx": 8,
"indent": 0,
"keep_closed": 0,
"label": "Authetication",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmpfii63a",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Section Break"
},
{
"child": 1,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"idx": 9,
"indent": 0,
"keep_closed": 0,
"label": "Social Login Key",
"link_to": "Social Login Key",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhm1dqo8tq",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"icon": "settings",
"idx": 10,
"indent": 0,
"keep_closed": 0,
"label": "LDAP Settings",
"link_to": "LDAP Settings",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhm0aurrn2",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"idx": 11,
"indent": 0,
"keep_closed": 0,
"label": "OAuth Client",
"link_to": "OAuth Client",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhm6f2u6gd",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
},
{
"child": 0,
"collapsible": 1,
"creation": "2025-11-13 22:52:32.146359",
"docstatus": 0,
"doctype": "Workspace Sidebar Item",
"idx": 12,
"indent": 0,
"keep_closed": 0,
"label": "OAuth Provider",
"link_to": "OAuth Provider Settings",
"link_type": "DocType",
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "mhmc7nvrfd",
"owner": "Administrator",
"parent": "Integrations",
"parentfield": "items",
"parenttype": "Workspace Sidebar",
"show_arrow": 0,
"type": "Link"
}
],
"modified": "2025-11-13 23:06:52.001638",
"modified_by": "Administrator",
"name": "Integrations",
"owner": "Administrator",
"title": "Integrations"
}