diff --git a/v3/examples/environment/README.md b/v3/examples/environment/README.md new file mode 100644 index 00000000000..1f922f34138 --- /dev/null +++ b/v3/examples/environment/README.md @@ -0,0 +1,19 @@ +# Screen Example + +This example will detect all attached screens and display their details. + +## Running the example + +To run the example, simply run the following command: + +```bash +go run . +``` + +# Status + +| Platform | Status | +|----------|---------| +| Mac | Working | +| Windows | Working | +| Linux | | diff --git a/v3/examples/environment/assets/index.html b/v3/examples/environment/assets/index.html new file mode 100644 index 00000000000..790dd4ff298 --- /dev/null +++ b/v3/examples/environment/assets/index.html @@ -0,0 +1,66 @@ + + + + + Screens Demo + + + + + + + + \ No newline at end of file diff --git a/v3/examples/environment/main.go b/v3/examples/environment/main.go new file mode 100644 index 00000000000..3a326f4ebcc --- /dev/null +++ b/v3/examples/environment/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed assets/* +var assets embed.FS + +func main() { + + app := application.New(application.Options{ + Name: "Environment Demo", + Description: "A demo of the Environment API", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + Assets: application.AssetOptions{ + Handler: application.BundledAssetFileServer(assets), + }, + }) + + app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + Title: "Environment 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()) + } +} diff --git a/v3/internal/runtime/desktop/@wailsio/runtime/src/system.js b/v3/internal/runtime/desktop/@wailsio/runtime/src/system.js index 204ae23469f..8341ac842a5 100644 --- a/v3/internal/runtime/desktop/@wailsio/runtime/src/system.js +++ b/v3/internal/runtime/desktop/@wailsio/runtime/src/system.js @@ -44,9 +44,20 @@ export function Capabilities() { } /** - * @typedef {object} EnvironmentInfo - * @property {string} OS - The operating system in use. + * @typedef {Object} OSInfo + * @property {string} Branding - The branding of the OS. + * @property {string} ID - The ID of the OS. + * @property {string} Name - The name of the OS. + * @property {string} Version - The version of the OS. + */ + +/** + * @typedef {Object} EnvironmentInfo * @property {string} Arch - The architecture of the system. + * @property {boolean} Debug - True if the application is running in debug mode, otherwise false. + * @property {string} OS - The operating system in use. + * @property {OSInfo} OSInfo - Details of the operating system. + * @property {Object} PlatformInfo - Additional platform information. */ /** diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 6c8814d719d..e0573cc9abf 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -3,6 +3,7 @@ package application import ( "embed" "encoding/json" + "github.com/wailsapp/wails/v3/internal/operatingsystem" "io" "log" "log/slog" @@ -891,11 +892,15 @@ func (a *App) BrowserOpenFile(path string) error { } func (a *App) Environment() EnvironmentInfo { - return EnvironmentInfo{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, - Debug: a.isDebugMode, - } + info, _ := operatingsystem.Info() + result := EnvironmentInfo{ + OS: runtime.GOOS, + Arch: runtime.GOARCH, + Debug: a.isDebugMode, + OSInfo: info, + } + result.PlatformInfo = a.platformEnvironment() + return result } func (a *App) shouldQuit() bool { diff --git a/v3/pkg/application/application_darwin.go b/v3/pkg/application/application_darwin.go index c540e95f126..68ae516bff5 100644 --- a/v3/pkg/application/application_darwin.go +++ b/v3/pkg/application/application_darwin.go @@ -355,3 +355,7 @@ func (a *App) logPlatformInfo() { a.info("Platform Info:", info.AsLogSlice()...) } + +func (a *App) platformEnvironment() map[string]any { + return map[string]any{} +} diff --git a/v3/pkg/application/application_linux.go b/v3/pkg/application/application_linux.go index 9ce6d3a1c62..705fffaf6ab 100644 --- a/v3/pkg/application/application_linux.go +++ b/v3/pkg/application/application_linux.go @@ -2,6 +2,16 @@ package application +/* + #include "gtk/gtk.h" + #include "webkit2/webkit2.h" + static guint get_compiled_gtk_major_version() { return GTK_MAJOR_VERSION; } + static guint get_compiled_gtk_minor_version() { return GTK_MINOR_VERSION; } + static guint get_compiled_gtk_micro_version() { return GTK_MICRO_VERSION; } + static guint get_compiled_webkit_major_version() { return WEBKIT_MAJOR_VERSION; } + static guint get_compiled_webkit_minor_version() { return WEBKIT_MINOR_VERSION; } + static guint get_compiled_webkit_micro_version() { return WEBKIT_MICRO_VERSION; } +*/ import "C" import ( "fmt" @@ -216,3 +226,33 @@ func processWindowEvent(windowID C.uint, eventID C.uint) { EventID: uint(eventID), } } + +func buildVersionString(major, minor, micro C.uint) string { + return fmt.Sprintf("%d.%d.%d", uint(major), uint(minor), uint(micro)) +} + +func (a *App) platformEnvironment() map[string]any { + result := map[string]any{} + result["gtk3-compiled"] = buildVersionString( + C.get_compiled_gtk_major_version(), + C.get_compiled_gtk_minor_version(), + C.get_compiled_gtk_micro_version(), + ) + result["gtk3-runtime"] = buildVersionString( + C.gtk_get_major_version(), + C.gtk_get_minor_version(), + C.gtk_get_micro_version(), + ) + + result["webkit2gtk-compiled"] = buildVersionString( + C.get_compiled_webkit_major_version(), + C.get_compiled_webkit_minor_version(), + C.get_compiled_webkit_micro_version(), + ) + result["webkit2gtk-runtime"] = buildVersionString( + C.webkit_get_major_version(), + C.webkit_get_minor_version(), + C.webkit_get_micro_version(), + ) + return result +} diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index c4811f08db5..430852e273b 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -350,3 +350,11 @@ func (a *App) logPlatformInfo() { a.info("Platform Info:", args...) } + +func (a *App) platformEnvironment() map[string]any { + result := map[string]any{} + webviewVersion, _ := webviewloader.GetAvailableCoreWebView2BrowserVersionString(a.options.Windows.WebviewBrowserPath) + result["Go-WebView2Loader"] = webviewloader.UsingGoWebview2Loader + result["WebView2"] = webviewVersion + return result +} diff --git a/v3/pkg/application/environment.go b/v3/pkg/application/environment.go index 4a0f303d90c..68be3ba06d5 100644 --- a/v3/pkg/application/environment.go +++ b/v3/pkg/application/environment.go @@ -1,13 +1,18 @@ package application +import "github.com/wailsapp/wails/v3/internal/operatingsystem" + // EnvironmentInfo represents information about the current environment. // // Fields: // - OS: the operating system that the program is running on. // - Arch: the architecture of the operating system. // - Debug: indicates whether debug mode is enabled. +// - OSInfo: information about the operating system. type EnvironmentInfo struct { - OS string - Arch string - Debug bool + OS string + Arch string + Debug bool + OSInfo *operatingsystem.OS + PlatformInfo map[string]any }