mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-09 06:52:41 +08:00
Update system.Environment
This commit is contained in:
parent
e92994d2e7
commit
aba82cc527
19
v3/examples/environment/README.md
Normal file
19
v3/examples/environment/README.md
Normal file
@ -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
v3/examples/environment/assets/index.html
Normal file
66
v3/examples/environment/assets/index.html
Normal file
@ -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
v3/examples/environment/main.go
Normal file
43
v3/examples/environment/main.go
Normal file
@ -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())
|
||||||
|
}
|
||||||
|
}
|
@ -44,9 +44,20 @@ export function Capabilities() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} EnvironmentInfo
|
* @typedef {Object} OSInfo
|
||||||
* @property {string} OS - The operating system in use.
|
* @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 {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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package application
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/wailsapp/wails/v3/internal/operatingsystem"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@ -891,11 +892,15 @@ func (a *App) BrowserOpenFile(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Environment() EnvironmentInfo {
|
func (a *App) Environment() EnvironmentInfo {
|
||||||
return EnvironmentInfo{
|
info, _ := operatingsystem.Info()
|
||||||
OS: runtime.GOOS,
|
result := EnvironmentInfo{
|
||||||
Arch: runtime.GOARCH,
|
OS: runtime.GOOS,
|
||||||
Debug: a.isDebugMode,
|
Arch: runtime.GOARCH,
|
||||||
|
Debug: a.isDebugMode,
|
||||||
|
OSInfo: info,
|
||||||
}
|
}
|
||||||
|
result.PlatformInfo = a.platformEnvironment()
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) shouldQuit() bool {
|
func (a *App) shouldQuit() bool {
|
||||||
|
@ -355,3 +355,7 @@ func (a *App) logPlatformInfo() {
|
|||||||
a.info("Platform Info:", info.AsLogSlice()...)
|
a.info("Platform Info:", info.AsLogSlice()...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) platformEnvironment() map[string]any {
|
||||||
|
return map[string]any{}
|
||||||
|
}
|
||||||
|
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
package application
|
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 "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -216,3 +226,33 @@ func processWindowEvent(windowID C.uint, eventID C.uint) {
|
|||||||
EventID: uint(eventID),
|
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
|
||||||
|
}
|
||||||
|
@ -350,3 +350,11 @@ func (a *App) logPlatformInfo() {
|
|||||||
|
|
||||||
a.info("Platform Info:", args...)
|
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
|
||||||
|
}
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
|
import "github.com/wailsapp/wails/v3/internal/operatingsystem"
|
||||||
|
|
||||||
// EnvironmentInfo represents information about the current environment.
|
// EnvironmentInfo represents information about the current environment.
|
||||||
//
|
//
|
||||||
// Fields:
|
// Fields:
|
||||||
// - OS: the operating system that the program is running on.
|
// - OS: the operating system that the program is running on.
|
||||||
// - Arch: the architecture of the operating system.
|
// - Arch: the architecture of the operating system.
|
||||||
// - Debug: indicates whether debug mode is enabled.
|
// - Debug: indicates whether debug mode is enabled.
|
||||||
|
// - OSInfo: information about the operating system.
|
||||||
type EnvironmentInfo struct {
|
type EnvironmentInfo struct {
|
||||||
OS string
|
OS string
|
||||||
Arch string
|
Arch string
|
||||||
Debug bool
|
Debug bool
|
||||||
|
OSInfo *operatingsystem.OS
|
||||||
|
PlatformInfo map[string]any
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user