Skip to content

Commit 911514f

Browse files
committed
feat: add permission status for Apple Music
1 parent 2936161 commit 911514f

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@ Return Value Descriptions:
5050
* Access to `photos` will always return a status of `authorized` prior to macOS 10.13, as the underlying API was not introduced until that version.
5151
* Access to `speech-recognition` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.
5252
* Access to `bluetooth` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.
53+
* Access to `music-library` will always return a status of `authorized` prior to macOS 11.0, as the underlying API was not introduced until that version.
5354

5455
Example:
5556
```js
5657
const types = [
57-
'contacts',
58+
'accessibility',
59+
'bluetooth',
5860
'calendar',
61+
'camera',
62+
'contacts',
5963
'reminders',
6064
'full-disk-access',
61-
'camera',
62-
'photos',
63-
'speech-recognition',
64-
'microphone',
65-
'accessibility',
6665
'location',
66+
'microphone',
67+
'music-library',
68+
'photos',
6769
'screen',
68-
'bluetooth'
70+
'speech-recognition'
6971
]
7072

7173
for (const type of types) {

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function getAuthStatus(type) {
1010
'photos',
1111
'speech-recognition',
1212
'microphone',
13+
'music-library',
1314
'accessibility',
1415
'location',
1516
'screen',

permissions.mm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <Foundation/Foundation.h>
1111
#import <Photos/Photos.h>
1212
#import <Speech/Speech.h>
13+
#import <Storekit/Storekit.h>
1314
#import <pwd.h>
1415

1516
/***** HELPER FUNCTIONS *****/
@@ -134,6 +135,25 @@ bool HasOpenSystemPreferencesDialog() {
134135
return kAuthorized;
135136
}
136137

138+
// Returns a status indicating whether the user has authorized Apple Music
139+
// Library access.
140+
std::string MusicLibraryAuthStatus() {
141+
if (@available(macOS 10.16, *)) {
142+
switch ([SKCloudServiceController authorizationStatus]) {
143+
case SKCloudServiceAuthorizationStatusAuthorized:
144+
return kAuthorized;
145+
case SKCloudServiceAuthorizationStatusDenied:
146+
return kDenied;
147+
case SKCloudServiceAuthorizationStatusRestricted:
148+
return kRestricted;
149+
default:
150+
return kNotDetermined;
151+
}
152+
}
153+
154+
return kAuthorized;
155+
}
156+
137157
// Returns a status indicating whether the user has authorized
138158
// Calendar/Reminders access.
139159
std::string EventAuthStatus(const std::string &type) {
@@ -332,6 +352,8 @@ bool HasOpenSystemPreferencesDialog() {
332352
auth_status = ScreenAuthStatus();
333353
} else if (type == "bluetooth") {
334354
auth_status = BluetoothAuthStatus();
355+
} else if (type == "music-library") {
356+
auth_status = MusicLibraryAuthStatus();
335357
}
336358

337359
return Napi::Value::From(env, auth_status);

test/module.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
const { expect } = require('chai')
2-
const {
3-
askForFoldersAccess,
4-
getAuthStatus,
5-
} = require('../index')
2+
const { askForFoldersAccess, getAuthStatus } = require('../index')
63

74
describe('node-mac-permissions', () => {
85
describe('getAuthStatus()', () => {
@@ -22,9 +19,10 @@ describe('node-mac-permissions', () => {
2219
'photos',
2320
'speech-recognition',
2421
'microphone',
22+
'music-library',
2523
'accessibility',
2624
'location',
27-
'screen'
25+
'screen',
2826
]
2927

3028
const statuses = ['not determined', 'denied', 'authorized', 'restricted']

0 commit comments

Comments
 (0)