Skip to content

Commit

Permalink
Update system.Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Mar 19, 2024
1 parent e92994d commit aba82cc
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 10 deletions.
19 changes: 19 additions & 0 deletions v3/examples/environment/README.md
Original file line number Diff line number Diff line change
@@ -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 | |
66 changes: 66 additions & 0 deletions v3/examples/environment/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Screens Demo</title>
<style>
body {
padding-top: 75px;
margin: 0 auto;
color: white;
text-align: -webkit-center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif
}

article {
padding: 1em;
}

::-webkit-scrollbar-track {
background-color: #888;
}
.center {
text-align: -webkit-center;
}
th {
text-align: left;
}
tr {
border: 1px solid white;
}
th, td {
padding: 5px;

}
</style>
<script src="/wails/runtime.js"></script>
</head>
<body>

<script>
let environment = wails.System.Environment();
environment.then((result) => {
console.log({result})
let html = "";
html += "<h1 class='center'>Environment</h1><br><br>";
html += "<table>";
html += "<tr><td>Name</td><td>"+ result.OSInfo.Name +"</td></tr>";
html += "<tr><td>Branding</td><td>"+ result.OSInfo.Branding +"</td></tr>";
html += "<tr><td>Version</td><td>"+ result.OSInfo.Version +"</td></tr>";
html += "<tr><td>ID</td><td>"+ result.OSInfo.ID +"</td></tr>";
html += "<tr><td>GOOS</td><td>"+ result.OS +"</td></tr>";
html += "<tr><td>GOARCH</td><td>"+ result.Arch +"</td></tr>";
html += "<tr><td>Debug</td><td>"+ result.Debug +"</td></tr>";
if(result.PlatformInfo) {
for (let key in result.PlatformInfo) {
if (obj.hasOwnProperty(key)) {
html += "<tr><td>"+key+"</td><td>"+ result.PlatformInfo[key] +"</td></tr>";
}
}
}
html += "</table>";
document.body.innerHTML = html;
})
</script>
</body>
</html>
43 changes: 43 additions & 0 deletions v3/examples/environment/main.go
Original file line number Diff line number Diff line change
@@ -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())
}
}
15 changes: 13 additions & 2 deletions v3/internal/runtime/desktop/@wailsio/runtime/src/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/**
Expand Down
15 changes: 10 additions & 5 deletions v3/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package application
import (
"embed"
"encoding/json"
"github.com/wailsapp/wails/v3/internal/operatingsystem"
"io"
"log"
"log/slog"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions v3/pkg/application/application_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
40 changes: 40 additions & 0 deletions v3/pkg/application/application_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions v3/pkg/application/application_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 8 additions & 3 deletions v3/pkg/application/environment.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit aba82cc

Please sign in to comment.