Bunchhieng/hnreader

Improve checkOS method for better handling existing browser

Bunchhieng opened this issue · 4 comments

Current code

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

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?

@kolten please checkout #1 and #2

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?

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