Skip to content

Commit

Permalink
fix: Store per-folder settings in YAML (#71)
Browse files Browse the repository at this point in the history
This should make it easier to edit settings manually.
  • Loading branch information
jbmorley authored Feb 26, 2024
1 parent d90a9fc commit 7b46f0e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
21 changes: 21 additions & 0 deletions Folders.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
D8DDBCC62B2A1317003EAF4E /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DDBCC52B2A1317003EAF4E /* FileManager.swift */; };
D8DDBCC82B2A1582003EAF4E /* DirectoryScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DDBCC72B2A1582003EAF4E /* DirectoryScanner.swift */; };
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 */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -114,6 +116,7 @@
D8DDBCC72B2A1582003EAF4E /* DirectoryScanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryScanner.swift; sourceTree = "<group>"; };
D8ED594E2B687FE800010FB3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
D8F349B42B8150690037D66A /* UTType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UTType.swift; sourceTree = "<group>"; };
D8F6A60A2B8D41F90003B1A6 /* yams-license */ = {isa = PBXFileReference; lastKnownFileType = text; path = "yams-license"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -125,6 +128,7 @@
D82B95842B23DC2B00C8B6FB /* FSEventsWrapper in Frameworks */,
D870ECAA2B7EDE0700704688 /* Interact in Frameworks */,
D870ECA42B7EDD8A00704688 /* Diligence in Frameworks */,
D8F6A6092B8D3D7E0003B1A6 /* Yams in Frameworks */,
D82B957F2B231A7900C8B6FB /* SQLite in Frameworks */,
D89622D92ACD1ECD006F7D2E /* OrderedCollections in Frameworks */,
);
Expand Down Expand Up @@ -168,6 +172,7 @@
D8D499C42B897C9200946CE9 /* swift-collections-license */,
D8D499C22B897B8E00946CE9 /* swift-numerics-license */,
D8D499CA2B897F4200946CE9 /* fs-events-wrapper-license */,
D8F6A60A2B8D41F90003B1A6 /* yams-license */,
);
path = Licenses;
sourceTree = "<group>";
Expand Down Expand Up @@ -299,6 +304,7 @@
D870ECA02B7ED5D700704688 /* Algorithms */,
D870ECA32B7EDD8A00704688 /* Diligence */,
D870ECA92B7EDE0700704688 /* Interact */,
D8F6A6082B8D3D7E0003B1A6 /* Yams */,
);
productName = Folders;
productReference = D87653B02AC9F01600E8B65D /* Folders.app */;
Expand Down Expand Up @@ -379,6 +385,7 @@
D870EC9F2B7ED5D700704688 /* XCRemoteSwiftPackageReference "swift-algorithms" */,
D870ECA22B7EDD8A00704688 /* XCLocalSwiftPackageReference "diligence" */,
D870ECA82B7EDE0700704688 /* XCLocalSwiftPackageReference "interact" */,
D8F6A6072B8D3D7E0003B1A6 /* XCRemoteSwiftPackageReference "Yams" */,
);
productRefGroup = D87653B12AC9F01600E8B65D /* Products */;
projectDirPath = "";
Expand All @@ -401,6 +408,7 @@
D8D499CB2B897F4200946CE9 /* fs-events-wrapper-license in Resources */,
D8D499C52B897C9200946CE9 /* swift-collections-license in Resources */,
D8D499C92B897E9E00946CE9 /* sqlite-swift-license in Resources */,
D8F6A60B2B8D41F90003B1A6 /* yams-license in Resources */,
D87653BB2AC9F01800E8B65D /* Preview Assets.xcassets in Resources */,
D870ECA72B7EDDD100704688 /* folders-license in Resources */,
D87653B82AC9F01800E8B65D /* Assets.xcassets in Resources */,
Expand Down Expand Up @@ -836,6 +844,14 @@
minimumVersion = 1.0.5;
};
};
D8F6A6072B8D3D7E0003B1A6 /* XCRemoteSwiftPackageReference "Yams" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/jpsim/Yams.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.6;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -867,6 +883,11 @@
package = D89622D72ACD1ECD006F7D2E /* XCRemoteSwiftPackageReference "swift-collections" */;
productName = OrderedCollections;
};
D8F6A6082B8D3D7E0003B1A6 /* Yams */ = {
isa = XCSwiftPackageProductDependency;
package = D8F6A6072B8D3D7E0003B1A6 /* XCRemoteSwiftPackageReference "Yams" */;
productName = Yams;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = D87653A82AC9F01600E8B65D /* Project object */;
Expand Down
7 changes: 5 additions & 2 deletions Folders/FoldersApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ struct FoldersApp: App {
let subject = "Folders Support (\(Bundle.main.version ?? "Unknown Version"))"

About(repository: "inseven/folders", copyright: "Copyright © 2023-2024 Jason Morley") {
Diligence.Action("GitHub", url: URL(string: "https://github.com/inseven/folders")!)
Diligence.Action("Support", url: URL(address: "[email protected]", subject: subject)!)
Action("GitHub", url: URL(string: "https://github.com/inseven/folders")!)
Action("Support", url: URL(address: "[email protected]", subject: subject)!)
} acknowledgements: {
Acknowledgements("Developers") {
Credit("Jason Morley", url: URL(string: "https://jbmorley.co.uk"))
Expand Down Expand Up @@ -76,6 +76,9 @@ struct FoldersApp: App {
License("Swift Numerics",
author: "Apple Inc. and the Swift Numerics Project Authors",
filename: "swift-numerics-license")
License("Yams",
author: "JP Simard",
filename: "yams-license")
}

}
Expand Down
21 changes: 21 additions & 0 deletions Folders/Licenses/yams-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 JP Simard.

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.
13 changes: 10 additions & 3 deletions Folders/Models/FolderModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@

import SwiftUI

import Yams

struct FolderSettings: Codable {

let url: URL
struct Link: Codable {
let url: URL
let title: String?
}

let links: [Link]

}

Expand All @@ -39,13 +46,13 @@ class FolderModel: ObservableObject {
}

func start() {
let settingsURL = url.appendingPathComponent("folders-settings.json") // TODO: Could I get macOS to hide these for me?
let settingsURL = url.appendingPathComponent("folders-settings.yaml") // TODO: Could I get macOS to hide these for me?
guard FileManager.default.fileExists(atPath: settingsURL.path) else {
return
}
do {
let data = try Data(contentsOf: settingsURL)
let decoder = JSONDecoder()
let decoder = YAMLDecoder()
let settings = try decoder.decode(FolderSettings.self, from: data)
self.settings = settings
} catch {
Expand Down
21 changes: 15 additions & 6 deletions Folders/Views/FolderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ struct FolderView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
GridView(sceneModel: sceneModel, store: applicationModel.store, ownerURL: ownerURL, directoryURL: url)
if let url = folderModel.settings?.url {
if let links = folderModel.settings?.links {
Divider()
HStack {
Button {
openURL(url)
} label: {
Text(url.absoluteString)
ForEach(links, id: \.title) { link in
Button {
openURL(link.url)
} label: {
Text(link.title ?? link.url.absoluteString)
}
.buttonStyle(.link)
.onHover { hover in
if hover {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}
}
.buttonStyle(.link)
}
.padding(8)
.background(.thinMaterial)
Expand Down

0 comments on commit 7b46f0e

Please sign in to comment.