Files
file-tool-wails/main.go
2026-06-23 15:33:22 +08:00

67 lines
1.2 KiB
Go

package main
import (
"context"
"embed"
"os"
"path/filepath"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed public/MuPDFLib.dll
var mupdfDLL []byte
func init() {
exe, err := os.Executable()
if err != nil {
return
}
exeDir := filepath.Dir(exe)
names := []string{"libmupdf.dll", "MuPDFLib.dll"}
for _, name := range names {
p := filepath.Join(exeDir, name)
if _, err := os.Stat(p); err == nil {
return
}
}
for _, name := range names {
p := filepath.Join(exeDir, name)
if err := os.WriteFile(p, mupdfDLL, 0644); err == nil {
return
}
}
}
func main() {
app := NewApp()
fileHandler := NewFileHandler()
err := wails.Run(&options.App{
Title: "年糕工具",
Width: 1280,
Height: 860,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 13, G: 17, B: 23, A: 1},
OnStartup: func(ctx context.Context) {
app.startup(ctx)
fileHandler.startup(ctx)
},
Bind: []interface{}{
app,
fileHandler,
},
})
if err != nil {
println("Error:", err.Error())
}
}