-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
113 lines (106 loc) · 3.01 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"context"
"embed"
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-dalledress/app"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/daemons"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/messages"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/types"
"github.com/wailsapp/wails/v2"
wLogger "github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
if os.Getenv("TB_CMD_LINE") == "true" {
logger.Info("Running in console mode")
a := app.NewApp()
ctx := context.Background()
a.Startup(ctx)
a.DomReady(ctx)
a.HandleLines()
} else {
a := app.NewApp()
opts := options.App{
Title: a.GetSession().Title,
Width: a.GetSession().Width,
Height: a.GetSession().Height,
OnStartup: a.Startup,
OnDomReady: a.DomReady,
OnShutdown: a.Shutdown,
BackgroundColour: nil,
LogLevel: wLogger.ERROR,
Menu: a.GetMenus(),
// Find: NewViews
Bind: []interface{}{
a,
&messages.DocumentMsg{},
&messages.ErrorMsg{},
&messages.ProgressMsg{},
&messages.DaemonMsg{},
&daemons.Daemon{},
&coreTypes.Transaction{},
&types.SummaryAbis{},
&types.SummaryIndex{},
&types.SummaryManifest{},
&types.SummaryMonitor{},
&types.SummaryName{},
&types.SummaryStatus{},
},
EnumBind: []interface{}{
types.NameParts,
daemons.Types,
daemons.States,
messages.Messages,
},
StartHidden: true,
AssetServer: &assetserver.Options{
Assets: assets,
},
}
http.HandleFunc("/files/", func(w http.ResponseWriter, r *http.Request) {
address := strings.TrimPrefix(r.URL.Path, "/files/")
parts := strings.Split(address, "&")
if len(parts) > 1 {
address = parts[0]
}
if address == "" {
http.Error(w, "Address not provided", http.StatusBadRequest)
return
}
cwd, err := os.Getwd()
if err != nil {
http.Error(w, "Error getting current working directory", http.StatusInternalServerError)
return
}
filePath := filepath.Join(cwd, "output", a.Series.Suffix, "annotated", address+".png")
if _, err := os.Stat(filePath); os.IsNotExist(err) {
msg := fmt.Sprintf("File not found at %s", filePath)
http.Error(w, msg, http.StatusNotFound)
return
}
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
http.ServeFile(w, r, filePath)
})
go func() {
logger.Info("Starting file server on :8889")
if err := http.ListenAndServe(":8889", nil); err != nil {
logger.Error("File server error:", err)
}
}()
if err := wails.Run(&opts); err != nil {
fmt.Println("Error:", err.Error())
}
}
}