Skip to content

Commit

Permalink
Remove folders is working, update readme, bump version, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiuspernat committed Dec 8, 2022
1 parent 40bf547 commit d544475
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ A macOS Finder right-click menu extension that displays diffusion metadata (usua
# TODO
- Refresh folder in the app when added folders via Finder toolbar item
- Don't display errors on the menu
- Add option to remove folders
- Support more PNG data formats
- Drop python requirement
12 changes: 6 additions & 6 deletions UnderPillow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
INFOPLIST_FILE = UnderPillowXPC/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = UnderPillowXPC;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillowXPC";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -427,7 +427,7 @@
INFOPLIST_FILE = UnderPillowXPC/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = UnderPillowXPC;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillowXPC";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -577,7 +577,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillow";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -609,7 +609,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillow";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -637,7 +637,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillow.UnderPillow-Finder";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -666,7 +666,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MARKETING_VERSION = 0.5;
MARKETING_VERSION = 0.6;
PRODUCT_BUNDLE_IDENTIFIER = "Crispy-Driven-Pixels.UnderPillow.UnderPillow-Finder";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
51 changes: 30 additions & 21 deletions UnderPillow/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ struct names {

@MainActor public class ListViewModel: ObservableObject {
@Published var items: [String] = []
@State var selectKeeper = Set<String>()
}

struct ContentView: View {
@State var selectKeeper = Set<String>()
@State var removeButtonDisabled = false
@ObservedObject var viewModel = ListViewModel()

var body: some View {
HStack {
VStack(alignment: .leading) {
List(viewModel.items, id: \.self, selection: $viewModel.selectKeeper){ name in
List(viewModel.items, id: \.self, selection: $selectKeeper){ name in
Text(name)
}
.onAppear{
Expand Down Expand Up @@ -63,12 +63,15 @@ struct ContentView: View {
.frame(maxWidth: .infinity)
.padding(.bottom, 5)
Button(action: {
viewModel.selectKeeper.forEach { item in

selectKeeper.forEach { item in
viewModel.items.removeAll(where: { $0 == item })
}
setFoldersFromList()

}, label: {
Text("Remove")
})
}) // Button
.disabled(removeButtonDisabled)
} // VStack
.padding(.bottom, 10)
Expand Down Expand Up @@ -96,24 +99,8 @@ struct ContentView: View {
if (viewModel.items.firstIndex(where: {$0 == newPath}) == nil) {

viewModel.items.append(newPath!)

let service = UnderPillowXPC.getService()

let foldersStringsDict: NSMutableDictionary = [UnderPillowXPC.keyFolderSettings:viewModel.items]

if let theJSONData = try? JSONSerialization.data(
withJSONObject: foldersStringsDict,
options: []) {

let theJSONText = String(data: theJSONData,
encoding: .utf8)

service.setFolders( theJSONText! ) { response in
print("Response from XPC service(2):", response)
}

DistributedNotificationCenter.default().postNotificationName(NSNotification.Name(UnderPillowXPC.NotificationFoldersChanged), object: theJSONText, userInfo: nil, options: [.deliverImmediately])
}
setFoldersFromList()
}
} else {
// User clicked on "Cancel"
Expand All @@ -139,6 +126,28 @@ struct ContentView: View {
}
}
}

func setFoldersFromList() {

let service = UnderPillowXPC.getService()

let foldersStringsDict: NSMutableDictionary = [UnderPillowXPC.keyFolderSettings:viewModel.items]

if let theJSONData = try? JSONSerialization.data(
withJSONObject: foldersStringsDict,
options: []) {

let theJSONText = String(data: theJSONData,
encoding: .utf8)

service.setFolders( theJSONText! ) { response in
print("Response from XPC service(2):", response)
}

DistributedNotificationCenter.default().postNotificationName(NSNotification.Name(UnderPillowXPC.NotificationFoldersChanged), object: theJSONText, userInfo: nil, options: [.deliverImmediately])
}
}

}


Expand Down

0 comments on commit d544475

Please sign in to comment.