Skip to content

Commit

Permalink
Merge branch 'dev_1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
boberito committed Dec 4, 2024
2 parents a25ef4d + 81e9546 commit 5b03e09
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 13 deletions.
12 changes: 8 additions & 4 deletions Air Drop Assistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
736C80F92C70302200E5E780 /* PrefWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736C80F82C70302200E5E780 /* PrefWatcher.swift */; };
736C80FE2C70EC6800E5E780 /* PreferencesWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736C80FD2C70EC6800E5E780 /* PreferencesWindow.swift */; };
736C81002C70EC9E00E5E780 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736C80FF2C70EC9E00E5E780 /* PreferencesViewController.swift */; };
73B614B92CF77F5500C3A14F /* PreferenceObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73B614B82CF77F5500C3A14F /* PreferenceObserver.swift */; };
73FFDCFB2C70210B00244D57 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73FFDCFA2C70210B00244D57 /* AppDelegate.swift */; };
73FFDCFD2C70210B00244D57 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73FFDCFC2C70210B00244D57 /* ViewController.swift */; };
73FFDCFF2C70210C00244D57 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 73FFDCFE2C70210C00244D57 /* Assets.xcassets */; };
Expand Down Expand Up @@ -51,6 +52,7 @@
736C80FD2C70EC6800E5E780 /* PreferencesWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindow.swift; sourceTree = "<group>"; };
736C80FF2C70EC9E00E5E780 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
737B8A342C8BE5D1006A4653 /* Air-Drop-Assistant-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Air-Drop-Assistant-Info.plist"; sourceTree = SOURCE_ROOT; };
73B614B82CF77F5500C3A14F /* PreferenceObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceObserver.swift; sourceTree = "<group>"; };
73FFDCF72C70210B00244D57 /* Air Drop Assistant.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Air Drop Assistant.app"; sourceTree = BUILT_PRODUCTS_DIR; };
73FFDCFA2C70210B00244D57 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
73FFDCFC2C70210B00244D57 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,6 +96,7 @@
736C80FD2C70EC6800E5E780 /* PreferencesWindow.swift */,
73FFDCFA2C70210B00244D57 /* AppDelegate.swift */,
736C80F82C70302200E5E780 /* PrefWatcher.swift */,
73B614B82CF77F5500C3A14F /* PreferenceObserver.swift */,
736C80FF2C70EC9E00E5E780 /* PreferencesViewController.swift */,
7328CDA42C8BA87B0042A517 /* com.ttinc.Air-Drop-Assistant.plist */,
73FFDCFC2C70210B00244D57 /* ViewController.swift */,
Expand Down Expand Up @@ -179,6 +182,7 @@
buildActionMask = 2147483647;
files = (
736C81002C70EC9E00E5E780 /* PreferencesViewController.swift in Sources */,
73B614B92CF77F5500C3A14F /* PreferenceObserver.swift in Sources */,
736C80FE2C70EC6800E5E780 /* PreferencesWindow.swift in Sources */,
73FFDCFD2C70210B00244D57 /* ViewController.swift in Sources */,
73FFDCFB2C70210B00244D57 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -330,7 +334,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 311;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = 2WUMX954UB;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -345,7 +349,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.ttinc.Air-Drop-Assistant";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -365,7 +369,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 311;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = 2WUMX954UB;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -380,7 +384,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.ttinc.Air-Drop-Assistant";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
56 changes: 49 additions & 7 deletions Air Drop Assistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,49 @@ import ServiceManagement
@NSApplicationMain


class AppDelegate: NSObject, NSApplicationDelegate, DataModelDelegate, PrefDataModelDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, DataModelDelegate, PrefDataModelDelegate, AppPrefObserverDelegate {
func newPreferenceValue() {
menuIcon()

guard let appBundleID = Bundle.main.bundleIdentifier else { return }
let hideMenuIconValue = UserDefaults.standard.bool(forKey: "hideMenuIcon")
let isForced = CFPreferencesAppValueIsForced("hideMenuIcon" as CFString, appBundleID as CFString)

if hideMenuIconValue && isForced {
adaMenu.menu?.removeAllItems()
NSStatusBar.system.removeStatusItem(adaMenu)
} else {
guard adaMenu.menu != nil else { return }
adaMenu = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

adaMenu.menu = NSMenu()

menuIcon()

adaMenuListing()
let prefs = NSMenuItem(title: "Preferences", action: #selector(Preferences), keyEquivalent: "")
let softwareUpdate = NSMenuItem(title: "Check for Update", action: #selector(updateCheckFunc), keyEquivalent: "")

var IncreaseByOne: Int = 0
if let menuItems = adaMenu.menu {
for item in menuItems.items {

if item.title == "AirDrop: Incoming Only"{
IncreaseByOne += 1
}
if item.title == "AirDrop: Outgoing Only" {
IncreaseByOne += 1
}
}
}

adaMenu.menu?.insertItem(prefs, at: 1 + IncreaseByOne)
adaMenu.menu?.insertItem(softwareUpdate, at: 2 + IncreaseByOne)
let quit = NSMenuItem(title: "Quit", action: #selector(QuitApp), keyEquivalent: "")
adaMenu.menu?.insertItem(quit, at: 3 + IncreaseByOne)
}
}

func checkAirDrop() {
if domain!.string(forKey: "DiscoverableMode") == UserDefaults.standard.string(forKey: "airDropSetting") || domain!.string(forKey: "DiscoverableMode") == "Off" {
return
Expand Down Expand Up @@ -81,19 +123,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, DataModelDelegate, PrefDataM
}

let domain = UserDefaults(suiteName: "com.apple.sharingd")
let adaMenu = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
var adaMenu = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
var airDropStatus = ""
let prefWatcher = PrefWatcher()
let updater = UpdateCheck()
let prefViewController = PreferencesViewController()

let observer = AppPreferencesObserver()
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
// Ensure that the app doesn't show the menu bar or Dock icon when reopened
NSApp.setActivationPolicy(.accessory)
return false
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSLog("ADA Launched")

NSApp.setActivationPolicy(.accessory)
if isAppAlreadyRunning() {
NSApp.terminate(nil)
Expand All @@ -106,7 +148,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, DataModelDelegate, PrefDataM
}
let arguments = CommandLine.arguments
let stringarguments = String(describing: arguments)
NSLog(stringarguments)

if arguments[1] == "--register" {
do {
Expand Down Expand Up @@ -181,7 +222,7 @@ AirDrop is disabled by an MDM Profile. Please contact your MDM administrator.
UserDefaults.standard.set(15, forKey: "timing")
}
prefWatcher.delegate = self
prefViewController.delegate = self
observer.delegate = self

if domain?.string(forKey: "DiscoverableMode") != UserDefaults.standard.string(forKey: "airDropSetting") && domain?.string(forKey: "DiscoverableMode") != "Off" {
Task {
Expand Down Expand Up @@ -260,7 +301,6 @@ AirDrop is disabled by an MDM Profile. Please contact your MDM administrator.
func adaMenuListing(){

var PFADAStatus: String?
// let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
guard let bundleID = Bundle.main.bundleIdentifier else { return }
let path = "/Library/Preferences/\(bundleID).plist"

Expand Down Expand Up @@ -332,6 +372,8 @@ AirDrop is disabled by an MDM Profile. Please contact your MDM administrator.
return
}
}
let prefViewController = PreferencesViewController()
prefViewController.delegate = self
var window: PreferencesWindow?
let windowSize = NSSize(width: 415, height: 200)
let screenSize = NSScreen.main?.frame.size ?? .zero
Expand Down
45 changes: 45 additions & 0 deletions Air Drop Assistant/PreferenceObserver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// PreferenceObserver.swift
// Air Drop Assistant
//
// Created by Bob Gendler on 11/27/24.
//
import Combine
import Foundation



extension UserDefaults {
@objc dynamic var hideMenuIcon: String? {
return string(forKey: "hideMenuIcon")
}

@objc dynamic var icon_mode: String? {
return string(forKey: "icon_mode")
}
}

protocol AppPrefObserverDelegate {
func newPreferenceValue()
}

class AppPreferencesObserver {

var delegate: AppPrefObserverDelegate?
private var cancellables = Set<AnyCancellable>()

init() {
let hideMenuIconPref = UserDefaults.standard.publisher(for: \.hideMenuIcon)
let icon_modePref = UserDefaults.standard.publisher(for: \.icon_mode)

// Combine the two publishers
Publishers.CombineLatest(hideMenuIconPref, icon_modePref)
.sink { _, _ in
self.delegate?.newPreferenceValue()
}
.store(in: &cancellables)
}
}

// Usage

6 changes: 4 additions & 2 deletions Air Drop Assistant/com.ttinc.Air-Drop-Assistant.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.ttinc.Air-Drop-Assistant</string>
<key>RunAtLoad</key>
Expand All @@ -10,7 +12,7 @@
<string>Contents/MacOS/Air Drop Assistant</string>
<key>ProcessType</key>
<string>Interactive</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
</dict>
</plist>

0 comments on commit 5b03e09

Please sign in to comment.