5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 15:42:18 +08:00
wails/v3/examples/services/main.go
Lea Anthony ef8c886b10
Ignore internal service methods when binding (#3720)
* Ignore internal service methods when binding

* Updated changelog.md
2024-09-09 08:36:19 +10:00

69 lines
1.7 KiB
Go

package main
import (
"embed"
"github.com/wailsapp/wails/v3/examples/services/hashes"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/services/fileserver"
"github.com/wailsapp/wails/v3/pkg/services/kvstore"
"github.com/wailsapp/wails/v3/pkg/services/log"
"github.com/wailsapp/wails/v3/pkg/services/sqlite"
"log/slog"
"os"
"path/filepath"
"runtime"
)
//go:embed assets/*
var assets embed.FS
func main() {
// Get the local directory of this source file
// This isn't needed when running the example with `go run .`
// but is needed when running the example from an IDE
_, thisFile, _, _ := runtime.Caller(0)
localDir := filepath.Dir(thisFile)
rootPath := filepath.Join(localDir, "files")
app := application.New(application.Options{
Name: "Services Demo",
Description: "A demo of the services API",
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
LogLevel: slog.LevelDebug,
Services: []application.Service{
application.NewService(hashes.New()),
application.NewService(sqlite.New(&sqlite.Config{
DBFile: "test.db",
})),
application.NewService(kvstore.New(&kvstore.Config{
Filename: "store.json",
AutoSave: true,
})),
application.NewService(log.New()),
application.NewService(fileserver.New(&fileserver.Config{
RootPath: rootPath,
}), application.ServiceOptions{
Route: "/files",
}),
},
Assets: application.AssetOptions{
Handler: application.BundledAssetFileServer(assets),
},
})
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Width: 1024,
Height: 768,
})
err := app.Run()
if err != nil {
println(err.Error())
os.Exit(1)
}
}