-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
84 lines (66 loc) · 1.76 KB
/
app.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
package main
import (
"context"
"time"
"github.com/gcerrato/godog-backend/pkg/core"
"github.com/gcerrato/godog-backend/pkg/fs"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
currentDirectory string
ctx context.Context
core *core.Core
fs *fs.FileScanner
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
core := core.NewCore()
core.Init(ctx)
a.core = core
a.currentDirectory = "."
a.fs = a.InitScanner(a.currentDirectory)
}
// Greet returns a greeting for the given name
func (a *App) GetReply(prompt string) string {
value, _ := a.core.GetReply(a.ctx, prompt)
return value
}
func (a *App) InitScanner(dirPath string) *fs.FileScanner {
scannerHelper := fs.NewScannerHelper()
opts := fs.FileScannerOpts{Interval: 10 * time.Millisecond, FilePath: dirPath, Rescursive: false}
filescanner := fs.GetFileScannerInstance(opts)
filescanner.AddObserver(scannerHelper)
go handleFiles(scannerHelper, a.core)
return filescanner
}
func handleFiles(sh *fs.ScannerHelper, core *core.Core) {
for {
files := <-sh.Notifications
for _, file := range files {
core.ProcessFile(context.Background(), file, sh)
}
}
}
func (a *App) SetDirectory() string {
path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{})
if err != nil {
// do something
}
if a.currentDirectory != path {
a.currentDirectory = path
}
return a.fs.UpdatePath(a.currentDirectory)
}
func (a *App) UploadDocuments() {
a.fs.Scan()
}
func (a *App) ConvertPDFToImages() {
// a.core.ConvertPDFToImages(a.fs.)
}