Use default Wails asset handler + GetStoredConfig binding
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
Desktop App / Build Linux (amd64) (push) Has been cancelled
Desktop App / Attach to Release (push) Has been cancelled

- Remove custom asset handler — it broke Wails IPC routing
- Use application.AssetFileServerFS(distFS) so Wails serves its own runtime
- Add GetStoredConfig binding: SPA calls it on startup to retrieve keychain config
- main.ts: loadDesktopConfig() fetches stored creds before mounting
- Remove runtime.js embed (Wails serves it internally)
This commit is contained in:
2026-07-13 23:45:54 +02:00
parent 0271727709
commit ff6608f9ea
3 changed files with 41 additions and 65 deletions

View File

@@ -31,17 +31,14 @@ var assets embed.FS
//go:embed icon.png
var iconPNG []byte
//go:embed runtime.js
var runtimeJS []byte
const (
keyringService = "com.hubris.oikos-desktop"
keyringUser = "oikos"
version = "0.1.0"
updateURL = "https://git.hubris.network/api/v1/repos/dtoro/oikos/releases"
pollInterval = 30 * time.Second
updateInterval = 6 * time.Hour
oidcCallbackPort = 18901
keyringService = "com.hubris.oikos-desktop"
keyringUser = "oikos"
version = "0.1.0"
updateURL = "https://git.hubris.network/api/v1/repos/dtoro/oikos/releases"
pollInterval = 30 * time.Second
updateInterval = 6 * time.Hour
oidcCallbackPort = 18901
)
type OikosConfig struct {
@@ -66,6 +63,10 @@ func (c *ConfigService) ClearConfig() error {
return keyring.Delete(keyringService, keyringUser)
}
func (c *ConfigService) GetStoredConfig() *OikosConfig {
return loadConfig()
}
func (c *ConfigService) EnableAutoStart() error {
if runtime.GOOS != "darwin" {
return fmt.Errorf("autostart not supported on %s", runtime.GOOS)
@@ -104,9 +105,6 @@ func (c *ConfigService) DisableAutoStart() error {
return os.Remove(path)
}
// StartOIDCLogin opens the system browser for Authentik login and returns
// the access token. The desktop app hosts a local HTTP server on a fixed
// port to receive the OIDC callback directly (no copy-paste).
func (c *ConfigService) StartOIDCLogin(apiUrl string) (string, error) {
apiUrl = strings.TrimRight(apiUrl, "/")
@@ -321,46 +319,6 @@ func loadConfig() *OikosConfig {
return &cfg
}
// ---- Asset handler ----
func newAssetHandler(cfg *OikosConfig) http.Handler {
distFS, err := fs.Sub(assets, "frontend/dist")
if err != nil {
log.Fatalf("embedded assets: %v", err)
}
fallback := http.FileServer(http.FS(distFS))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/wails/runtime.js" {
w.Header().Set("Content-Type", "application/javascript")
w.Write(runtimeJS)
return
}
if path == "/" || path == "/index.html" {
data, err := fs.ReadFile(distFS, "index.html")
if err != nil {
fallback.ServeHTTP(w, r)
return
}
html := string(data)
if cfg != nil {
configJSON, _ := json.Marshal(cfg)
placeholder := `<script>window.__OIKOS_CONFIG__ = {};</script>`
injected := fmt.Sprintf(`<script>window.__OIKOS_CONFIG__ = %s;</script>`, configJSON)
html = strings.ReplaceAll(html, placeholder, injected)
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(html))
return
}
fallback.ServeHTTP(w, r)
})
}
// ---- Notifications ----
type dashboardSummary struct {
@@ -483,7 +441,10 @@ func checkUpdates() {
// ---- Main ----
func main() {
cfg := loadConfig()
distFS, err := fs.Sub(assets, "frontend/dist")
if err != nil {
log.Fatalf("embedded assets: %v", err)
}
app := application.New(application.Options{
Name: "Oikos",
@@ -492,14 +453,13 @@ func main() {
application.NewService(&ConfigService{}),
},
Assets: application.AssetOptions{
Handler: newAssetHandler(cfg),
Handler: application.AssetFileServerFS(distFS),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: false,
},
})
// --- System tray ---
systemTray := app.SystemTray.New()
systemTray.SetLabel("Oikos")
systemTray.SetTooltip("Oikos")
@@ -523,7 +483,6 @@ func main() {
})
systemTray.SetMenu(trayMenu)
// --- Main window ---
ws := loadWindowState()
width, height := 1400, 900
minWidth, minHeight := 1024, 700
@@ -552,10 +511,10 @@ func main() {
saveWindowState(window)
})
go pollDashboard(cfg)
go pollDashboard(loadConfig())
go checkUpdates()
err := app.Run()
err = app.Run()
if err != nil {
log.Fatal(err)
}