1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-08 00:29:54 +00:00

open in browser

This commit is contained in:
Laura
2025-08-11 01:59:26 +02:00
parent d352047a8d
commit 92a67123e7
3 changed files with 36 additions and 3 deletions

View File

@@ -37,7 +37,7 @@ jobs:
--original-filename whiskr.exe \
--icon static/favicon.ico \
--copyright "(c) 2025 coalaura" \
--file-description "AI story writing tool" \
--file-description "Minimal LLM chat UI using OpenRouter giving you control over your context." \
--file-version "${{ github.ref_name }}" \
--arch "${{ matrix.goarch }}"

4
env.go
View File

@@ -9,6 +9,7 @@ import (
var (
Debug bool
NoOpen bool
OpenRouterToken string
)
@@ -16,12 +17,13 @@ func init() {
log.MustPanic(godotenv.Load())
Debug = os.Getenv("DEBUG") == "true"
NoOpen = os.Getenv("NO_OPEN") == "true"
if OpenRouterToken = os.Getenv("OPENROUTER_TOKEN"); OpenRouterToken == "" {
log.Panic(errors.New("missing openrouter token"))
}
if Debug {
log.Debug("Debug mode enabled")
log.Warning("Debug mode enabled")
}
}

33
main.go
View File

@@ -1,9 +1,13 @@
package main
import (
"errors"
"net/http"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/coalaura/logger"
adapter "github.com/coalaura/logger/http"
@@ -18,9 +22,12 @@ var log = logger.New().DetectTerminal().WithOptions(logger.Options{
})
func main() {
log.Info("Loading models...")
models, err := LoadModels()
log.MustPanic(err)
log.Info("Preparing router...")
r := chi.NewRouter()
r.Use(middleware.Recoverer)
@@ -38,7 +45,18 @@ func main() {
r.Post("/-/chat", HandleChat)
log.Debug("Listening at http://localhost:3443/")
if !NoOpen {
time.AfterFunc(500*time.Millisecond, func() {
log.Info("Opening browser...")
err := open("http://localhost:3443/")
if err != nil {
log.WarningE(err)
}
})
}
log.Info("Listening at http://localhost:3443/")
http.ListenAndServe(":3443", r)
}
@@ -54,3 +72,16 @@ func cache(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
func open(url string) error {
switch runtime.GOOS {
case "linux":
return exec.Command("xdg-open", url).Start()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
return exec.Command("open", url).Start()
}
return errors.New("unsupported platform")
}