Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 3682c56

Browse files
author
John Kleinschmidt
authored
migrate keytar to napi (#268)
1 parent 2b1a9fa commit 3682c56

File tree

7 files changed

+228
-199
lines changed

7 files changed

+228
-199
lines changed

binding.gyp

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
'targets': [
33
{
44
'target_name': 'keytar',
5-
'include_dirs': [ '<!(node -e "require(\'nan\')")' ],
5+
'cflags!': [ '-fno-exceptions' ],
6+
'cflags_cc!': [ '-fno-exceptions' ],
7+
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
8+
'CLANG_CXX_LIBRARY': 'libc++',
9+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
10+
},
11+
'msvs_settings': {
12+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
13+
},
14+
'include_dirs' : [ "<!@(node -p \"require('node-addon-api').include\")" ],
615
'sources': [
716
'src/async.cc',
817
'src/main.cc',

lib/keytar.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,38 @@ function checkRequired(val, name) {
66
}
77
}
88

9-
function callbackPromise(callback) {
10-
if (typeof callback === 'function') {
11-
return new Promise(function(resolve, reject) {
12-
callback((err, val) => {
13-
if (err) {
14-
reject(err)
15-
} else {
16-
resolve(val)
17-
}
18-
})
19-
})
20-
} else {
21-
throw new Error('Callback required')
22-
}
23-
}
24-
259
module.exports = {
2610
getPassword: function (service, account) {
2711
checkRequired(service, 'Service')
2812
checkRequired(account, 'Account')
2913

30-
return callbackPromise(callback => keytar.getPassword(service, account, callback))
14+
return keytar.getPassword(service, account)
3115
},
3216

3317
setPassword: function (service, account, password) {
3418
checkRequired(service, 'Service')
3519
checkRequired(account, 'Account')
3620
checkRequired(password, 'Password')
3721

38-
return callbackPromise(callback => keytar.setPassword(service, account, password, callback))
22+
return keytar.setPassword(service, account, password)
3923
},
4024

4125
deletePassword: function (service, account) {
4226
checkRequired(service, 'Service')
4327
checkRequired(account, 'Account')
4428

45-
return callbackPromise(callback => keytar.deletePassword(service, account, callback))
29+
return keytar.deletePassword(service, account)
4630
},
4731

4832
findPassword: function (service) {
4933
checkRequired(service, 'Service')
5034

51-
return callbackPromise(callback => keytar.findPassword(service, callback))
35+
return keytar.findPassword(service)
5236
},
5337

5438
findCredentials: function (service) {
5539
checkRequired(service, 'Service')
5640

57-
return callbackPromise(callback => keytar.findCredentials(service, callback))
41+
return keytar.findCredentials(service)
5842
}
5943
}

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prebuild": "^10.0.0"
5353
},
5454
"dependencies": {
55-
"nan": "2.14.1",
55+
"node-addon-api": "^3.0.0",
5656
"prebuild-install": "5.3.3"
5757
}
5858
}

0 commit comments

Comments
 (0)