()
| 900 | } |
| 901 | |
| 902 | func MigratePresetsBackgrounds() { |
| 903 | configDirAbsPath := wavebase.GetWaveConfigDir() |
| 904 | backgroundsFile := filepath.Join(configDirAbsPath, "backgrounds.json") |
| 905 | if _, err := os.Stat(backgroundsFile); err == nil { |
| 906 | return |
| 907 | } else if !os.IsNotExist(err) { |
| 908 | log.Printf("error checking backgrounds.json during migration: %v\n", err) |
| 909 | return |
| 910 | } |
| 911 | bgFile := filepath.Join(configDirAbsPath, "presets", "bg.json") |
| 912 | bgData, err := os.ReadFile(bgFile) |
| 913 | if err != nil { |
| 914 | if !os.IsNotExist(err) { |
| 915 | log.Printf("error reading presets/bg.json for migration: %v\n", err) |
| 916 | } |
| 917 | return |
| 918 | } |
| 919 | var rawMap map[string]json.RawMessage |
| 920 | if err := json.Unmarshal(bgData, &rawMap); err != nil { |
| 921 | log.Printf("error parsing presets/bg.json for migration: %v\n", err) |
| 922 | return |
| 923 | } |
| 924 | filtered := make(map[string]json.RawMessage) |
| 925 | for k, v := range rawMap { |
| 926 | if strings.HasPrefix(k, "bg@") { |
| 927 | filtered[k] = v |
| 928 | } |
| 929 | } |
| 930 | if len(filtered) == 0 { |
| 931 | return |
| 932 | } |
| 933 | outBarr, err := json.MarshalIndent(filtered, "", " ") |
| 934 | if err != nil { |
| 935 | log.Printf("error marshaling backgrounds.json during migration: %v\n", err) |
| 936 | return |
| 937 | } |
| 938 | if err := fileutil.AtomicWriteFile(backgroundsFile, outBarr, 0644); err != nil { |
| 939 | log.Printf("error writing backgrounds.json during migration: %v\n", err) |
| 940 | return |
| 941 | } |
| 942 | log.Printf("migrated %d background presets from presets/bg.json to backgrounds.json\n", len(filtered)) |
| 943 | } |
| 944 | |
| 945 | // CountCustomWidgets returns the number of custom widgets the user has defined. |
| 946 | // Custom widgets are identified as widgets whose ID doesn't start with "defwidget@". |
no test coverage detected