Embed Wails runtime.js, serve it from custom asset handler
The SPA needs /wails/runtime.js for window.wails to be available. Since we use a custom AssetOptions.Handler, Wails' internal routing doesn't serve it. Embed the runtime and serve it explicitly.
This commit is contained in:
@@ -31,6 +31,9 @@ var assets embed.FS
|
|||||||
//go:embed icon.png
|
//go:embed icon.png
|
||||||
var iconPNG []byte
|
var iconPNG []byte
|
||||||
|
|
||||||
|
//go:embed runtime.js
|
||||||
|
var runtimeJS []byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
keyringService = "com.hubris.oikos-desktop"
|
keyringService = "com.hubris.oikos-desktop"
|
||||||
keyringUser = "oikos"
|
keyringUser = "oikos"
|
||||||
@@ -330,6 +333,13 @@ func newAssetHandler(cfg *OikosConfig) http.Handler {
|
|||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
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" {
|
if path == "/" || path == "/index.html" {
|
||||||
data, err := fs.ReadFile(distFS, "index.html")
|
data, err := fs.ReadFile(distFS, "index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
1
cmd/desktop/runtime.js
Normal file
1
cmd/desktop/runtime.js
Normal file
File diff suppressed because one or more lines are too long
@@ -11,6 +11,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
<script src="/wails/runtime.js"></script>
|
||||||
<script>window.__OIKOS_CONFIG__ = {};</script>
|
<script>window.__OIKOS_CONFIG__ = {};</script>
|
||||||
<script type="module" src="/src/main.ts"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user