mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 03:29:03 +08:00
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"github.com/wailsapp/wails/v3/internal/term"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
//go:embed webview2/MicrosoftEdgeWebview2Setup.exe
|
|
var webview2Bootstrapper []byte
|
|
|
|
type GenerateWebView2Options struct {
|
|
Directory string `name:"dir" json:"directory"`
|
|
}
|
|
|
|
func GenerateWebView2Bootstrapper(options *GenerateWebView2Options) error {
|
|
println("options.Directory", options.Directory)
|
|
options.Directory = filepath.Clean(options.Directory)
|
|
println("cleaned options.Directory", options.Directory)
|
|
|
|
// If the file already exists, exit early
|
|
if _, err := os.Stat(filepath.Join(options.Directory, "MicrosoftEdgeWebview2Setup.exe")); err == nil {
|
|
return nil
|
|
}
|
|
|
|
// Create target directory if it doesn't exist
|
|
err := os.MkdirAll(options.Directory, 0755)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create target directory: %w", err)
|
|
}
|
|
|
|
// Write to target directory
|
|
targetPath := filepath.Join(options.Directory, "MicrosoftEdgeWebview2Setup.exe")
|
|
err = os.WriteFile(targetPath, webview2Bootstrapper, 0644)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to write WebView2 bootstrapper: %w", err)
|
|
}
|
|
|
|
term.Success("Generated WebView2 bootstrapper at: " + targetPath + "\n")
|
|
return nil
|
|
}
|