5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 07:29:56 +08:00
wails/v3/examples/screen/main.go
Mohamed Gharib efe0c8d534
[v3-Windows] New DIP system for Enhanced High DPI Monitor Support (#3665)
* [v3-Windows] New DIP system for Enhanced High DPI Monitor Support

* Update changelog

* Remove asset middleware

* Remove SetThreadDpiAwarenessContext()

* Fix macOS build.

* Fill missing screens fields (linux, darwin)

* Skip DPI transformation on unsupported platforms

* Simplify distanceFromRectSquared()

* Update v3/pkg/application/screenmanager.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-09-22 08:38:30 +10:00

79 lines
1.9 KiB
Go

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())
}
}