From 229b8d942233b00caaf3e645f78c6dc52307cc33 Mon Sep 17 00:00:00 2001 From: Torben Raab Date: Fri, 4 Apr 2025 18:12:00 +0200 Subject: [PATCH 1/2] Add Edge Profile capabilities --- Browserino/Models/BrowserUtil.swift | 36 ++++++++++++++----- .../Views/Preferences/BrowsersTab.swift | 6 +++- .../Views/Preferences/EditRuleForm.swift | 25 +++++++++++++ Browserino/Views/Preferences/RulesTab.swift | 6 +++- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/Browserino/Models/BrowserUtil.swift b/Browserino/Models/BrowserUtil.swift index 462d705..19f0bd3 100644 --- a/Browserino/Models/BrowserUtil.swift +++ b/Browserino/Models/BrowserUtil.swift @@ -109,6 +109,18 @@ class BrowserUtil { browserItems.append(BrowserItem(url: browserURL, profile: profile)) } } + } else if let bundle = Bundle(url: browserURL), bundle.bundleIdentifier == "com.microsoft.edgemac" { + // Handle Edge specially + let profiles = getEdgeProfiles() + if profiles.isEmpty { + // If no profiles found, add Edge as a single entry + browserItems.append(BrowserItem(url: browserURL)) + } else { + // Add Edge for each profile + for profile in profiles { + browserItems.append(BrowserItem(url: browserURL, profile: profile)) + } + } } else { // Add regular browser browserItems.append(BrowserItem(url: browserURL)) @@ -117,17 +129,25 @@ class BrowserUtil { return browserItems } - + static func getChromeProfiles() -> [ChromeProfile] { - log("šŸ” Getting Chrome profiles...") + return BrowserUtil.getChromiumProfiles("Google/Chrome", "Chrome") + } + + static func getEdgeProfiles() -> [ChromeProfile] { + return BrowserUtil.getChromiumProfiles("Microsoft Edge", "Edge") + } + + static func getChromiumProfiles(_ path: String, _ name: String) -> [ChromeProfile] { + log("šŸ” Getting \(name) profiles...") let fileManager = FileManager.default let userPath = fileManager.homeDirectoryForCurrentUser.path - let chromePath = "\(userPath)/Library/Application Support/Google/Chrome" + let chromePath = "\(userPath)/Library/Application Support/\(path)" - log("šŸ“ Chrome path: \(chromePath)") + log("šŸ“ \(name) path: \(chromePath)") guard fileManager.fileExists(atPath: chromePath) else { - log("āŒ Chrome directory not found") + log("āŒ \(name) directory not found") return [] } @@ -139,7 +159,7 @@ class BrowserUtil { let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], let info = json["profile"] as? [String: Any], let profiles = info["info_cache"] as? [String: [String: Any]] else { - log("āŒ Failed to read or parse Chrome profile data") + log("āŒ Failed to read or parse \(name) profile data") return [] } @@ -154,7 +174,7 @@ class BrowserUtil { ) }.sorted { $0.name < $1.name } - log("āœ… Found \(chromeProfiles.count) Chrome profiles:") + log("āœ… Found \(chromeProfiles.count) \(name) profiles:") chromeProfiles.forEach { profile in log("", items: [ " - Profile: \(profile.name)", @@ -189,7 +209,7 @@ class BrowserUtil { let configuration = NSWorkspace.OpenConfiguration() - if bundle.bundleIdentifier == "com.google.Chrome" && chromeProfile != nil { + if (bundle.bundleIdentifier == "com.google.Chrome" || bundle.bundleIdentifier == "com.microsoft.edgemac") && chromeProfile != nil { configuration.createsNewApplicationInstance = true // Use --profile-directory without quotes and with the exact profile directory name let profileArg = "--profile-directory=\(chromeProfile!.id)" diff --git a/Browserino/Views/Preferences/BrowsersTab.swift b/Browserino/Views/Preferences/BrowsersTab.swift index 6177efe..de86539 100644 --- a/Browserino/Views/Preferences/BrowsersTab.swift +++ b/Browserino/Views/Preferences/BrowsersTab.swift @@ -35,6 +35,10 @@ struct BrowsersTab: View { private func isChrome(_ bundle: Bundle) -> Bool { return bundle.bundleIdentifier == "com.google.Chrome" } + + private func isEdge(_ bundle: Bundle) -> Bool { + return bundle.bundleIdentifier == "com.microsoft.edgemac" + } private func rescanBrowsers() { BrowserUtil.log("\nšŸ”„ Rescanning browsers in BrowsersTab...") @@ -95,7 +99,7 @@ struct BrowsersTab: View { Spacer().frame(width: 8) - if isChrome(bundle) && browser.profile != nil { + if (isChrome(bundle) || isEdge(bundle)) && browser.profile != nil { Text("\(bundle.infoDictionary!["CFBundleName"] as! String) (\(browser.profile!.name))") .font(.system(size: 14)) } else { diff --git a/Browserino/Views/Preferences/EditRuleForm.swift b/Browserino/Views/Preferences/EditRuleForm.swift index df35f34..55b2d8e 100644 --- a/Browserino/Views/Preferences/EditRuleForm.swift +++ b/Browserino/Views/Preferences/EditRuleForm.swift @@ -74,6 +74,11 @@ struct RuleForm: View { guard let bundle = url.map({ Bundle(url: $0)! }) else { return false } return bundle.bundleIdentifier == "com.google.Chrome" } + + private var isEdge: Bool { + guard let bundle = url.map({ Bundle(url: $0)! }) else { return false } + return bundle.bundleIdentifier == "com.microsoft.edgemac" + } private var compiledRegex: Regex? { return try? Regex(regex).ignoresCase() @@ -140,6 +145,9 @@ struct RuleForm: View { if isChrome { chromeProfiles = BrowserUtil.getChromeProfiles() } + if isEdge { + chromeProfiles = BrowserUtil.getEdgeProfiles() + } } } @@ -164,6 +172,20 @@ struct RuleForm: View { .frame(width: 200) } } + + if isEdge && !chromeProfiles.isEmpty { + LabeledContent("Edge Profile:") { + Picker("Profile", selection: $selectedProfile) { + Text("Default") + .tag(nil as ChromeProfile?) + ForEach(chromeProfiles) { profile in + Text(profile.name) + .tag(profile as ChromeProfile?) + } + } + .frame(width: 200) + } + } Spacer() .frame(height: 32) @@ -209,6 +231,9 @@ struct RuleForm: View { if isChrome { chromeProfiles = BrowserUtil.getChromeProfiles() } + if isEdge { + chromeProfiles = BrowserUtil.getEdgeProfiles() + } } } } diff --git a/Browserino/Views/Preferences/RulesTab.swift b/Browserino/Views/Preferences/RulesTab.swift index dc37491..786b626 100644 --- a/Browserino/Views/Preferences/RulesTab.swift +++ b/Browserino/Views/Preferences/RulesTab.swift @@ -45,6 +45,10 @@ struct RuleItem: View { private func isChrome(_ bundle: Bundle) -> Bool { return bundle.bundleIdentifier == "com.google.Chrome" } + + private func isEdge(_ bundle: Bundle) -> Bool { + return bundle.bundleIdentifier == "com.microsoft.edgemac" + } private func loadBundle() { bundle = Bundle(url: rule.app) @@ -71,7 +75,7 @@ struct RuleItem: View { if let bundle = bundle { if let bundleName = bundle.infoDictionary?["CFBundleName"] as? String { - if isChrome(bundle) && rule.chromeProfile != nil { + if (isChrome(bundle) || isEdge(bundle)) && rule.chromeProfile != nil { Text("\(bundleName) (\(rule.chromeProfile!.name))") .font(.system(size: 14)) } else { From 9a6320ef098317f63815468df948a497359e5b3a Mon Sep 17 00:00:00 2001 From: Torben Raab Date: Wed, 9 Apr 2025 10:45:28 +0200 Subject: [PATCH 2/2] Fix PromtView now also displaying the profiles for Edge --- Browserino/Views/Prompt/PromptView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Browserino/Views/Prompt/PromptView.swift b/Browserino/Views/Prompt/PromptView.swift index 4df1192..6007d59 100644 --- a/Browserino/Views/Prompt/PromptView.swift +++ b/Browserino/Views/Prompt/PromptView.swift @@ -23,6 +23,10 @@ struct PromptView: View { private func isChrome(_ bundle: Bundle) -> Bool { return bundle.bundleIdentifier == "com.google.Chrome" } + + private func isEdge(_ bundle: Bundle) -> Bool { + return bundle.bundleIdentifier == "com.microsoft.edgemac" + } private func shortcutKey(for browser: BrowserItem, bundleId: String) -> String { if let profile = browser.profile { @@ -72,13 +76,13 @@ struct PromptView: View { ]) // Check if this is Chrome and has a profile - if bundle.bundleIdentifier == "com.google.Chrome" && rule.chromeProfile != nil { + if (isChrome(bundle) || isEdge(bundle)) && rule.chromeProfile != nil { BrowserUtil.log("\nšŸ” Looking for matching Chrome profile...") // Find the matching browser with the correct Chrome profile let matchingBrowser = browsers.first(where: { browser in guard let browserBundle = Bundle(url: browser.url), - browserBundle.bundleIdentifier == "com.google.Chrome", + isChrome(bundle) || isEdge(bundle), let browserProfile = browser.profile else { BrowserUtil.log("āŒ Skipping browser: No Chrome or no profile") return false @@ -204,7 +208,7 @@ struct PromptView: View { .resizable() .frame(width: 32, height: 32) - if isChrome(bundle) && browser.profile != nil { + if (isChrome(bundle) || isEdge(bundle)) && browser.profile != nil { Text("\(bundle.infoDictionary!["CFBundleName"] as! String) (\(browser.profile!.name))") .font(.system(size: 14)) } else {