From 88b0fe6af3ef7c144ecebf96ed7b36a6684ff1b7 Mon Sep 17 00:00:00 2001 From: tw93 Date: Thu, 26 Feb 2026 11:53:39 +0800 Subject: [PATCH] refactor(base): extract get_lsregister_path as shared utility Move get_lsregister_path() to base.sh to avoid duplication across optimize and uninstall modules. Adds macOS 14+ compatibility with fallback paths. --- lib/core/base.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/core/base.sh b/lib/core/base.sh index 890e63a..d0efe1a 100644 --- a/lib/core/base.sh +++ b/lib/core/base.sh @@ -43,6 +43,27 @@ readonly ICON_NAV_UP="↑" readonly ICON_NAV_DOWN="↓" readonly ICON_INFO="ℹ" +# ============================================================================ +# LaunchServices Utility +# ============================================================================ + +# Locate the lsregister binary (path varies across macOS versions). +get_lsregister_path() { + local -a candidates=( + "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister" + "/System/Library/CoreServices/Frameworks/LaunchServices.framework/Support/lsregister" + ) + local candidate="" + for candidate in "${candidates[@]}"; do + if [[ -x "$candidate" ]]; then + echo "$candidate" + return 0 + fi + done + echo "" + return 0 +} + # ============================================================================ # Global Configuration Constants # ============================================================================