Skip to content

Commit bf9b486

Browse files
Merge pull request #49 from mohamed-arradi/feature/add_custom_url_scheme
v2.2.7: Sonoma Compatibility + Bug Fixes
2 parents b54d02b + fa3560a commit bf9b486

30 files changed

+321
-76
lines changed

AirpodsPro Battery/AirpodsPro Battery.xcodeproj/project.pbxproj

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 53;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -362,6 +362,7 @@
362362
isa = PBXGroup;
363363
children = (
364364
EBC7AD3E2386769700A53E83 /* AppDelegate.swift */,
365+
EBC7AD4E2386776000A53E83 /* String+Localized.swift */,
365366
EBC7AD402386769700A53E83 /* StatusMenuController.swift */,
366367
);
367368
path = Controllers;
@@ -370,7 +371,6 @@
370371
EBC7AD652387DF2300A53E83 /* Extensions */ = {
371372
isa = PBXGroup;
372373
children = (
373-
EBC7AD4E2386776000A53E83 /* String+Localized.swift */,
374374
EBFE03A523A36356006095DB /* Bundle+Versioning.swift */,
375375
D904C6462747AB94009856C5 /* NSScreen+Extension.swift */,
376376
D957E012274E6658007F940C /* System+Extension.swift */,
@@ -701,7 +701,7 @@
701701
"@executable_path/../Frameworks",
702702
"@executable_path/../../../../Frameworks",
703703
);
704-
MACOSX_DEPLOYMENT_TARGET = 11.0;
704+
MACOSX_DEPLOYMENT_TARGET = 13.5;
705705
MARKETING_VERSION = 2.2.6;
706706
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery.batteryWidget";
707707
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -733,7 +733,7 @@
733733
"@executable_path/../Frameworks",
734734
"@executable_path/../../../../Frameworks",
735735
);
736-
MACOSX_DEPLOYMENT_TARGET = 11.0;
736+
MACOSX_DEPLOYMENT_TARGET = 13.5;
737737
MARKETING_VERSION = 2.2.6;
738738
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery.batteryWidget";
739739
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -840,7 +840,7 @@
840840
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
841841
GCC_WARN_UNUSED_FUNCTION = YES;
842842
GCC_WARN_UNUSED_VARIABLE = YES;
843-
MACOSX_DEPLOYMENT_TARGET = 11.0;
843+
MACOSX_DEPLOYMENT_TARGET = 12.0;
844844
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
845845
MTL_FAST_MATH = YES;
846846
ONLY_ACTIVE_ARCH = YES;
@@ -898,7 +898,7 @@
898898
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
899899
GCC_WARN_UNUSED_FUNCTION = YES;
900900
GCC_WARN_UNUSED_VARIABLE = YES;
901-
MACOSX_DEPLOYMENT_TARGET = 11.0;
901+
MACOSX_DEPLOYMENT_TARGET = 12.0;
902902
MTL_ENABLE_DEBUG_INFO = NO;
903903
MTL_FAST_MATH = YES;
904904
PRODUCT_NAME = "Airpods Battery Monitor";
@@ -918,7 +918,7 @@
918918
CODE_SIGN_IDENTITY = "Apple Development";
919919
CODE_SIGN_STYLE = Automatic;
920920
COMBINE_HIDPI_IMAGES = YES;
921-
CURRENT_PROJECT_VERSION = 0;
921+
CURRENT_PROJECT_VERSION = 1;
922922
DEAD_CODE_STRIPPING = YES;
923923
DEVELOPMENT_TEAM = 8JVK53ZY4C;
924924
ENABLE_HARDENED_RUNTIME = YES;
@@ -928,8 +928,8 @@
928928
"$(inherited)",
929929
"@executable_path/../Frameworks",
930930
);
931-
MACOSX_DEPLOYMENT_TARGET = 11.0;
932-
MARKETING_VERSION = 2.2.6;
931+
MACOSX_DEPLOYMENT_TARGET = 13.5;
932+
MARKETING_VERSION = 2.2.7;
933933
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery";
934934
PRODUCT_NAME = "Airpods Battery Monitor";
935935
SWIFT_OBJC_BRIDGING_HEADER = "AirpodsPro Battery/External/TransparencyCore/AirpodsPro Battery-Bridging-Header.h";
@@ -948,7 +948,7 @@
948948
CODE_SIGN_IDENTITY = "Apple Development";
949949
CODE_SIGN_STYLE = Automatic;
950950
COMBINE_HIDPI_IMAGES = YES;
951-
CURRENT_PROJECT_VERSION = 0;
951+
CURRENT_PROJECT_VERSION = 1;
952952
DEAD_CODE_STRIPPING = YES;
953953
DEVELOPMENT_TEAM = 8JVK53ZY4C;
954954
ENABLE_HARDENED_RUNTIME = YES;
@@ -958,8 +958,8 @@
958958
"$(inherited)",
959959
"@executable_path/../Frameworks",
960960
);
961-
MACOSX_DEPLOYMENT_TARGET = 11.0;
962-
MARKETING_VERSION = 2.2.6;
961+
MACOSX_DEPLOYMENT_TARGET = 13.5;
962+
MARKETING_VERSION = 2.2.7;
963963
PRODUCT_BUNDLE_IDENTIFIER = "com.mac.AirpodsPro-Battery";
964964
PRODUCT_NAME = "Airpods Battery Monitor";
965965
SWIFT_OBJC_BRIDGING_HEADER = "AirpodsPro Battery/External/TransparencyCore/AirpodsPro Battery-Bridging-Header.h";
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2+
"originHash" : "1ec685d27a84c49c67d8ed572df27602b3ff131cede7880b853cef2bde046d2a",
23
"pins" : [
34
{
45
"identity" : "loginservicekit",
56
"kind" : "remoteSourceControl",
67
"location" : "https://github.com/Clipy/LoginServiceKit",
78
"state" : {
89
"branch" : "master",
9-
"revision" : "a8e68051aca8bbb702e62ab36006a301966ab053"
10+
"revision" : "56dce9dbf4367c1445ef2343a2a912bbe5019a6c"
1011
}
1112
}
1213
],
13-
"version" : 2
14+
"version" : 3
1415
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
{
22
"images" : [
33
{
4-
"size" : "16x16",
4+
"filename" : "16.png",
55
"idiom" : "mac",
6-
"filename" : "icon_16@1x.png",
7-
"scale" : "1x"
6+
"scale" : "1x",
7+
"size" : "16x16"
88
},
99
{
10-
"size" : "16x16",
10+
"filename" : "32.png",
1111
"idiom" : "mac",
12-
"filename" : "icon_16@2x.png",
13-
"scale" : "2x"
12+
"scale" : "2x",
13+
"size" : "16x16"
1414
},
1515
{
16-
"size" : "32x32",
16+
"filename" : "32.png",
1717
"idiom" : "mac",
18-
"filename" : "icon_32@1x.png",
19-
"scale" : "1x"
18+
"scale" : "1x",
19+
"size" : "32x32"
2020
},
2121
{
22-
"size" : "32x32",
22+
"filename" : "64.png",
2323
"idiom" : "mac",
24-
"filename" : "icon_32@2x.png",
25-
"scale" : "2x"
24+
"scale" : "2x",
25+
"size" : "32x32"
2626
},
2727
{
28-
"size" : "128x128",
28+
"filename" : "128.png",
2929
"idiom" : "mac",
30-
"filename" : "icon_128@1x.png",
31-
"scale" : "1x"
30+
"scale" : "1x",
31+
"size" : "128x128"
3232
},
3333
{
34-
"size" : "128x128",
34+
"filename" : "256.png",
3535
"idiom" : "mac",
36-
"filename" : "icon_128@2x.png",
37-
"scale" : "2x"
36+
"scale" : "2x",
37+
"size" : "128x128"
3838
},
3939
{
40-
"size" : "256x256",
40+
"filename" : "256.png",
4141
"idiom" : "mac",
42-
"filename" : "icon_256@1x.png",
43-
"scale" : "1x"
42+
"scale" : "1x",
43+
"size" : "256x256"
4444
},
4545
{
46-
"size" : "256x256",
46+
"filename" : "512.png",
4747
"idiom" : "mac",
48-
"filename" : "icon_256@2x.png",
49-
"scale" : "2x"
48+
"scale" : "2x",
49+
"size" : "256x256"
5050
},
5151
{
52-
"size" : "512x512",
52+
"filename" : "512.png",
5353
"idiom" : "mac",
54-
"filename" : "icon_512@1x.png",
55-
"scale" : "1x"
54+
"scale" : "1x",
55+
"size" : "512x512"
5656
},
5757
{
58-
"size" : "512x512",
58+
"filename" : "1024.png",
5959
"idiom" : "mac",
60-
"filename" : "icon_512@2x.png",
61-
"scale" : "2x"
60+
"scale" : "2x",
61+
"size" : "512x512"
6262
}
6363
],
6464
"info" : {
65-
"version" : 1,
66-
"author" : "xcode"
65+
"author" : "xcode",
66+
"version" : 1
6767
}
68-
}
68+
}

AirpodsPro Battery/AirpodsPro Battery/Controllers/AppDelegate.swift

+41
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Cocoa
1010
import UserNotifications
1111
import LoginServiceKit
12+
import WidgetKit
1213

1314
@NSApplicationMain
1415
class AppDelegate: NSObject, NSApplicationDelegate {
@@ -30,6 +31,46 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3031
pref {
3132
LoginServiceKit.addLoginItems()
3233
}
34+
35+
NSAppleEventManager
36+
.shared()
37+
.setEventHandler(
38+
self,
39+
andSelector: #selector(handleURL(event:reply:)),
40+
forEventClass: AEEventClass(kInternetEventClass),
41+
andEventID: AEEventID(kAEGetURL)
42+
)
43+
44+
// ScriptsHandler.default.askPermissionsForUser()
45+
}
46+
47+
@objc func handleURL(event: NSAppleEventDescriptor, reply: NSAppleEventDescriptor) {
48+
if let path = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue?.removingPercentEncoding {
49+
50+
if path.contains("//connect") || path.contains("//disconnect") {
51+
let airpodsViewModel = AirPodsBatteryViewModel()
52+
53+
let leftP = PrefsPersistanceManager().getValuePreferences(from: PreferenceKey.BatteryValue.left.rawValue) as? CGFloat
54+
let rightP = PrefsPersistanceManager().getValuePreferences(from: PreferenceKey.BatteryValue.right.rawValue) as? CGFloat
55+
56+
var isConnected = false
57+
58+
if let left = leftP,
59+
let right = rightP, left > 0.0 && right > 0.0 {
60+
isConnected = true
61+
}
62+
if isConnected && path.contains("//connect") {
63+
return
64+
}
65+
66+
if !isConnected && path.contains("//disconnect") {
67+
return
68+
}
69+
70+
AirPodsBatteryViewModel().toogleCurrentBluetoothDevice()
71+
WidgetCenter.shared.reloadAllTimelines()
72+
}
73+
}
3374
}
3475
}
3576

AirpodsPro Battery/AirpodsPro Battery/Controllers/StatusMenuController.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,16 @@ class StatusMenuController: NSObject {
142142

143143
DispatchQueue.main.async {
144144
self?.airpodsBatteryStatusView.updateViewData(self?.airpodsBatteryViewModel)
145-
self?.statusItem.button?.title = self?.airpodsBatteryViewModel.fullStatusMessage ?? ""
145+
146+
if let button = self?.statusItem.button {
147+
let style = NSMutableParagraphStyle()
148+
style.maximumLineHeight = 10
149+
style.alignment = NSTextAlignment.left
150+
let attributes = [NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: NSFont.systemFont(ofSize: 11.0), NSAttributedString.Key.baselineOffset: -5] as [NSAttributedString.Key : Any]
151+
let textString = self?.airpodsBatteryViewModel.fullStatusMessage ?? ""
152+
let attributedTitle = NSAttributedString(string: textString, attributes: attributes)
153+
button.attributedTitle = attributedTitle
154+
}
146155

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

155164
@objc fileprivate func updateAirpodsMode() {
156165
if !statusItem.isVisible {
157-
airpodsBatteryViewModel.updateAirpodsMode()
158166
statusItem.button?.title = airpodsBatteryViewModel.fullStatusMessage
159167
if #available(OSX 11, *) {
160168
WidgetCenter.shared.reloadAllTimelines()

AirpodsPro Battery/AirpodsPro Battery/Extensions/String+Localized.swift renamed to AirpodsPro Battery/AirpodsPro Battery/Controllers/String+Localized.swift

+13
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ extension String {
5353
return []
5454
}
5555
}
56+
57+
func listeningMode() -> String {
58+
if self == NCListeningMode.normal.rawValue {
59+
return "Normal"
60+
}
61+
if self == NCListeningMode.anc.rawValue {
62+
return "Noise Cancellation"
63+
}
64+
if self == NCListeningMode.transparency.rawValue {
65+
return "Transparency"
66+
}
67+
return self
68+
}
5669
}

AirpodsPro Battery/AirpodsPro Battery/Info.plist

+14-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,23 @@
3333
<key>NSBluetoothPeripheralUsageDescription</key>
3434
<string>We use bluetooth to fetch data </string>
3535
<key>NSHumanReadableCopyright</key>
36-
<string>Copyright © 2019 Mohamed Arradi. All rights reserved.</string>
36+
<string>Copyright © 2024 Mohamed Arradi Alaoui. All rights reserved.</string>
3737
<key>NSMainNibFile</key>
3838
<string>MainMenu</string>
3939
<key>NSPrincipalClass</key>
4040
<string>NSApplication</string>
41+
<key>CFBundleURLTypes</key>
42+
<array>
43+
<dict>
44+
<key>CFBundleURLName</key>
45+
<string>airpodsbattery</string>
46+
<key>CFBundleURLSchemes</key>
47+
<array>
48+
<string>airpodsbattery</string>
49+
</array>
50+
</dict>
51+
</array>
52+
<key>NSBluetoothAlwaysUsageDescription</key>
53+
<string>Bluetooth Permission are required to fetch Airpods battery information</string>
4154
</dict>
4255
</plist>

0 commit comments

Comments
 (0)