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

Allow you to specific any executable for redirection #20

Merged
merged 4 commits into from
Feb 8, 2024

Conversation

nixxquality
Copy link
Contributor

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.

@nixxquality nixxquality marked this pull request as draft January 30, 2024 12:38
@jorgenpt
Copy link
Owner

jorgenpt commented Feb 2, 2024

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
Copy link
Contributor Author

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).

@nixxquality nixxquality marked this pull request as ready for review February 2, 2024 11:29
@jorgenpt jorgenpt merged commit 47890ac into jorgenpt:main Feb 8, 2024
2 checks passed
@jorgenpt
Copy link
Owner

jorgenpt commented Feb 8, 2024

Perfect, thank you!

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

Successfully merging this pull request may close these issues.

2 participants