-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (68 loc) · 2.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
let windowsSecurityCredentialsUiModule = null;
function getWindowsSecurityCredentialsUiModule() {
if (windowsSecurityCredentialsUiModule != null) {
return windowsSecurityCredentialsUiModule;
}
try {
windowsSecurityCredentialsUiModule = require('@nodert-win10-rs4/windows.security.credentials.ui');
return windowsSecurityCredentialsUiModule;
} catch (e) {
console.error(e);
}
return null;
}
async function supportsBiometric() {
const availability = await checkAvailabilityAsync();
return getAllowedAvailabilities().includes(availability);
}
async function checkAvailabilityAsync() {
const module = getWindowsSecurityCredentialsUiModule();
if (module != null) {
return new Promise((resolve, reject) => {
try {
module.UserConsentVerifier.checkAvailabilityAsync((error, result) => {
if (error) {
return resolve(null);
}
return resolve(result);
});
} catch (e) {
console.error(e);
return resolve(null);
}
});
}
return Promise.resolve(null);
}
function getAllowedAvailabilities() {
try {
const module = getWindowsSecurityCredentialsUiModule();
if (module != null) {
return [
module.UserConsentVerifierAvailability.available,
module.UserConsentVerifierAvailability.deviceBusy,
];
}
} catch (e) {
console.error(e);
}
return [];
}
function getWindowsMajorVersion() {
if (process.platform !== 'win32') {
return -1;
}
try {
const version = require('os').release();
return Number.parseInt(version.split('.')[0], 10);
}
catch (e) {
console.error(e);
}
return -1;
}
const version = getWindowsMajorVersion();
console.info(`Windows Major Version: ${version}`);
let supported = false;
supportsBiometric().then(value => supported = value, e => console.error(e));
console.info(`Biometrics Supported: ${supported}`);