???
This commit is contained in:
parent
30062807a3
commit
1fbc5ca87e
4 changed files with 2 additions and 48 deletions
41
examples/index.html
Normal file
41
examples/index.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<button onclick="greet()">Greet</button>
|
||||
<button onclick="file()">Read File</button>
|
||||
<button onclick="directory()">List Directory</button>
|
||||
<button onclick="notify()">Notify</button>
|
||||
|
||||
<script>
|
||||
function greet() {
|
||||
tiramisu.invoke("hello", "world")
|
||||
.then(response => alert(response))
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
function file() {
|
||||
const filename = prompt("Enter the filename to read:");
|
||||
if (!filename) return;
|
||||
tiramisu.fs.readFile(filename)
|
||||
.then(data => alert("File content: " + data))
|
||||
.catch(error => alert("Error reading file: " + error.message));
|
||||
}
|
||||
|
||||
function directory() {
|
||||
const dirname = prompt("Enter the directory to list:");
|
||||
if (!dirname) return;
|
||||
tiramisu.fs.readDir(dirname)
|
||||
.then(files => alert("Files: " + files.join(", ")))
|
||||
.catch(error => alert("Error listing directory: " + error.message));
|
||||
}
|
||||
|
||||
function notify() {
|
||||
const message = prompt("Enter the notification message:");
|
||||
if (!message) return;
|
||||
tiramisu.notifications.notify(message)
|
||||
.then(() => alert("Notification sent!"))
|
||||
.catch(error => alert("Error sending notification: " + error.message));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
37
examples/main.go
Normal file
37
examples/main.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
_ "embed"
|
||||
|
||||
t "git.iwakura.rip/grng/tiramisu"
|
||||
webview "github.com/webview/webview_go"
|
||||
)
|
||||
|
||||
//go:embed index.html
|
||||
var html string
|
||||
|
||||
func main() {
|
||||
app := t.New(t.TiramisuOptions{
|
||||
Debug: true,
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Title: "Tiramisu",
|
||||
Hints: webview.HintFixed,
|
||||
})
|
||||
|
||||
app.Run(func() {
|
||||
app.Bind("hello", func(args ...any) (any, error) {
|
||||
if len(args) == 0 {
|
||||
return "Hello, World!", nil
|
||||
}
|
||||
if len(args) == 1 {
|
||||
return fmt.Sprintf("Hello, %s!", args[0]), nil
|
||||
}
|
||||
return "Hello, unknown!", nil
|
||||
})
|
||||
|
||||
app.HTML(html)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue