jorgenpt / bichrome

A program that picks which browser & browser profile to open links in based on matching the URL
Apache License 2.0
19 stars 6 forks source link

Allow you to specific any executable for redirection #20

Closed nixxquality closed 9 months ago

nixxquality commented 9 months ago

I had an idea to write an application that would automatically open links like YouTube in media players so I looked around for ways to set/check default browser in Rust and I found your very well fleshed out project. Good job on this!

I was able to wrench my way in and add support for this feature as well. Here's an example config:

{
    "default_profile": "Firefox",
    "profiles": {
        "Firefox": {
            "browser": "Firefox"
        },
        "mpv": {
            "browser": "Executable",
            "path": "C:/Program Files/mpv/mpv.exe"
        }
    },
    "profile_selection": [
        {
            "profile": "mpv",
            "pattern": "*.youtube.com"
        },
        {
            "profile": "mpv",
            "pattern": "youtu.be"
        }
    ]
}

I'm not very experienced with serde, but I managed to make it error out if you forget the path for the executable, even if it's a bit unspecific:

cargo run -- --debug https://google.com/
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target\debug\bichrome.exe --debug https://google.com/`
12:31:03 [DEBUG] (1) bichrome::windows: attempting to load config from C:\Users\Linus\Code\bichrome\target\debug\bichrome_config.json
12:31:03 [ERROR] failed to parse config: InvalidJson(Error("missing field `path`", line: 10, column: 5))

I don't know if you're interested in having this feature at all, so let me know what your intentions are. I have a MacBook so I could probably write and test the macOS code myself.

jorgenpt commented 9 months ago

Thank you for your contribution! I'd be happy to accept this feature into bichrome -- it's a relatively low surface area, and seems like it would expand utility noticeably (even if I don't know that I'd use it myself).

It would be great if you could add support to macOS as well -- it shouldn't be too much work -- and if you could add some information to README.md and an example to example_config/bichrome_config.json.

As for the code itself, what's the motivation for using String instead of path::PathBuf inside of ExecutablePath()? I think serde supports deserialization into path::PathBuf.

nixxquality commented 9 months ago

Thank you for the comments. The reason I went to String before PathBuf is simple: I didn't know that Serde could do it :)

I added some documentation and possible macOS code. I call it possible code, because for some reason the exe doesn't want to run for me so I can't test it myself. It's the same with the mainline code, and probably something wrong on my end (it's a pretty old MacBook).

jorgenpt commented 9 months ago

Perfect, thank you!