Files
file-tool-wails/main.go

79 lines
1.5 KiB
Go
Raw Normal View History

2026-06-11 15:46:19 +08:00
package main
import (
2026-06-17 08:05:20 +08:00
"context"
2026-06-11 15:46:19 +08:00
"embed"
2026-06-30 12:30:49 +08:00
"log"
2026-06-23 15:33:22 +08:00
"os"
"path/filepath"
2026-06-11 15:46:19 +08:00
"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
2026-06-23 15:33:22 +08:00
//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"}
2026-06-30 12:30:49 +08:00
// 检查是否已存在
2026-06-23 15:33:22 +08:00
for _, name := range names {
p := filepath.Join(exeDir, name)
if _, err := os.Stat(p); err == nil {
2026-06-30 12:30:49 +08:00
return // DLL已存在
2026-06-23 15:33:22 +08:00
}
}
2026-06-30 12:30:49 +08:00
// 尝试释放嵌入的DLL
2026-06-23 15:33:22 +08:00
for _, name := range names {
p := filepath.Join(exeDir, name)
2026-06-30 12:30:49 +08:00
if err := os.WriteFile(p, mupdfDLL, 0644); err != nil {
// 记录错误但不崩溃
log.Printf("Failed to extract MuPDF DLL: %v", err)
} else {
2026-06-23 15:33:22 +08:00
return
}
}
2026-06-30 12:30:49 +08:00
// 如果都失败设置环境变量标记使用nofitz
log.Println("MuPDF DLL not available, will use nofitz mode for PDF operations")
os.Setenv("XK_NO_FITZ", "1")
2026-06-23 15:33:22 +08:00
}
2026-06-11 15:46:19 +08:00
func main() {
app := NewApp()
2026-06-17 08:05:20 +08:00
fileHandler := NewFileHandler()
2026-06-11 15:46:19 +08:00
err := wails.Run(&options.App{
2026-06-23 15:33:22 +08:00
Title: "年糕工具",
2026-06-17 08:05:20 +08:00
Width: 1280,
Height: 860,
2026-06-11 15:46:19 +08:00
AssetServer: &assetserver.Options{
Assets: assets,
},
2026-06-17 08:05:20 +08:00
BackgroundColour: &options.RGBA{R: 13, G: 17, B: 23, A: 1},
OnStartup: func(ctx context.Context) {
app.startup(ctx)
fileHandler.startup(ctx)
},
2026-06-11 15:46:19 +08:00
Bind: []interface{}{
app,
2026-06-17 08:05:20 +08:00
fileHandler,
2026-06-11 15:46:19 +08:00
},
})
if err != nil {
println("Error:", err.Error())
}
}