2023-01-18 21:42:49 +11:00
package main
import (
_ "embed"
"log"
"net/http"
2023-04-26 16:28:27 +02:00
"time"
2023-01-18 21:42:49 +11:00
"github.com/wailsapp/wails/v3/pkg/application"
)
func main () {
2023-02-09 18:35:26 +11:00
app := application . New ( application . Options {
2023-01-18 21:42:49 +11:00
Name : "Plain" ,
Description : "A demo of using raw HTML & CSS" ,
2023-02-09 18:35:26 +11:00
Mac : application . MacOptions {
2023-01-18 21:42:49 +11:00
ApplicationShouldTerminateAfterLastWindowClosed : true ,
},
2023-03-15 09:14:41 +01:00
Assets : application . AssetOptions {
Handler : http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) {
w . WriteHeader ( http . StatusOK )
2024-03-20 10:30:14 +01:00
w . Write ([] byte ( `<html><head><title>Plain Bundle</title><script type="module" src="/wails/runtime.js"></script></head><body><div class="main"><h1>Plain Bundle</h1><p>This is a plain bundle. It has no frontend code but this was Served by the AssetServer's Handler.</p><br/><br/><p wml-event="clicked">Clicking this paragraph emits an event...<p></div></body></html>` ))
2023-03-15 09:14:41 +01:00
}),
},
2023-01-18 21:42:49 +11:00
})
// Create window
2023-05-01 18:21:22 +10:00
app . NewWebviewWindowWithOptions ( application . WebviewWindowOptions {
2023-01-18 21:42:49 +11:00
Title : "Plain Bundle" ,
2023-07-01 03:55:10 +03:00
CSS : `body { background-color: rgb(255, 255, 255); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; user-select: none; -ms-user-select: none; -webkit-user-select: none; } .main { color: white; margin: 20%; }` ,
2023-02-09 18:35:26 +11:00
Mac : application . MacWindow {
2023-01-18 21:42:49 +11:00
InvisibleTitleBarHeight : 50 ,
2023-02-09 18:35:26 +11:00
Backdrop : application . MacBackdropTranslucent ,
2023-02-16 20:28:24 +11:00
TitleBar : application . MacTitleBarHiddenInsetUnified ,
2023-01-18 21:42:49 +11:00
},
URL : "/" ,
})
2023-06-05 20:34:52 +10:00
app . NewWebviewWindowWithOptions ( application . WebviewWindowOptions {
Title : "HTML TEST" ,
HTML : "<h1>AWESOME!</h1>" ,
2023-07-01 03:55:10 +03:00
CSS : `body { background-color: rgb(255, 0, 0); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; user-select: none; -ms-user-select: none; -webkit-user-select: none; } .main { color: white; margin: 20%; }` ,
2023-06-05 20:34:52 +10:00
JS : `window.iamhere = function() { console.log("Hello World!"); }` ,
})
2023-04-11 03:28:06 -05:00
app . Events . On ( "clicked" , func ( _ * application . WailsEvent ) {
2023-02-16 20:28:24 +11:00
println ( "clicked" )
})
2023-04-26 16:28:27 +02:00
go func () {
time . Sleep ( 5 * time . Second )
2023-05-01 18:21:22 +10:00
app . NewWebviewWindowWithOptions ( application . WebviewWindowOptions {
2023-04-26 16:28:27 +02:00
Title : "Plain Bundle new Window from GoRoutine" ,
Width : 500 ,
Height : 500 ,
Mac : application . MacWindow {
Backdrop : application . MacBackdropTranslucent ,
TitleBar : application . MacTitleBarHiddenInsetUnified ,
InvisibleTitleBarHeight : 50 ,
},
})
}()
2023-01-18 21:42:49 +11:00
err := app . Run ()
if err != nil {
log . Fatal ( err )
}
}