Skip to content

Commit f12397d

Browse files
choose icon from local
1 parent 203f630 commit f12397d

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

IconChanger/ChangeView.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ struct ChangeView: View {
5858
Text("Local")
5959
}
6060
}
61+
.fileImporter(isPresented: $importImage, allowedContentTypes: [.image, .icns]) { result in
62+
switch result {
63+
case .success(let url):
64+
if url.startAccessingSecurityScopedResource() {
65+
if let nsimage = NSImage(contentsOf: url) {
66+
do {
67+
try IconManager.shared.setImage(nsimage, app: setPath)
68+
} catch {
69+
fatalError(error.localizedDescription)
70+
}
71+
}
72+
url.stopAccessingSecurityScopedResource()
73+
}
74+
case .failure(let error):
75+
print(error)
76+
}
77+
}
6178
.padding()
6279
.toolbar {
6380
ToolbarItem(placement: .cancellationAction) {
@@ -79,7 +96,6 @@ struct ChangeView: View {
7996
.task {
8097
do {
8198
icons = try await iconManager.getIcons(setPath)
82-
print(icons)
8399
} catch {
84100
print(error)
85101
}

IconChanger/IconManager.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ class IconManager: ObservableObject {
165165
let urlName = AliasName.getNames(for: app.url.deletingPathExtension().lastPathComponent) ?? app.url.deletingPathExtension().lastPathComponent
166166
let bundleName = try getAppBundleName(app)
167167

168-
print(appName, urlName, bundleName)
169-
170168
var urls = [URL]()
171169

172170
urls.append(contentsOf: try await MyQueryRequestController().sendRequest(appName))
@@ -175,8 +173,6 @@ class IconManager: ObservableObject {
175173
urls.append(contentsOf: try await MyQueryRequestController().sendRequest(bundleName))
176174
}
177175

178-
print(urls)
179-
180176
return Set(urls).map { $0 }
181177
}
182178

IconChanger/Request.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ class MyQueryRequestController {
103103
let json = try JSON(data: data)
104104
let hits = json["hits"].arrayValue
105105

106-
print(json)
107-
108106
return hits.map { json in
109107
(Foundation.URL(string: json["icnsUrl"].stringValue), json["downloads"].intValue)
110108
}.sorted { hit1, hit2 in

0 commit comments

Comments
 (0)