Bunchhieng / hnreader

Open programming news with your favorite browser using command line
https://bunchhieng.github.io/hnreader/
MIT License
7 stars 10 forks source link

Improve checkOS method for better handling existing browser #6

Open Bunchhieng opened 5 years ago

Bunchhieng commented 5 years ago

Current code

func checkOS() string {
    chrome := ""
    if runtime.GOOS == "windows" {
        chrome = "chrome"
    } else if runtime.GOOS == "darwin" {
        chrome = "Google Chrome"
    }
    return chrome
}
kolten commented 5 years ago

Suggestion/slightly outside of this issue: Instead of having the user specify a browser, what about executing a system command to open their default browser?

Bunchhieng commented 5 years ago

@kolten please checkout https://github.com/Bunchhieng/hnreader/issues/1 and https://github.com/Bunchhieng/hnreader/issues/2

zpeters commented 5 years ago

We might be able to simplify browser selection. Let me know what you think.

1 if the user specifies --browser explicitly use that exact path/command

2 if no #1, then find the users default browser. For Macos i believe you can use "open http://myurl" and it will launch with the default browser. For windows and linux there is probably something similar

This could potentially simplify your code in the future.

What do you think?

sarlalian commented 5 years ago

For windows I believe it is "start http://myurl" and for linux it is "xdg-open http://myurl"