-
Notifications
You must be signed in to change notification settings - Fork 208
/
main.go
98 lines (86 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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")
}