package main import ( "MacFastLookup/service" "context" "fmt" "os" "path/filepath" "github.com/wailsapp/wails/v2/pkg/runtime" ) // App struct type App struct { ctx context.Context } // NewApp creates a new App application struct func NewApp() *App { return &App{} } // startup is called when the app starts. The context is saved // so we can call the runtime methods func (a *App) startup(ctx context.Context) { a.ctx = ctx } func (a *App) StartDownload() { dbFileDir := ".macfastlookup" userHomeDir, _ := os.UserHomeDir() dbFileName := "mac_vendors.sqlite3" dbFilePath := filepath.Join(userHomeDir, dbFileDir, dbFileName) // create the folder if not exist path := filepath.Join(userHomeDir, dbFileDir) if _, err := os.Stat(path); os.IsNotExist(err) { os.Mkdir(path, 0755) } service.EnhancedDownload("https://tools.taurusxin.com/macfastlookup/mac_vendors.sqlite3", dbFilePath, true, func(downloaded, total, rate int64, packageName string) { fmt.Printf("\rDownloading[%s][ %d%% ][%d/%d]", packageName, rate, downloaded, total) runtime.EventsEmit(a.ctx, "download-progress", rate) }) }