Skip to content

Commit fb22d7e

Browse files
committed
chore: improve linting
1 parent ab7b1f4 commit fb22d7e

File tree

6 files changed

+87
-32
lines changed

6 files changed

+87
-32
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: macOS-latest
14+
steps:
15+
- uses: actions/checkout@master
16+
- name: Use Node.js 12.x
17+
uses: actions/setup-node@v1
18+
with:
19+
version: 12.x
20+
- name: Lint
21+
run: |
22+
npm install
23+
npm run lint

.github/workflows/nodejs.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: Test
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
build:
7-
813
runs-on: macOS-latest
9-
1014
steps:
1115
- uses: actions/checkout@master
1216
- name: Use Node.js 10.x

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"parser": "typescript",
7+
"endOfLine": "lf"
8+
}

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"build": "node-gyp rebuild",
88
"clean": "node-gyp clean",
9-
"format": "clang-format -i permissions.mm",
9+
"lint": "prettier --check index.js",
10+
"format": "clang-format -i permissions.mm && prettier --write index.js",
1011
"test": "./node_modules/.bin/mocha --reporter spec"
1112
},
1213
"repository": {
@@ -34,6 +35,7 @@
3435
"chai": "^4.2.0",
3536
"clang-format": "^1.3.0",
3637
"mocha": "^6.2.2",
37-
"node-gyp": "^6.0.1"
38+
"node-gyp": "^6.0.1",
39+
"prettier": "^2.0.4"
3840
}
3941
}

permissions.mm

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -287,59 +287,71 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
287287
Napi::Promise AskForCameraAccess(const Napi::CallbackInfo &info) {
288288
Napi::Env env = info.Env();
289289
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env);
290-
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(env, Napi::Function::New(env, NoOp), "cameraAccessCallback", 0, 1, [](Napi::Env) {});
290+
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(
291+
env, Napi::Function::New(env, NoOp), "cameraAccessCallback", 0, 1,
292+
[](Napi::Env) {});
291293

292294
if (@available(macOS 10.14, *)) {
293295
std::string auth_status = MediaAuthStatus("camera");
294296

295297
if (auth_status == "not determined") {
296-
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
297-
auto callback = [=](Napi::Env env, Napi::Function js_cb, const char *granted) {
298-
deferred.Resolve(Napi::String::New(env, granted));
299-
};
300-
301-
ts_fn.BlockingCall(granted ? "authorized" : "denied", callback);
302-
}];
303-
} else if (auth_status == "denied"){
298+
[AVCaptureDevice
299+
requestAccessForMediaType:AVMediaTypeVideo
300+
completionHandler:^(BOOL granted) {
301+
auto callback = [=](Napi::Env env, Napi::Function js_cb,
302+
const char *granted) {
303+
deferred.Resolve(Napi::String::New(env, granted));
304+
};
305+
306+
ts_fn.BlockingCall(granted ? "authorized" : "denied",
307+
callback);
308+
}];
309+
} else if (auth_status == "denied") {
304310
NSWorkspace *workspace = [[NSWorkspace alloc] init];
305-
NSString *pref_string = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Camera";
306-
311+
NSString *pref_string = @"x-apple.systempreferences:com.apple.preference."
312+
@"security?Privacy_Camera";
313+
307314
[workspace openURL:[NSURL URLWithString:pref_string]];
308315

309316
deferred.Resolve(Napi::String::New(env, "denied"));
310317
} else {
311318
deferred.Resolve(Napi::String::New(env, auth_status));
312-
}
319+
}
313320
} else {
314321
deferred.Resolve(Napi::String::New(env, "authorized"));
315322
}
316323

317324
return deferred.Promise();
318325
}
319326

320-
321-
322327
// Request Microphone Access.
323328
Napi::Promise AskForMicrophoneAccess(const Napi::CallbackInfo &info) {
324329
Napi::Env env = info.Env();
325330
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env);
326-
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(env, Napi::Function::New(env, NoOp), "microphoneAccessCallback", 0, 1, [](Napi::Env) {});
331+
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(
332+
env, Napi::Function::New(env, NoOp), "microphoneAccessCallback", 0, 1,
333+
[](Napi::Env) {});
327334

328335
if (@available(macOS 10.14, *)) {
329336
std::string auth_status = MediaAuthStatus("microphone");
330337

331338
if (auth_status == "not determined") {
332-
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
333-
auto callback = [=](Napi::Env env, Napi::Function js_cb, const char *granted) {
334-
deferred.Resolve(Napi::String::New(env, granted));
335-
};
336-
337-
ts_fn.BlockingCall(granted ? "authorized" : "denied", callback);
338-
}];
339+
[AVCaptureDevice
340+
requestAccessForMediaType:AVMediaTypeAudio
341+
completionHandler:^(BOOL granted) {
342+
auto callback = [=](Napi::Env env, Napi::Function js_cb,
343+
const char *granted) {
344+
deferred.Resolve(Napi::String::New(env, granted));
345+
};
346+
347+
ts_fn.BlockingCall(granted ? "authorized" : "denied",
348+
callback);
349+
}];
339350
} else if (auth_status == "denied") {
340351
NSWorkspace *workspace = [[NSWorkspace alloc] init];
341-
NSString *pref_string = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone";
342-
352+
NSString *pref_string = @"x-apple.systempreferences:com.apple.preference."
353+
@"security?Privacy_Microphone";
354+
343355
[workspace openURL:[NSURL URLWithString:pref_string]];
344356

345357
deferred.Resolve(Napi::String::New(env, "denied"));
@@ -388,9 +400,9 @@ void AskForAccessibilityAccess(const Napi::CallbackInfo &info) {
388400
Napi::Function::New(env, AskForRemindersAccess));
389401
exports.Set(Napi::String::New(env, "askForFullDiskAccess"),
390402
Napi::Function::New(env, AskForFullDiskAccess));
391-
exports.Set(Napi::String::New(env, "askForCameraAccess"),
403+
exports.Set(Napi::String::New(env, "askForCameraAccess"),
392404
Napi::Function::New(env, AskForCameraAccess));
393-
exports.Set(Napi::String::New(env, "askForMicrophoneAccess"),
405+
exports.Set(Napi::String::New(env, "askForMicrophoneAccess"),
394406
Napi::Function::New(env, AskForMicrophoneAccess));
395407
exports.Set(Napi::String::New(env, "askForScreenCaptureAccess"),
396408
Napi::Function::New(env, AskForScreenCaptureAccess));

0 commit comments

Comments
 (0)