加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin2li 提交于 2023-07-26 13:01 . Merge branch 'anki' into dev
package main
import (
"embed"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"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 all:thirdparty/ocr.py
// go:embed all:thirdparty/convert.py
// go:embed all:thirdparty/dist/pdf.exe
// var thirdpartyAsset embed.FS
var (
log *logrus.Logger
logger *logrus.Entry
logdir string
)
func main() {
defer func() {
if err := recover(); err != nil {
fmt.Println("Error:", err)
}
}()
// init logger
log = logrus.New()
if runtime.GOOS == "windows" {
logdir = filepath.Join(os.Getenv("USERPROFILE"), ".pdf_guru")
} else {
logdir = filepath.Join(os.Getenv("HOME"), ".pdf_guru")
}
err := os.MkdirAll(logdir, 0755)
if err != nil {
err = errors.Wrap(err, "failed to create log directory")
log.Fatal(err)
}
logpath := filepath.Join(logdir, "access.log")
file, err := os.OpenFile(logpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
err = errors.Wrap(err, "failed to create log file")
log.Fatal(err)
}
defer file.Close()
log.SetOutput(io.MultiWriter(os.Stdout, file))
log.SetLevel(logrus.DebugLevel)
log.SetReportCaller(true)
log.SetFormatter(&logrus.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
DisableColors: true,
})
logger = log.WithFields(logrus.Fields{
"service": "pdf-guru",
})
logger.Info("starting pdf-guru")
// Create an instance of the app structure
app := NewApp()
// Create application with options
err = wails.Run(&options.App{
Title: "PDF Guru",
Width: 1280,
Height: 700,
MinWidth: 1000,
MinHeight: 600,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
})
if err != nil {
err = errors.Wrap(err, "run wails app failed")
fmt.Println("Error:", err.Error())
}
logger.Info("exiting pdf-guru")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化