5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-08 13:21:18 +08:00
wails/v3/examples/services/main.go
Atterpac e316cd0719
[V3] Plugins implemenations (#3570)
* plugin handler and lifecycle

* rebase

* remove reflect

s

* remove Config and NewPlugin from plugin template

* Remove plugin manager, generation of plugin interface

* implement http handlers for services

remove log

trim path

prefix wails/services

* update plugine example

* Misc updates

* Ported plugins to services, rewritten example

* Added fileserver

* Update OnStartup and use a context for the application

* Rename PathPrefix to Route. Create docs.

* Use service config copy. Add Name to Service Options. Improve service generation.

* Use service config copy. Add Name to Service Options. Improve service generation. Update README

* Remove rogue db

* Update changelog.md

---------

Co-authored-by: Lea O'Anthony <lea.anthony@gmail.com>
2024-09-01 17:26:22 +10:00

62 lines
1.4 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"
)
//go:embed assets/*
var assets embed.FS
func main() {
rootPath, _ := filepath.Abs("./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)
}
}