mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-10 02:51:35 +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:
parent
d423c1c366
commit
c531c714d4
@ -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 {
|
||||||
|
@ -8,23 +8,31 @@
|
|||||||
<title>Wails App</title>
|
<title>Wails App</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div>
|
<div>
|
||||||
<a wml-openURL="https://wails.io">
|
<a wml-openURL="https://wails.io">
|
||||||
<img src="/wails.png" class="logo" alt="Wails logo"/>
|
<img src="/wails.png" class="logo" alt="Wails logo"/>
|
||||||
</a>
|
</a>
|
||||||
<a wml-openURL="https://developer.mozilla.org/en-US/docs/Web/JavaScript">
|
<a wml-openURL="https://developer.mozilla.org/en-US/docs/Web/JavaScript">
|
||||||
<img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo"/>
|
<img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
<h1>Hello Wails!</h1>
|
|
||||||
<div class="card">
|
|
||||||
<button id="test" onclick="doGreet()">Press me!</button>
|
|
||||||
</div>
|
|
||||||
<p class="read-the-docs">
|
|
||||||
Click on the Wails logo to learn more
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<script type="module" src="/main.js"></script>
|
<h1>Wails + Javascript</h1>
|
||||||
|
<div>
|
||||||
|
<p id="time">Listening for Time event...</p>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<label for="name">Enter your name</label>
|
||||||
|
<input id="name" type="text"/>
|
||||||
|
<button onclick="doGreet()">Press me!</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p id="greeting"> </p>
|
||||||
|
</div>
|
||||||
|
<p class="read-the-docs">
|
||||||
|
Click on the Wails logo to learn more
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<script type="module" src="/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -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;
|
||||||
|
});
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user