Skip to content

Commit

Permalink
Fix: Now Wallpaper Explorer Won't Go Blank When Parsing Invalid Wallp…
Browse files Browse the repository at this point in the history
…apers

This bug is annoying, which even cause your normal wallpapers disappear.
  • Loading branch information
haren724 committed Aug 24, 2023
1 parent 4743e36 commit 6ee5a7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Open Wallpaper Engine/Services/WEProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ struct WEProject: Codable, Equatable, Hashable {
var workshopid: String?
var type: String?
var version: Int?

static let invalid = Self(file: "",
general: WEProjectGeneral(properties: WEProjectProperties()),
preview: "",
tags: [],
title: "Error")
}

struct WEWallpaper: Identifiable {
Expand Down
16 changes: 7 additions & 9 deletions Open Wallpaper Engine/Services/WallpaperViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ class WallpaperViewModel: ObservableObject {

/// Show all the wallpaper inside application wallpaper directory, without being filtered
private var allWallpapers: [WEWallpaper] {
if let wallpapers = try? self.urls.map({ url in
let project = try JSONDecoder().decode(WEProject.self, from: try Data(contentsOf: url.appending(path: "project.json")))
return WEWallpaper(using: project, where: url)
}) {
return wallpapers
}
else {
return []
}
self.urls.map({ url in
if let data = try? Data(contentsOf: url.appending(path: "project.json")), let project = try? JSONDecoder().decode(WEProject.self, from: data) {
return WEWallpaper(using: project, where: url)
} else {
return WEWallpaper(using: .invalid, where: url)
}
})
}

private var filteredWallpapers: [WEWallpaper] {
Expand Down

0 comments on commit 6ee5a7a

Please sign in to comment.