app: add code for macOS and Windows apps under 'app' (#12933)

* app: add code for macOS and Windows apps under 'app'

* app: add readme

* app: windows and linux only for now

* ci: fix ui CI validation

---------

Co-authored-by: jmorganca <jmorganca@gmail.com>
This commit is contained in:
Daniel Hiltgen
2025-11-04 11:40:17 -08:00
committed by GitHub
parent a4770107a6
commit d3b4b9970a
212 changed files with 102976 additions and 1482 deletions

44
app/ui/app.go Normal file
View File

@@ -0,0 +1,44 @@
//go:build windows || darwin
package ui
import (
"bytes"
"embed"
"errors"
"io/fs"
"net/http"
"strings"
"time"
)
//go:embed app/dist
var appFS embed.FS
// appHandler returns an HTTP handler that serves the React SPA.
// It tries to serve real files first, then falls back to index.html for React Router.
func (s *Server) appHandler() http.Handler {
// Strip the dist prefix so URLs look clean
fsys, _ := fs.Sub(appFS, "app/dist")
fileServer := http.FileServer(http.FS(fsys))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, "/")
if _, err := fsys.Open(p); err == nil {
// Serve the file directly
fileServer.ServeHTTP(w, r)
return
}
// Fallback serve index.html for unknown paths so React Router works
data, err := fs.ReadFile(fsys, "index.html")
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
http.NotFound(w, r)
} else {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
return
}
http.ServeContent(w, r, "index.html", time.Time{}, bytes.NewReader(data))
})
}