35 lines
554 B
Go
35 lines
554 B
Go
package ui
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
"varia.zone/hui/internal/model"
|
|
)
|
|
|
|
func openLocalhost(url string) error {
|
|
var cmd string
|
|
var args []string
|
|
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
cmd = "open"
|
|
default:
|
|
cmd = "xdg-open"
|
|
}
|
|
|
|
args = append(args, url)
|
|
|
|
return exec.Command(cmd, args...).Start()
|
|
}
|
|
|
|
// PreviewSite previews the site locally.
|
|
func PreviewSite(m *model.Model) error {
|
|
// TODO: run serve with generated port
|
|
// ensure no port clash by checking model
|
|
|
|
url := "http://localhost:1313"
|
|
openLocalhost(url)
|
|
return nil
|
|
}
|