Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TrackerZapper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -29,6 +30,7 @@
543DAE5426DFDE66000B6705 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
543DAE5626DFDE66000B6705 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
543DAE5726DFDE66000B6705 /* TrackerZapper.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TrackerZapper.entitlements; sourceTree = "<group>"; };
545CD0EE26EE518800589ADE /* DropDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDelegate.swift; sourceTree = "<group>"; };
54C728D226E3B2AD002D63E0 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -67,6 +69,7 @@
children = (
543DAE4A26DFDE65000B6705 /* AppDelegate.swift */,
540DD58A26ED3F91001CAA6B /* GeneralPreferencesView.swift */,
545CD0EE26EE518800589ADE /* DropDelegate.swift */,
54C728D226E3B2AD002D63E0 /* Credits.rtf */,
543DAE4E26DFDE66000B6705 /* Assets.xcassets */,
543DAE5326DFDE66000B6705 /* Main.storyboard */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
Binary file not shown.
51 changes: 51 additions & 0 deletions TrackerZapper/DropDelegate.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions TrackerZapper/GeneralPreferencesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -20,6 +23,9 @@ struct GeneralPreferencesView: View {
KeyboardShortcuts.Recorder(for: .toggleZapping)
}
LaunchAtLogin.Toggle()
Text("HELLO")
.padding(20)
.onDrop(of: uttypes, delegate: dropDelegate as! DropDelegate)
}
}
}
Expand Down