43 lines
1011 B
Go
43 lines
1011 B
Go
package main
|
|
|
|
import (
|
|
"MacFastLookup/service"
|
|
"context"
|
|
"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.DownloadFile("https://tools.taurusxin.com/macfastlookup/mac_vendors.sqlite3", dbFilePath, true, func(progress, total int64) {
|
|
runtime.EventsEmit(a.ctx, "download-progress", float32(progress / total))
|
|
})
|
|
} |