1package main23import (4 "context"5 "sync/atomic"67 wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime"8)910// The Wails context exists only between startup and shutdown, and native11// dialogs can only be asked for through it. It is captured at startup and12// read wherever a request handler needs to put a window in front of the13// user; a request that arrives before there is a window is refused rather14// than queued.15var wailsContext atomic.Value1617func captureWailsContext(ctx context.Context) {18 wailsContext.Store(ctx)19}2021// pickBundleFiles opens the native file dialog filtered to .atlas files and22// returns the chosen paths, or nothing if there is no window yet.23func pickBundleFiles() ([]string, bool) {24 ctx, ok := wailsContext.Load().(context.Context)25 if !ok {26 return nil, false27 }28 paths, err := wailsruntime.OpenMultipleFilesDialog(ctx, wailsruntime.OpenDialogOptions{29 Title: "Add game bundles",30 Filters: []wailsruntime.FileFilter{31 {DisplayName: "Atlas bundles (*.atlas)", Pattern: "*.atlas"},32 },33 })34 if err != nil {35 wailsruntime.LogErrorf(ctx, "atlas: open dialog: %v", err)36 return nil, true37 }38 return paths, true39}