Skip to content

Commit

Permalink
Merge pull request #49 from mohamed-arradi/feature/add_custom_url_scheme
Browse files Browse the repository at this point in the history
v2.2.7: Sonoma Compatibility + Bug Fixes
  • Loading branch information
mohamed-arradi authored Oct 12, 2024
2 parents b54d02b + fa3560a commit bf9b486
Show file tree
Hide file tree
Showing 30 changed files with 321 additions and 76 deletions.
24 changes: 12 additions & 12 deletions AirpodsPro Battery/AirpodsPro Battery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -362,6 +362,7 @@
isa = PBXGroup;
children = (
EBC7AD3E2386769700A53E83 /* AppDelegate.swift */,
EBC7AD4E2386776000A53E83 /* String+Localized.swift */,
EBC7AD402386769700A53E83 /* StatusMenuController.swift */,
);
path = Controllers;
Expand All @@ -370,7 +371,6 @@
EBC7AD652387DF2300A53E83 /* Extensions */ = {
isa = PBXGroup;
children = (
EBC7AD4E2386776000A53E83 /* String+Localized.swift */,
EBFE03A523A36356006095DB /* Bundle+Versioning.swift */,
D904C6462747AB94009856C5 /* NSScreen+Extension.swift */,
D957E012274E6658007F940C /* System+Extension.swift */,
Expand Down Expand Up @@ -701,7 +701,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 2.2.6;
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery.batteryWidget";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -733,7 +733,7 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 2.2.6;
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery.batteryWidget";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -840,7 +840,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -898,7 +898,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "Airpods Battery Monitor";
Expand All @@ -918,7 +918,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 8JVK53ZY4C;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -928,8 +928,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.2.6;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 2.2.7;
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery";
PRODUCT_NAME = "Airpods Battery Monitor";
SWIFT_OBJC_BRIDGING_HEADER = "AirpodsPro Battery/External/TransparencyCore/AirpodsPro Battery-Bridging-Header.h";
Expand All @@ -948,7 +948,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 8JVK53ZY4C;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -958,8 +958,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.2.6;
MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 2.2.7;
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery";
PRODUCT_NAME = "Airpods Battery Monitor";
SWIFT_OBJC_BRIDGING_HEADER = "AirpodsPro Battery/External/TransparencyCore/AirpodsPro Battery-Bridging-Header.h";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"originHash" : "1ec685d27a84c49c67d8ed572df27602b3ff131cede7880b853cef2bde046d2a",
"pins" : [
{
"identity" : "loginservicekit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Clipy/LoginServiceKit",
"state" : {
"branch" : "master",
"revision" : "a8e68051aca8bbb702e62ab36006a301966ab053"
"revision" : "56dce9dbf4367c1445ef2343a2a912bbe5019a6c"
}
}
],
"version" : 2
"version" : 3
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
{
"images" : [
{
"size" : "16x16",
"filename" : "16.png",
"idiom" : "mac",
"filename" : "icon_16@1x.png",
"scale" : "1x"
"scale" : "1x",
"size" : "16x16"
},
{
"size" : "16x16",
"filename" : "32.png",
"idiom" : "mac",
"filename" : "icon_16@2x.png",
"scale" : "2x"
"scale" : "2x",
"size" : "16x16"
},
{
"size" : "32x32",
"filename" : "32.png",
"idiom" : "mac",
"filename" : "icon_32@1x.png",
"scale" : "1x"
"scale" : "1x",
"size" : "32x32"
},
{
"size" : "32x32",
"filename" : "64.png",
"idiom" : "mac",
"filename" : "icon_32@2x.png",
"scale" : "2x"
"scale" : "2x",
"size" : "32x32"
},
{
"size" : "128x128",
"filename" : "128.png",
"idiom" : "mac",
"filename" : "icon_128@1x.png",
"scale" : "1x"
"scale" : "1x",
"size" : "128x128"
},
{
"size" : "128x128",
"filename" : "256.png",
"idiom" : "mac",
"filename" : "icon_128@2x.png",
"scale" : "2x"
"scale" : "2x",
"size" : "128x128"
},
{
"size" : "256x256",
"filename" : "256.png",
"idiom" : "mac",
"filename" : "icon_256@1x.png",
"scale" : "1x"
"scale" : "1x",
"size" : "256x256"
},
{
"size" : "256x256",
"filename" : "512.png",
"idiom" : "mac",
"filename" : "icon_256@2x.png",
"scale" : "2x"
"scale" : "2x",
"size" : "256x256"
},
{
"size" : "512x512",
"filename" : "512.png",
"idiom" : "mac",
"filename" : "icon_512@1x.png",
"scale" : "1x"
"scale" : "1x",
"size" : "512x512"
},
{
"size" : "512x512",
"filename" : "1024.png",
"idiom" : "mac",
"filename" : "icon_512@2x.png",
"scale" : "2x"
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Cocoa
import UserNotifications
import LoginServiceKit
import WidgetKit

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
Expand All @@ -30,6 +31,46 @@ class AppDelegate: NSObject, NSApplicationDelegate {
pref {
LoginServiceKit.addLoginItems()
}

NSAppleEventManager
.shared()
.setEventHandler(
self,
andSelector: #selector(handleURL(event:reply:)),
forEventClass: AEEventClass(kInternetEventClass),
andEventID: AEEventID(kAEGetURL)
)

// ScriptsHandler.default.askPermissionsForUser()
}

@objc func handleURL(event: NSAppleEventDescriptor, reply: NSAppleEventDescriptor) {
if let path = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue?.removingPercentEncoding {

if path.contains("//connect") || path.contains("//disconnect") {
let airpodsViewModel = AirPodsBatteryViewModel()

let leftP = PrefsPersistanceManager().getValuePreferences(from: PreferenceKey.BatteryValue.left.rawValue) as? CGFloat
let rightP = PrefsPersistanceManager().getValuePreferences(from: PreferenceKey.BatteryValue.right.rawValue) as? CGFloat

var isConnected = false

if let left = leftP,
let right = rightP, left > 0.0 && right > 0.0 {
isConnected = true
}
if isConnected && path.contains("//connect") {
return
}

if !isConnected && path.contains("//disconnect") {
return
}

AirPodsBatteryViewModel().toogleCurrentBluetoothDevice()
WidgetCenter.shared.reloadAllTimelines()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ class StatusMenuController: NSObject {

DispatchQueue.main.async {
self?.airpodsBatteryStatusView.updateViewData(self?.airpodsBatteryViewModel)
self?.statusItem.button?.title = self?.airpodsBatteryViewModel.fullStatusMessage ?? ""

if let button = self?.statusItem.button {
let style = NSMutableParagraphStyle()
style.maximumLineHeight = 10
style.alignment = NSTextAlignment.left
let attributes = [NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: NSFont.systemFont(ofSize: 11.0), NSAttributedString.Key.baselineOffset: -5] as [NSAttributedString.Key : Any]
let textString = self?.airpodsBatteryViewModel.fullStatusMessage ?? ""
let attributedTitle = NSAttributedString(string: textString, attributes: attributes)
button.attributedTitle = attributedTitle
}

let pairedDevicesConnected = self?.airpodsBatteryViewModel.connectionStatus == .connected
self?.updateStatusButtonImage(hide: pairedDevicesConnected)
Expand All @@ -154,7 +163,6 @@ class StatusMenuController: NSObject {

@objc fileprivate func updateAirpodsMode() {
if !statusItem.isVisible {
airpodsBatteryViewModel.updateAirpodsMode()
statusItem.button?.title = airpodsBatteryViewModel.fullStatusMessage
if #available(OSX 11, *) {
WidgetCenter.shared.reloadAllTimelines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ extension String {
return []
}
}

func listeningMode() -> String {
if self == NCListeningMode.normal.rawValue {
return "Normal"
}
if self == NCListeningMode.anc.rawValue {
return "Noise Cancellation"
}
if self == NCListeningMode.transparency.rawValue {
return "Transparency"
}
return self
}
}
15 changes: 14 additions & 1 deletion AirpodsPro Battery/AirpodsPro Battery/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,23 @@
<key>NSBluetoothPeripheralUsageDescription</key>
<string>We use bluetooth to fetch data </string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 Mohamed Arradi. All rights reserved.</string>
<string>Copyright © 2024 Mohamed Arradi Alaoui. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>airpodsbattery</string>
<key>CFBundleURLSchemes</key>
<array>
<string>airpodsbattery</string>
</array>
</dict>
</array>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Bluetooth Permission are required to fetch Airpods battery information</string>
</dict>
</plist>
Loading

0 comments on commit bf9b486

Please sign in to comment.