Files
Firefly_Launcher/main.go
2025-08-25 18:12:13 +07:00

107 lines
2.6 KiB
Go

package main
import (
"embed"
_ "embed"
appService "firefly-launcher/internal/app-service"
diffService "firefly-launcher/internal/diff-service"
fsService "firefly-launcher/internal/fs-service"
gitService "firefly-launcher/internal/git-service"
languageService "firefly-launcher/internal/language-service"
"firefly-launcher/pkg/constant"
"fmt"
"log"
"os"
"path/filepath"
"github.com/wailsapp/wails/v3/pkg/application"
)
//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)
}
func main() {
// Extract required files
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)
}
}
}
// Remove old executable
exePath, err := os.Executable()
if err == nil {
dir := filepath.Dir(exePath)
base := filepath.Base(exePath)
oldPath := filepath.Join(dir, "."+base+".old")
fmt.Println("Old executable path:", oldPath)
os.Remove(oldPath)
}
// Create application
app := application.New(application.Options{
Name: "firefly-launcher",
Description: "Firefly Launcher - Kain",
Services: []application.Service{
application.NewService(&fsService.FSService{}),
application.NewService(&languageService.LanguageService{}),
application.NewService(&gitService.GitService{}),
application.NewService(&diffService.DiffService{}),
application.NewService(&appService.AppService{}),
},
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
// Create window
app.Window.NewWithOptions(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)
}
}