2023-05-03 23:38:54 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2023-07-28 12:30:05 +08:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2023-05-30 11:04:11 +08:00
|
|
|
"runtime/debug"
|
|
|
|
"strings"
|
2023-05-03 23:38:54 +08:00
|
|
|
|
2023-05-05 23:23:34 +08:00
|
|
|
backend "rwkv-runner/backend-golang"
|
|
|
|
|
2023-05-03 23:38:54 +08:00
|
|
|
"github.com/wailsapp/wails/v2"
|
2023-12-11 12:02:24 +08:00
|
|
|
wailsLogger "github.com/wailsapp/wails/v2/pkg/logger"
|
2023-05-03 23:38:54 +08:00
|
|
|
"github.com/wailsapp/wails/v2/pkg/options"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
2023-06-20 22:22:14 +08:00
|
|
|
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
2023-05-03 23:38:54 +08:00
|
|
|
)
|
|
|
|
|
2023-07-28 12:30:05 +08:00
|
|
|
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, "/")
|
2023-10-27 11:36:29 +08:00
|
|
|
requestedFilename = strings.TrimPrefix(requestedFilename, "=>") // absolute path
|
2023-07-28 12:30:05 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-05-03 23:38:54 +08:00
|
|
|
//go:embed all:frontend/dist
|
|
|
|
var assets embed.FS
|
|
|
|
|
2023-05-29 09:39:16 +08:00
|
|
|
//go:embed all:py310/Lib/site-packages/cyac
|
|
|
|
var cyac embed.FS
|
|
|
|
|
2023-10-25 22:40:39 +08:00
|
|
|
//go:embed all:py310/Lib/site-packages/cyac-1.9.dist-info
|
2023-05-29 09:39:16 +08:00
|
|
|
var cyacInfo embed.FS
|
|
|
|
|
|
|
|
//go:embed backend-python
|
|
|
|
var py embed.FS
|
|
|
|
|
2023-08-16 23:07:58 +08:00
|
|
|
//go:embed backend-rust
|
|
|
|
var webgpu embed.FS
|
|
|
|
|
2023-07-03 17:41:47 +08:00
|
|
|
//go:embed finetune
|
|
|
|
var finetune embed.FS
|
|
|
|
|
2023-07-28 12:30:05 +08:00
|
|
|
//go:embed midi
|
|
|
|
var midi embed.FS
|
|
|
|
|
|
|
|
//go:embed assets/sound-font
|
|
|
|
var midiAssets embed.FS
|
|
|
|
|
2023-08-27 22:53:18 +08:00
|
|
|
//go:embed components
|
|
|
|
var components embed.FS
|
|
|
|
|
2023-05-03 23:38:54 +08:00
|
|
|
func main() {
|
2023-12-11 12:02:24 +08:00
|
|
|
dev := true
|
2023-05-30 11:04:11 +08:00
|
|
|
if buildInfo, ok := debug.ReadBuildInfo(); !ok || strings.Contains(buildInfo.String(), "-ldflags") {
|
2023-12-11 12:02:24 +08:00
|
|
|
dev = false
|
|
|
|
|
2023-11-07 22:23:26 +08:00
|
|
|
backend.CopyEmbed(assets)
|
2023-10-25 22:40:39 +08:00
|
|
|
os.RemoveAll("./py310/Lib/site-packages/cyac-1.7.dist-info")
|
2023-05-30 11:04:11 +08:00
|
|
|
backend.CopyEmbed(cyac)
|
|
|
|
backend.CopyEmbed(cyacInfo)
|
|
|
|
backend.CopyEmbed(py)
|
2023-08-16 23:07:58 +08:00
|
|
|
backend.CopyEmbed(webgpu)
|
2023-07-03 17:41:47 +08:00
|
|
|
backend.CopyEmbed(finetune)
|
2023-07-28 12:30:05 +08:00
|
|
|
backend.CopyEmbed(midi)
|
|
|
|
backend.CopyEmbed(midiAssets)
|
2023-08-27 22:53:18 +08:00
|
|
|
backend.CopyEmbed(components)
|
2023-05-30 11:04:11 +08:00
|
|
|
}
|
2023-05-29 09:39:16 +08:00
|
|
|
|
2023-05-03 23:38:54 +08:00
|
|
|
// Create an instance of the app structure
|
2023-05-05 23:23:34 +08:00
|
|
|
app := backend.NewApp()
|
2023-05-03 23:38:54 +08:00
|
|
|
|
2023-06-20 22:22:14 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-12-11 12:02:24 +08:00
|
|
|
var logger wailsLogger.Logger
|
|
|
|
if dev {
|
|
|
|
logger = wailsLogger.NewDefaultLogger()
|
|
|
|
} else {
|
|
|
|
logger = wailsLogger.NewFileLogger("crash.log")
|
|
|
|
}
|
|
|
|
|
2023-05-03 23:38:54 +08:00
|
|
|
// Create application with options
|
2023-06-20 22:22:14 +08:00
|
|
|
err = wails.Run(&options.App{
|
2023-10-25 22:40:39 +08:00
|
|
|
Title: "RWKV-Runner",
|
|
|
|
Width: 1024,
|
|
|
|
Height: 680,
|
|
|
|
MinWidth: 375,
|
|
|
|
MinHeight: 640,
|
2023-09-16 00:29:45 +08:00
|
|
|
EnableDefaultContextMenu: true,
|
2023-06-20 22:22:14 +08:00
|
|
|
Windows: &windows.Options{
|
|
|
|
ZoomFactor: zoomFactor,
|
|
|
|
IsZoomControlEnabled: true,
|
|
|
|
},
|
2023-05-03 23:38:54 +08:00
|
|
|
AssetServer: &assetserver.Options{
|
2023-07-28 12:30:05 +08:00
|
|
|
Assets: assets,
|
|
|
|
Handler: NewFileLoader(),
|
2023-05-03 23:38:54 +08:00
|
|
|
},
|
2023-08-27 22:53:18 +08:00
|
|
|
OnStartup: app.OnStartup,
|
|
|
|
OnBeforeClose: app.OnBeforeClose,
|
2023-05-13 20:15:18 +08:00
|
|
|
Bind: []any{
|
2023-05-03 23:38:54 +08:00
|
|
|
app,
|
|
|
|
},
|
2023-12-11 12:02:24 +08:00
|
|
|
Logger: logger,
|
2023-05-03 23:38:54 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
println("Error:", err.Error())
|
|
|
|
}
|
|
|
|
}
|