package main import ( "context" "embed" "flag" "fmt" "log" "os" "time" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" "github.com/wailsapp/wails/v2/pkg/options/mac" ) //go:embed all:frontend/dist var assets embed.FS //go:embed static/vectors/Former.svg var formerLogoSVG []byte func main() { // CLI flags flagHeight := flag.Float64("height", DefaultStencilHeight, "Stencil height in mm") flagWallHeight := flag.Float64("wall-height", DefaultWallHeight, "Wall height in mm") flagWallThickness := flag.Float64("wall-thickness", DefaultWallThickness, "Wall thickness in mm") flagDPI := flag.Float64("dpi", DefaultDPI, "DPI for rendering") flagKeepPNG := flag.Bool("keep-png", false, "Save intermediate PNG file") flag.Parse() // If files are passed as arguments, run in CLI mode if flag.NArg() > 0 { cfg := Config{ StencilHeight: *flagHeight, WallHeight: *flagWallHeight, WallThickness: *flagWallThickness, DPI: *flagDPI, KeepPNG: *flagKeepPNG, } runCLI(cfg, flag.Args()) return } // Ensure working directories exist cwd, _ := os.Getwd() debugLog("CWD: %s", cwd) debugLog("Ensuring ~/former dirs (includes temp)...") ensureFormerDirs() debugLog("Startup complete, launching GUI") runGUI() } func runCLI(cfg Config, args []string) { if len(args) < 1 { fmt.Println("Usage: former [options] [outline_file]") fmt.Println(" former (no args = launch GUI)") flag.PrintDefaults() os.Exit(1) } gerberPath := args[0] var outlinePath string if len(args) > 1 { outlinePath = args[1] } _, _, _, err := processPCB(gerberPath, outlinePath, cfg, []string{"stl"}) if err != nil { log.Fatalf("Error: %v", err) } fmt.Println("Success! Happy printing.") } func runGUI() { imageServer := NewImageServer() app := NewApp(imageServer) err := wails.Run(&options.App{ Title: "Former", Width: 960, Height: 720, MinWidth: 640, MinHeight: 480, AssetServer: &assetserver.Options{ Assets: assets, Handler: imageServer, }, OnStartup: app.startup, OnBeforeClose: func(ctx context.Context) (prevent bool) { // Force-exit after brief grace period to prevent ghost PIDs on macOS go func() { time.Sleep(500 * time.Millisecond) os.Exit(0) }() return false }, Bind: []interface{}{ app, }, Mac: &mac.Options{ TitleBar: mac.TitleBarHiddenInset(), About: &mac.AboutInfo{ Title: "Former", Message: "PCB Stencil & Enclosure Generator", }, WebviewIsTransparent: true, WindowIsTranslucent: false, }, }) if err != nil { log.Fatal(err) } }