Files
file-tool-wails/main.go
2026-06-30 12:30:49 +08:00

79 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"context"
"embed"
"log"
"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 // DLL已存在
}
}
// 尝试释放嵌入的DLL
for _, name := range names {
p := filepath.Join(exeDir, name)
if err := os.WriteFile(p, mupdfDLL, 0644); err != nil {
// 记录错误但不崩溃
log.Printf("Failed to extract MuPDF DLL: %v", err)
} else {
return
}
}
// 如果都失败设置环境变量标记使用nofitz
log.Println("MuPDF DLL not available, will use nofitz mode for PDF operations")
os.Setenv("XK_NO_FITZ", "1")
}
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())
}
}