|
|
@@ -158,27 +158,25 @@ struct AppTileView: View {
|
|
|
}
|
|
|
|
|
|
private func addToDesktop() {
|
|
|
- guard let url = app.webURL else {
|
|
|
- showAlert(title: "Unavailable", message: "This tile doesn’t have a web link to create a desktop shortcut.")
|
|
|
+ let widgetVariants = WidgetTemplates.variants(for: app)
|
|
|
+ guard let variant = widgetVariants.first else {
|
|
|
+ showAlert(title: "Unavailable", message: "No desktop widget is available for this app.")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- guard let desktopURL = FileManager.default.urls(for: .desktopDirectory, in: .userDomainMask).first else {
|
|
|
- showAlert(title: "Error", message: "Couldn’t find your Desktop folder.")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let fileName = sanitizedFileName(app.name).isEmpty ? "Shortcut" : sanitizedFileName(app.name)
|
|
|
- let targetURL = desktopURL.appendingPathComponent("\(fileName).webloc")
|
|
|
+ var updated = decodeUUIDSet(from: widgetAppIDsData)
|
|
|
+ updated.insert(app.id)
|
|
|
+ widgetAppIDsData = encodeUUIDSet(updated)
|
|
|
|
|
|
- let payload: [String: Any] = ["URL": url.absoluteString]
|
|
|
- do {
|
|
|
- let data = try PropertyListSerialization.data(fromPropertyList: payload, format: .xml, options: 0)
|
|
|
- try data.write(to: targetURL, options: .atomic)
|
|
|
- showAlert(title: "Created", message: "Desktop shortcut created: \(targetURL.lastPathComponent)")
|
|
|
- } catch {
|
|
|
- showAlert(title: "Error", message: "Couldn’t create the desktop shortcut.")
|
|
|
- }
|
|
|
+ let instance = WidgetInstance(
|
|
|
+ appID: app.id,
|
|
|
+ variantID: variant.id,
|
|
|
+ size: variant.size,
|
|
|
+ origin: nil
|
|
|
+ )
|
|
|
+ DesktopWidgetWindowManager.shared.show(instance: instance, appProvider: { id in
|
|
|
+ id == app.id ? app : nil
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
private func decodeUUIDSet(from dataString: String) -> Set<UUID> {
|
|
|
@@ -201,13 +199,6 @@ struct AppTileView: View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func sanitizedFileName(_ input: String) -> String {
|
|
|
- let invalid = CharacterSet(charactersIn: "/:\\?%*|\"<>")
|
|
|
- let cleaned = input.components(separatedBy: invalid).joined(separator: " ")
|
|
|
- return cleaned.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
- .replacingOccurrences(of: " +", with: " ", options: .regularExpression)
|
|
|
- }
|
|
|
-
|
|
|
private func showAlert(title: String, message: String) {
|
|
|
let alert = NSAlert()
|
|
|
alert.messageText = title
|