-
Notifications
You must be signed in to change notification settings - Fork 503
/
main.go
135 lines (112 loc) · 3.03 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"embed"
"fmt"
"net/http"
"os"
"runtime/debug"
"strings"
backend "rwkv-runner/backend-golang"
"github.com/wailsapp/wails/v2"
wailsLogger "github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
type FileLoader struct {
http.Handler
}
func NewFileLoader() *FileLoader {
return &FileLoader{}
}
func (h *FileLoader) ServeHTTP(res http.ResponseWriter, req *http.Request) {
var err error
requestedFilename := strings.TrimPrefix(req.URL.Path, "/")
requestedFilename = strings.TrimPrefix(requestedFilename, "=>") // absolute path
println("Requesting file:", requestedFilename)
fileData, err := os.ReadFile(requestedFilename)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
res.Write([]byte(fmt.Sprintf("Could not load file %s", requestedFilename)))
}
res.Write(fileData)
}
//go:embed all:frontend/dist
var assets embed.FS
//go:embed all:py310/Lib/site-packages/cyac
var cyac embed.FS
//go:embed all:py310/Lib/site-packages/cyac-1.9.dist-info
var cyacInfo embed.FS
//go:embed backend-python
var py embed.FS
//go:embed backend-rust
var webgpu embed.FS
//go:embed all:finetune
var finetune embed.FS
//go:embed midi
var midi embed.FS
//go:embed assets/sound-font
var midiAssets embed.FS
//go:embed components
var components embed.FS
func main() {
// Create an instance of the app structure
app := backend.NewApp()
app.Dev = true
if buildInfo, ok := debug.ReadBuildInfo(); !ok || strings.Contains(buildInfo.String(), "-ldflags") {
app.Dev = false
backend.CopyEmbed(assets)
os.RemoveAll("./py310/Lib/site-packages/cyac-1.7.dist-info")
backend.CopyEmbed(cyac)
backend.CopyEmbed(cyacInfo)
backend.CopyEmbed(py)
backend.CopyEmbed(webgpu)
backend.CopyEmbed(finetune)
backend.CopyEmbed(midi)
backend.CopyEmbed(midiAssets)
backend.CopyEmbed(components)
}
var zoomFactor float64 = 1.0
data, err := app.ReadJson("config.json")
if err == nil {
app.HasConfigData = true
app.ConfigData = data.(map[string]any)
if dpiScaling, ok := app.ConfigData["settings"].(map[string]any)["dpiScaling"]; ok {
zoomFactor = dpiScaling.(float64) / 100
}
} else {
app.HasConfigData = false
}
var logger wailsLogger.Logger
if app.Dev {
logger = wailsLogger.NewDefaultLogger()
} else {
logger = wailsLogger.NewFileLogger("crash.log")
}
// Create application with options
err = wails.Run(&options.App{
Title: "RWKV-Runner",
Width: 1024,
Height: 700,
MinWidth: 375,
MinHeight: 640,
EnableDefaultContextMenu: true,
Windows: &windows.Options{
ZoomFactor: zoomFactor,
IsZoomControlEnabled: true,
},
AssetServer: &assetserver.Options{
Assets: assets,
Handler: NewFileLoader(),
},
OnStartup: app.OnStartup,
OnBeforeClose: app.OnBeforeClose,
Bind: []any{
app,
},
Logger: logger,
})
if err != nil {
println("Error:", err.Error())
}
}