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

open in browser

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

View File

@@ -37,7 +37,7 @@ jobs:
--original-filename whiskr.exe \ --original-filename whiskr.exe \
--icon static/favicon.ico \ --icon static/favicon.ico \
--copyright "(c) 2025 coalaura" \ --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 }}" \ --file-version "${{ github.ref_name }}" \
--arch "${{ matrix.goarch }}" --arch "${{ matrix.goarch }}"

4
env.go
View File

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

33
main.go
View File

@@ -1,9 +1,13 @@
package main package main
import ( import (
"errors"
"net/http" "net/http"
"os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"time"
"github.com/coalaura/logger" "github.com/coalaura/logger"
adapter "github.com/coalaura/logger/http" adapter "github.com/coalaura/logger/http"
@@ -18,9 +22,12 @@ var log = logger.New().DetectTerminal().WithOptions(logger.Options{
}) })
func main() { func main() {
log.Info("Loading models...")
models, err := LoadModels() models, err := LoadModels()
log.MustPanic(err) log.MustPanic(err)
log.Info("Preparing router...")
r := chi.NewRouter() r := chi.NewRouter()
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)
@@ -38,7 +45,18 @@ func main() {
r.Post("/-/chat", HandleChat) 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) http.ListenAndServe(":3443", r)
} }
@@ -54,3 +72,16 @@ func cache(next http.Handler) http.Handler {
next.ServeHTTP(w, r) 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")
}