package main import ( "embed" "log" "log/slog" "net/http" "os" "path/filepath" "runtime" "github.com/wailsapp/wails/v3/pkg/application" ) //go:embed assets/* var assets embed.FS func main() { app := application.New(application.Options{ Name: "Screen Demo", Description: "A demo of the Screen API", Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, Windows: application.WindowsOptions{ WndProcInterceptor: nil, DisableQuitOnLastWindowClosed: false, WebviewUserDataPath: "", WebviewBrowserPath: "", }, Services: []application.Service{ application.NewService(&ScreenService{}), }, LogLevel: slog.LevelError, Assets: application.AssetOptions{ Handler: application.BundledAssetFileServer(assets), Middleware: func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Disable caching w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Pragma", "no-cache") w.Header().Set("Expires", "0") _, filename, _, _ := runtime.Caller(0) dir := filepath.Dir(filename) url := r.URL.Path path := dir + "/assets" + url if _, err := os.Stat(path); err == nil { // Serve file from disk to make testing easy http.ServeFile(w, r, path) } else { // Passthrough to the default asset handler if file not found on disk next.ServeHTTP(w, r) } }) }, }, }) app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ Title: "Screen Demo", Width: 800, Height: 600, Mac: application.MacWindow{ Backdrop: application.MacBackdropTranslucent, TitleBar: application.MacTitleBarHiddenInsetUnified, InvisibleTitleBarHeight: 50, }, }) err := app.Run() if err != nil { log.Fatal(err.Error()) } }