Support Screens API

This commit is contained in:
Lea Anthony
2023-02-15 18:56:52 +11:00
parent 045a830fbc
commit a5e10557c5
16 changed files with 347 additions and 119 deletions
+66
View 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;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
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;
}
.monitor {
width: 300px;
height: 150px;
overflow-y: scroll;
border: solid 1em #333;
border-radius: .5em;
background: lightblue;
}
.monitor::-webkit-scrollbar {
width: 15px;
}
.monitor::-webkit-scrollbar-thumb {
background: #666;
}
::-webkit-scrollbar-track {
background-color: #888;
}
.center {
text-align: -webkit-center;
}
</style>
</head>
<body>
<script>
let monitors = wails.Screens.GetAll();
monitors.then((result) => {
console.log({result})
let html = "";
for (let i = 0; i < result.length; i++) {
html += "<article class='center'><div class='monitor'><div style='padding:5px;'>";
let hidpi = result[i].scale === 2 ? " (HiDPI)" : "";
html += "<h3 class='center'>"+result[i].name+"</h3>";
html += "<h4 class='center'>"+hidpi+"</h4>";
html += "<h4 class='center'>"+result[i].size.width+"x"+result[i].size.height+"</h4>";
html += "</div></div></article>";
}
document.body.innerHTML = html;
})
</script>
</body>
</html>
+43
View 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: "Screen Demo",
Description: "A demo of the Screen API",
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{
Title: "Screen Demo",
Width: 800,
Height: 600,
Assets: application.AssetOptions{
FS: assets,
},
Mac: application.MacWindow{
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInsetUnified,
InvisibleTitleBarHeight: 50,
},
})
err := app.Run()
if err != nil {
log.Fatal(err.Error())
}
}