diff --git a/Folders.xcodeproj/project.pbxproj b/Folders.xcodeproj/project.pbxproj index 4831930..595de01 100644 --- a/Folders.xcodeproj/project.pbxproj +++ b/Folders.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ D8F349B52B8150690037D66A /* UTType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F349B42B8150690037D66A /* UTType.swift */; }; D8F6A6092B8D3D7E0003B1A6 /* Yams in Frameworks */ = {isa = PBXBuildFile; productRef = D8F6A6082B8D3D7E0003B1A6 /* Yams */; }; D8F6A60B2B8D41F90003B1A6 /* yams-license in Resources */ = {isa = PBXBuildFile; fileRef = D8F6A60A2B8D41F90003B1A6 /* yams-license */; }; + D8F6A60D2B8D46720003B1A6 /* FolderSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F6A60C2B8D46720003B1A6 /* FolderSettings.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -117,6 +118,7 @@ D8ED594E2B687FE800010FB3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; D8F349B42B8150690037D66A /* UTType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UTType.swift; sourceTree = ""; }; D8F6A60A2B8D41F90003B1A6 /* yams-license */ = {isa = PBXFileReference; lastKnownFileType = text; path = "yams-license"; sourceTree = ""; }; + D8F6A60C2B8D46720003B1A6 /* FolderSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderSettings.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -273,6 +275,7 @@ D89622DA2ACD394A006F7D2E /* ApplicationModel.swift */, D83312E82B77132B00B994B3 /* Details.swift */, D870EC9D2B7EC47B00704688 /* FolderModel.swift */, + D8F6A60C2B8D46720003B1A6 /* FolderSettings.swift */, D8DDBCC32B2A0F8E003EAF4E /* PreviewItem.swift */, D89622E52ACD42F2006F7D2E /* SceneModel.swift */, D89622DD2ACD3B82006F7D2E /* Settings.swift */, @@ -452,6 +455,7 @@ D89622E22ACD4200006F7D2E /* Sidebar.swift in Sources */, D870EC9E2B7EC47B00704688 /* FolderModel.swift in Sources */, D8472A682B2518320070DB64 /* FixedItemSizeCollectionViewLayout.swift in Sources */, + D8F6A60D2B8D46720003B1A6 /* FolderSettings.swift in Sources */, D8472A6E2B2518D00070DB64 /* InteractiveCollectionView.swift in Sources */, D83312E92B77132B00B994B3 /* Details.swift in Sources */, D83312E32B76FE4E00B994B3 /* Filter.swift in Sources */, diff --git a/Folders/Models/FolderModel.swift b/Folders/Models/FolderModel.swift index 2254044..2e3dba9 100644 --- a/Folders/Models/FolderModel.swift +++ b/Folders/Models/FolderModel.swift @@ -22,41 +22,26 @@ import SwiftUI -import Yams - -struct FolderSettings: Codable { - - struct Link: Codable { - let url: URL - let title: String? - } - - let links: [Link] - -} - class FolderModel: ObservableObject { let url: URL @Published var settings: FolderSettings? + @Published var error: Error? init(url: URL) { self.url = url } func start() { - let settingsURL = url.appendingPathComponent("folders-settings.yaml") // TODO: Could I get macOS to hide these for me? + let settingsURL = url.appendingPathComponent("folders-settings.yaml") guard FileManager.default.fileExists(atPath: settingsURL.path) else { return } do { - let data = try Data(contentsOf: settingsURL) - let decoder = YAMLDecoder() - let settings = try decoder.decode(FolderSettings.self, from: data) - self.settings = settings + self.settings = try FolderSettings(contentsOf: settingsURL) } catch { - print("Failed to load folder settings with error \(error).") + self.error = error } } diff --git a/Folders/Models/FolderSettings.swift b/Folders/Models/FolderSettings.swift new file mode 100644 index 0000000..2ff21cb --- /dev/null +++ b/Folders/Models/FolderSettings.swift @@ -0,0 +1,42 @@ +// MIT License +// +// Copyright (c) 2023-2024 Jason Morley +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import SwiftUI + +import Yams + +struct FolderSettings: Codable { + + struct Link: Codable { + let url: URL + let title: String? + } + + let links: [Link] + + init(contentsOf url: URL) throws { + let data = try Data(contentsOf: url) + let decoder = YAMLDecoder() + self = try decoder.decode(FolderSettings.self, from: data) + } + +} diff --git a/Folders/Views/FolderView.swift b/Folders/Views/FolderView.swift index 7a53f31..21ac9c5 100644 --- a/Folders/Views/FolderView.swift +++ b/Folders/Views/FolderView.swift @@ -67,6 +67,7 @@ struct FolderView: View { } } .navigationTitle(url.displayName) + .presents($folderModel.error) .onAppear { folderModel.start() }