107 lines
3.2 KiB
Go
107 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
_ "embed"
|
|
"firefly-launcher/internal"
|
|
"firefly-launcher/pkg/constant"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
)
|
|
|
|
// Wails uses Go's `embed` package to embed the frontend files into the binary.
|
|
// Any files in the frontend/dist folder will be embedded into the binary and
|
|
// made available to the frontend.
|
|
// See https://pkg.go.dev/embed for more information.
|
|
|
|
//go:embed all:frontend/dist
|
|
var assets embed.FS
|
|
|
|
//go:embed all:assets
|
|
var tools embed.FS
|
|
|
|
func fileExists(path string) bool {
|
|
info, err := os.Stat(path)
|
|
return err == nil && !info.IsDir()
|
|
}
|
|
|
|
func extractFile(embedPath, outPath string) error {
|
|
data, err := tools.ReadFile(embedPath)
|
|
if err != nil {
|
|
return fmt.Errorf("can't read file embed %s: %w", embedPath, err)
|
|
}
|
|
|
|
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
|
|
return fmt.Errorf("can't create directory %s: %w", filepath.Dir(outPath), err)
|
|
}
|
|
|
|
return os.WriteFile(outPath, data, 0755)
|
|
}
|
|
|
|
// main function serves as the application's entry point. It initializes the application, creates a window,
|
|
// and starts a goroutine that emits a time-based event every second. It subsequently runs the application and
|
|
// logs any error that might occur.
|
|
func main() {
|
|
for outPath, embedPath := range constant.RequiredFiles {
|
|
if !fileExists(outPath.String()) {
|
|
err := extractFile(embedPath, outPath.String())
|
|
if err != nil {
|
|
fmt.Println("can't copy file:", err)
|
|
}
|
|
}
|
|
}
|
|
// Create a new Wails application by providing the necessary options.
|
|
// Variables 'Name' and 'Description' are for application metadata.
|
|
// 'Assets' configures the asset server with the 'FS' variable pointing to the frontend files.
|
|
// 'Bind' is a list of Go struct instances. The frontend has access to the methods of these instances.
|
|
// 'Mac' options tailor the application when running an macOS.
|
|
app := application.New(application.Options{
|
|
Name: "firefly-launcher",
|
|
Description: "Firefly Launcher - Kain",
|
|
Services: []application.Service{
|
|
application.NewService(&internal.FSService{}),
|
|
application.NewService(&internal.LanguageService{}),
|
|
application.NewService(&internal.GitService{}),
|
|
application.NewService(&internal.HdiffzService{}),
|
|
},
|
|
Assets: application.AssetOptions{
|
|
Handler: application.AssetFileServerFS(assets),
|
|
|
|
},
|
|
Mac: application.MacOptions{
|
|
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
|
},
|
|
})
|
|
|
|
// Create a new window with the necessary options.
|
|
// 'Title' is the title of the window.
|
|
// 'Mac' options tailor the window when running on macOS.
|
|
// 'BackgroundColour' is the background colour of the window.
|
|
// 'URL' is the URL that will be loaded into the webview.
|
|
|
|
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
|
|
|
Title: "Firefly Launcher - Kain",
|
|
Mac: application.MacWindow{
|
|
InvisibleTitleBarHeight: 50,
|
|
Backdrop: application.MacBackdropTranslucent,
|
|
TitleBar: application.MacTitleBarHiddenInset,
|
|
},
|
|
|
|
BackgroundColour: application.NewRGB(27, 38, 54),
|
|
Width: 1200,
|
|
Height: 600,
|
|
URL: "/",
|
|
DevToolsEnabled: true,
|
|
})
|
|
|
|
err := app.Run()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|