fix: inject CSS to make macOS window draggable via Wails OnDomReady
This commit is contained in:
+30
-15
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -150,20 +152,41 @@ func main() {
|
||||
EditMenu.AddText("Paste", keys.CmdOrCtrl("v"), func(_ *menu.CallbackData) {})
|
||||
EditMenu.AddText("Select All", keys.CmdOrCtrl("a"), func(_ *menu.CallbackData) {})
|
||||
|
||||
// Wait for the backend URL to be set
|
||||
targetURL, _ := url.Parse(app.backendURL)
|
||||
proxy := httputil.NewSingleHostReverseProxy(targetURL)
|
||||
|
||||
// Start Wails application
|
||||
// We use a dummy handler for AssetServer to prevent wails from complaining
|
||||
// We use a Reverse Proxy to seamlessly proxy Wails' frontend to our Go backend
|
||||
err := wails.Run(&options.App{
|
||||
Title: "WeKnora Lite",
|
||||
Width: 1280,
|
||||
Height: 800,
|
||||
Menu: AppMenu,
|
||||
AssetServer: &assetserver.Options{
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}),
|
||||
Handler: proxy,
|
||||
},
|
||||
StartHidden: false, // Show window on startup
|
||||
OnStartup: app.startup,
|
||||
OnDomReady: func(ctx context.Context) {
|
||||
// Inject CSS to make the top area draggable for macOS hiddenInset titlebar
|
||||
css := `
|
||||
const style = document.createElement('style');
|
||||
style.innerHTML = ` + "`" + `
|
||||
.logo_row, .menu_top, .chat-header {
|
||||
--wails-draggable: drag !important;
|
||||
}
|
||||
.logo_row *, .menu_top *, .chat-header * {
|
||||
--wails-draggable: no-drag !important;
|
||||
}
|
||||
.sidebar-toggle, .logo_box {
|
||||
--wails-draggable: no-drag !important;
|
||||
}
|
||||
` + "`" + `;
|
||||
document.head.appendChild(style);
|
||||
`
|
||||
wailsruntime.WindowExecJS(ctx, css)
|
||||
},
|
||||
OnShutdown: app.shutdown,
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
@@ -199,16 +222,6 @@ func NewApp() *App {
|
||||
// so we can call the runtime methods
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
|
||||
// Navigate the Wails webview to our local Go backend
|
||||
// We use the wails runtime to change the URL programmatically
|
||||
go func() {
|
||||
// Navigate the Wails webview to our local Go backend
|
||||
// Wait a tiny bit just to ensure window is ready
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// Instead of WindowNavigate, we change the URL via javascript
|
||||
wailsruntime.WindowExecJS(a.ctx, fmt.Sprintf("window.location.href = '%s';", a.backendURL))
|
||||
}()
|
||||
}
|
||||
|
||||
func (a *App) shutdown(ctx context.Context) {
|
||||
@@ -232,7 +245,9 @@ func listenWithRetry(addr string, maxRetries int, baseDelay time.Duration) (net.
|
||||
lastErr = err
|
||||
if i < maxRetries-1 {
|
||||
delay := baseDelay * time.Duration(1<<uint(i))
|
||||
if delay > 3*time.Second { delay = 3 * time.Second }
|
||||
if delay > 3*time.Second {
|
||||
delay = 3 * time.Second
|
||||
}
|
||||
time.Sleep(delay)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user