Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions Browserino/Models/BrowserUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 []
}

Expand All @@ -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 []
}

Expand All @@ -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)",
Expand Down Expand Up @@ -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)"
Expand Down
6 changes: 5 additions & 1 deletion Browserino/Views/Preferences/BrowsersTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions Browserino/Views/Preferences/EditRuleForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyRegexOutput>? {
return try? Regex(regex).ignoresCase()
Expand Down Expand Up @@ -140,6 +145,9 @@ struct RuleForm: View {
if isChrome {
chromeProfiles = BrowserUtil.getChromeProfiles()
}
if isEdge {
chromeProfiles = BrowserUtil.getEdgeProfiles()
}
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -209,6 +231,9 @@ struct RuleForm: View {
if isChrome {
chromeProfiles = BrowserUtil.getChromeProfiles()
}
if isEdge {
chromeProfiles = BrowserUtil.getEdgeProfiles()
}
}
}
}
6 changes: 5 additions & 1 deletion Browserino/Views/Preferences/RulesTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions Browserino/Views/Prompt/PromptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down