Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default browser selection for opening links & video calls #255

Closed
Ariandr opened this issue Sep 24, 2024 · 18 comments
Closed

Add default browser selection for opening links & video calls #255

Ariandr opened this issue Sep 24, 2024 · 18 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@Ariandr
Copy link
Contributor

Ariandr commented Sep 24, 2024

Hi!
My use case is that I moved my working calendar to Apple Calendar to use with Calendr app. There I have a lot of video calls with links.

But my default browser is not my working browser, so wherever I click the events to open the meetings (Google Meets mostly), it launches them in the wrong browser and I have to copy the link and open it in another browser.

  1. My idea is that it would be really great to set the default browser for opening links in the Calendr Settings.

  2. Or, provide the option to open it in a specific browser (after right clicking near Join), like in the Mail app:
    image

  3. Or, have the option to Copy link here, so that I can insert it where I need to without launching the meeting in the wrong browser first. I know the link is available in the event details, but I have a long description there and it's not convenient to copy the link from the details.
    image

What do you think about these ideas?

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 24, 2024

This is how we can detect what browsers are installed.

import Cocoa

func getInstalledBrowsers() -> [String] {
    let browserBundleIDs = [
        // Popular browsers
        "com.apple.Safari",               // Safari
        "com.google.Chrome",              // Google Chrome
        "org.mozilla.firefox",            // Mozilla Firefox
        "com.microsoft.edgemac",          // Microsoft Edge
        "com.operasoftware.Opera",        // Opera
        "com.brave.Browser",              // Brave
        "com.vivaldi.Vivaldi",            // Vivaldi

        // Alternative browsers
        "com.maxthon.mac.Maxthon",        // Maxthon
        "com.torproject.torbrowser",      // Tor Browser
        "com.flock.Flock",                // Flock
        "com.seamonkey-project.SeaMonkey",// SeaMonkey
        "org.waterfoxproject.waterfox",   // Waterfox
        "com.qutebrowser.qutebrowser",    // qutebrowser

        // Developer-focused browsers
        "com.coastbyopera.Coast",         // Opera Coast
        "org.webkit.WebKit",              // WebKit

        // Other niche or privacy-focused browsers
        "com.sleipnir.Sleipnir",          // Sleipnir
        "com.epicbrowser.epic",           // Epic Privacy Browser
        "org.isc.roccat",                 // Roccat Browser
        "org.ghostbrowser.GhostBrowser",  // Ghost Browser
        "com.avast.osx.securebrowser",    // Avast Secure Browser
        "com.cliqz.browser",              // Cliqz
        "com.uc.browser",                 // UC Browser
    ]
    
    var installedBrowsers: [String] = []
    
    let workspace = NSWorkspace.shared
    for bundleID in browserBundleIDs {
        if let appURL = workspace.urlForApplication(withBundleIdentifier: bundleID) {
            installedBrowsers.append("\(bundleID) at: \(appURL.path)")
        }
    }
    
    return installedBrowsers
}

// Usage example:
let browsers = getInstalledBrowsers()
if browsers.isEmpty {
    print("No browsers found.")
} else {
    for browser in browsers {
        print("Found browser: \(browser)")
    }
}

And that's how we can launch a URL inside the selected one.

import Cocoa

func openURLInBrowser(urlString: String, browserBundleID: String) {
    guard let url = URL(string: urlString) else {
        print("Invalid URL string.")
        return
    }

    let workspace = NSWorkspace.shared
    if let browserURL = workspace.urlForApplication(withBundleIdentifier: browserBundleID) {
        do {
            try workspace.open([url], withApplicationAt: browserURL, options: [], configuration: [:])
            print("Opened \(urlString) in \(browserBundleID).")
        } catch {
            print("Failed to open \(urlString) in \(browserBundleID): \(error).")
        }
    } else {
        print("Browser with bundle ID \(browserBundleID) is not installed.")
    }
}

// Usage example:
let browserBundleID = "com.google.Chrome"  // Change to the browser's bundle ID you want
let urlString = "https://www.example.com"

openURLInBrowser(urlString: urlString, browserBundleID: browserBundleID)

That's how to get browser icons.

import Cocoa

func getBrowserIcon(bundleID: String) -> NSImage? {
    let workspace = NSWorkspace.shared
    if let appURL = workspace.urlForApplication(withBundleIdentifier: bundleID) {
        return workspace.icon(forFile: appURL.path)
    } else {
        print("Browser with bundle ID \(bundleID) is not installed.")
        return nil
    }
}

// Usage example:
let browserBundleID = "com.google.Chrome"  // Change this to the browser bundle ID
if let icon = getBrowserIcon(bundleID: browserBundleID) {
    print("Icon retrieved for \(browserBundleID).")
    // You can now use 'icon', for example in an NSImageView
} else {
    print("Failed to retrieve the icon.")
}

Getting browser name.

import Cocoa

func getAppName(bundleID: String) -> String? {
    let workspace = NSWorkspace.shared
    if let appURL = workspace.urlForApplication(withBundleIdentifier: bundleID),
       let appBundle = Bundle(url: appURL) {
        return appBundle.object(forInfoDictionaryKey: "CFBundleName") as? String
    } else {
        print("Application with bundle ID \(bundleID) is not installed.")
        return nil
    }
}

// Usage example:
let browserBundleID = "com.google.Chrome"  // Change to the desired browser bundle ID
if let appName = getAppName(bundleID: browserBundleID) {
    print("Application name: \(appName)")
} else {
    print("Failed to retrieve the application name.")
}

@pakerwreah
Copy link
Owner

pakerwreah commented Sep 24, 2024

I have a working browser as well. I use an app called Finicky as my "default browser" and I configure which browser should open the URL.

module.exports = {
  defaultBrowser: "Safari",
  handlers: [
    {
      match: [
        "notion.*/*",
        "*.notion.*/*",
        "linear.app/*",
        "*.linear.app/*",
        "play.google.com/*",
        "developers.facebook.com/*",
        '*.figma.com/*',
        'console.cloud.google.com/*',
        "*.aws.amazon.com/*",
      ],
      /*browser: {
        name: "Google Chrome",
        profile: "Profile 1"
      }*/
      browser: ({ urlString }) => ({
        name: "Firefox",
        args: ["-P", "Profile 1", `${urlString}`]
      })
    }
  ]
}

That has the advantage of being system-wide, so if I click a link on Slack, for example, it also routes to my work browser.

@pakerwreah pakerwreah changed the title Feature request: Add default browser selection for opening links & video calls Add default browser selection for opening links & video calls Sep 24, 2024
@pakerwreah pakerwreah added feature New feature or request not planned This will not be worked on labels Sep 24, 2024
@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 24, 2024

@pakerwreah
Cool, thanks for the advice.

But probably would be nice to have it in the Calendr app in some form too, since most users don't have such helper apps.

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 24, 2024

I think when I have time I'll work on it and come up with a PR.

@pakerwreah
Copy link
Owner

pakerwreah commented Sep 24, 2024

The problem is that a context menu will not be helpful, as it will become extremely frustrating and repetitive.
Defining a default browser is also not enough, as you can have mixed work and personal calendars.
So we would need to have a default browser per calendar, which is a bit too much.

That said, it should be pretty simple, actually. You don't have to map every browser.
https://ericmaciel.me/posts/how-to-get-the-list-of-installed-browsers-on-macos

Feel free to implement this, but I'm probably not going to merge it, as it's beyond the scope of Calendr.
Unless I find a simple and non-intrusive way of doing it.

@pakerwreah
Copy link
Owner

pakerwreah commented Sep 25, 2024

It's done 😂
could you please try out this version?
Calendr.zip

     

I will add more stuff to it before releasing, so remember to download and reinstall after the official release comes out.

@pakerwreah pakerwreah added this to the v1.13.4 milestone Sep 25, 2024
@pakerwreah pakerwreah self-assigned this Sep 25, 2024
@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
You rock🔥🔥🔥
Thank you a lot, I will try now.

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
Cannot find where it's placed.
In event details it's not available for me it seems.
image

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
I found, it's available only in events with usual links, but not video calls🙂
Probably we should expand to video calls if possible, otherwise it would be hard to find, I didn't even have events with just links.

Also, found several issues:

  1. The icon disappears from here sometimes, and sometimes appears. Or is it intentional?
    image

  2. While the correct browser with the link is opened when clicking here, the link itself is not opened.
    image

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

Also, just a question to consider.
Maybe it would be possible to move it to Calendars preferences? Or do you think too clumsy?

I also think if it's a default browser, after selection the browser option it can be without the icon, like in the 1. bug I showed you. And if it's not default, then it will be with the icon. So that by default it's not intrusive if we are talking about the preferences. But it's subjective and personally I like the icons always.

image

@pakerwreah
Copy link
Owner

Yeah, I wrongly assumed that I was only showing native apps as video calls. I forgot about google meet/hangouts.

About moving it to preferences, it would have to be per calendar, that's why I don't want to do it there.

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
Okay, that makes sense, regarding the preferences.

Definitely it would be enough to just have it near the links/video calls.

@pakerwreah
Copy link
Owner

pakerwreah commented Sep 25, 2024

I completely forgot to open the link 🤣

  • Icon is hidden when selecting the default browser
  • Show browser selector for any regular http urls
  • Links are now actually opening, not just the browser

👉🏻 Calendr.zip

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
Great, thank you. I will test.

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
It works, but after selecting another browser it sometimes treats a non-default browser as default. In my case Opera is default, but it shows Chrome as default. Not a big deal though.
image

@pakerwreah
Copy link
Owner

pakerwreah commented Sep 25, 2024

Hum 🤔 it should always show the default first. Than can cause problems, let me have a look.

@pakerwreah
Copy link
Owner

yeah, I'm just dumb and don't know how to sort multiple keys 😆

we're almost there... Calendr.zip

@Ariandr
Copy link
Contributor Author

Ariandr commented Sep 25, 2024

@pakerwreah
Now seems working well🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants