5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-11 14:39:30 +08:00

Update vanilla+js template and dependencies

The frontend interaction has been significantly updated, including improvements to the Greet function and the addition of an ongoing time display. Additionally, dependencies in package.json have been updated to their latest versions. Also, redundant print statement was removed from messageprocessor_call.go and changes were made to layout structure and styles in the main.go.tmpl and index.html files.
This commit is contained in:
Lea Anthony 2023-12-30 21:11:38 +11:00
parent d423c1c366
commit c531c714d4
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
5 changed files with 54 additions and 26 deletions

View File

@ -27,17 +27,27 @@ func main() {
}) })
// Create window // Create window
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "Plain Bundle", Title: "Window 1",
CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`,
Mac: application.MacWindow{ Mac: application.MacWindow{
InvisibleTitleBarHeight: 50, InvisibleTitleBarHeight: 50,
Backdrop: application.MacBackdropTranslucent, Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset, TitleBar: application.MacTitleBarHiddenInset,
}, },
BackgroundColour: application.NewRGB(36, 36, 36),
URL: "/", URL: "/",
}) })
go func() {
for {
now := time.Now().Format(time.RFC1123)
app.Events.Emit(&application.WailsEvent{
Name: "time",
Data: now,
})
time.Sleep(time.Second)
}
}()
err := app.Run() err := app.Run()
if err != nil { if err != nil {

View File

@ -17,9 +17,17 @@
<img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo"/> <img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo"/>
</a> </a>
</div> </div>
<h1>Hello Wails!</h1> <h1>Wails + Javascript</h1>
<div>
<p id="time">Listening for Time event...</p>
</div>
<div class="card"> <div class="card">
<button id="test" onclick="doGreet()">Press me!</button> <label for="name">Enter your name</label>
<input id="name" type="text"/>
<button onclick="doGreet()">Press me!</button>
</div>
<div>
<p id="greeting">&nbsp;</p>
</div> </div>
<p class="read-the-docs"> <p class="read-the-docs">
Click on the Wails logo to learn more Click on the Wails logo to learn more

View File

@ -1,9 +1,20 @@
import {Greet} from "./bindings/main/GreetService.js"; import {Greet} from "./bindings/main/GreetService.js";
import {Events} from "@wailsio/runtime";
window.doGreet = () => { window.doGreet = () => {
Greet('test').then((result) => { let name = document.getElementById('name').value;
console.log(result); if (!name) {
name = 'from Go';
}
Greet(name).then((result) => {
let element = document.getElementById('greeting');
element.innerText = result;
}).catch((err) => { }).catch((err) => {
console.log(err); console.log(err);
}); });
} }
Events.On('time', (time) => {
let element = document.getElementById('time');
element.innerText = time.data;
});

View File

@ -9,7 +9,7 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"devDependencies": { "devDependencies": {
"vite": "^4.0.0", "vite": "^5.0.0",
"@wailsio/runtime": "^3.0.0-alpha.6" "@wailsio/runtime": "latest"
} }
} }

View File

@ -26,7 +26,6 @@ func (m *MessageProcessor) processCallMethod(method int, rw http.ResponseWriter,
m.httpError(rw, "Unable to parse arguments: %s", err.Error()) m.httpError(rw, "Unable to parse arguments: %s", err.Error())
return return
} }
fmt.Println("processCallMethod", args)
callID := args.String("call-id") callID := args.String("call-id")
if callID == nil { if callID == nil {
m.Error("call-id is required") m.Error("call-id is required")