diff --git a/TrackerZapper.xcodeproj/project.pbxproj b/TrackerZapper.xcodeproj/project.pbxproj index d87e63f..7ce28c3 100644 --- a/TrackerZapper.xcodeproj/project.pbxproj +++ b/TrackerZapper.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 543DAE4F26DFDE66000B6705 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 543DAE4E26DFDE66000B6705 /* Assets.xcassets */; }; 543DAE5226DFDE66000B6705 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 543DAE5126DFDE66000B6705 /* Preview Assets.xcassets */; }; 543DAE5526DFDE66000B6705 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 543DAE5326DFDE66000B6705 /* Main.storyboard */; }; + 545CD0EF26EE518800589ADE /* DropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545CD0EE26EE518800589ADE /* DropDelegate.swift */; }; 54C728D326E3B2AD002D63E0 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 54C728D226E3B2AD002D63E0 /* Credits.rtf */; }; /* End PBXBuildFile section */ @@ -29,6 +30,7 @@ 543DAE5426DFDE66000B6705 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 543DAE5626DFDE66000B6705 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 543DAE5726DFDE66000B6705 /* TrackerZapper.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TrackerZapper.entitlements; sourceTree = ""; }; + 545CD0EE26EE518800589ADE /* DropDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDelegate.swift; sourceTree = ""; }; 54C728D226E3B2AD002D63E0 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; /* End PBXFileReference section */ @@ -67,6 +69,7 @@ children = ( 543DAE4A26DFDE65000B6705 /* AppDelegate.swift */, 540DD58A26ED3F91001CAA6B /* GeneralPreferencesView.swift */, + 545CD0EE26EE518800589ADE /* DropDelegate.swift */, 54C728D226E3B2AD002D63E0 /* Credits.rtf */, 543DAE4E26DFDE66000B6705 /* Assets.xcassets */, 543DAE5326DFDE66000B6705 /* Main.storyboard */, @@ -189,6 +192,7 @@ buildActionMask = 2147483647; files = ( 540DD58B26ED3F91001CAA6B /* GeneralPreferencesView.swift in Sources */, + 545CD0EF26EE518800589ADE /* DropDelegate.swift in Sources */, 543DAE4B26DFDE65000B6705 /* AppDelegate.swift in Sources */, 540DD58926ED3CF6001CAA6B /* Constants.swift in Sources */, ); diff --git a/TrackerZapper.xcodeproj/project.xcworkspace/xcuserdata/robb.xcuserdatad/UserInterfaceState.xcuserstate b/TrackerZapper.xcodeproj/project.xcworkspace/xcuserdata/robb.xcuserdatad/UserInterfaceState.xcuserstate index def12c7..8391d0a 100644 Binary files a/TrackerZapper.xcodeproj/project.xcworkspace/xcuserdata/robb.xcuserdatad/UserInterfaceState.xcuserstate and b/TrackerZapper.xcodeproj/project.xcworkspace/xcuserdata/robb.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TrackerZapper/DropDelegate.swift b/TrackerZapper/DropDelegate.swift new file mode 100644 index 0000000..598daf0 --- /dev/null +++ b/TrackerZapper/DropDelegate.swift @@ -0,0 +1,51 @@ +// +// DropDelegate.swift +// TrackerZapper +// +// Created by Robb Knight on 12/09/2021. +// + +import Foundation +import SwiftUI + +struct AppDropDelegate: DropDelegate +{ + + func validateDrop(info: DropInfo) -> Bool + { + return true + } + + func dropEntered(info: DropInfo) + { + print ("Drop Entered") + } + + func performDrop(info: DropInfo) -> Bool + { + print ("performDrop") + NSSound(named: "Submarine")?.play() + + print (info) + print ("Has UniformTypeIdentifiers:", info.hasItemsConforming(to: uttypes)) + + let items = info.itemProviders(for: uttypes) + print ("Number of items:",items.count) + print (items) + + for item in items + { + item.loadItem(forTypeIdentifier: (kUTTypeFileURL as String), options: nil) {item, error in + guard let data = item as? Data, let url = URL(dataRepresentation: data, relativeTo: nil) else { return } + print(url) + if !url.absoluteString.contains(".app") { + return + } + print(NSWorkspace.shared.frontmostApplication?.bundleURL) + // have bundle URL, how do I get the app bundle ID based on this so + // I can then match on NSWorkspace.shared.frontmostApplication?.bundleURL + } + } + return true + } +} diff --git a/TrackerZapper/GeneralPreferencesView.swift b/TrackerZapper/GeneralPreferencesView.swift index e766d90..ad85ccf 100644 --- a/TrackerZapper/GeneralPreferencesView.swift +++ b/TrackerZapper/GeneralPreferencesView.swift @@ -10,8 +10,11 @@ import Preferences import KeyboardShortcuts import LaunchAtLogin +let uttypes = [String(kUTTypeFileURL)] + struct GeneralPreferencesView: View { private let contentWidth: Double = 300.0 + let dropDelegate = AppDropDelegate() var body: some View { Preferences.Container(contentWidth: contentWidth) { @@ -20,6 +23,9 @@ struct GeneralPreferencesView: View { KeyboardShortcuts.Recorder(for: .toggleZapping) } LaunchAtLogin.Toggle() + Text("HELLO") + .padding(20) + .onDrop(of: uttypes, delegate: dropDelegate as! DropDelegate) } } }