-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
70 lines (67 loc) · 1.85 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
function NativeBinding() {
this._tried = false;
this._keymapping = null;
}
NativeBinding.prototype._init = function() {
if (this._tried) {
return;
}
this._tried = true;
try {
this._keymapping = require('./build/Release/keymapping');
} catch (err) {
// fallback to the debug build
this._keymapping = require('./build/Debug/keymapping');
}
};
NativeBinding.prototype.getKeyMap = function() {
try {
this._init();
return this._keymapping.getKeyMap();
} catch(err) {
console.error(err);
return [];
}
};
NativeBinding.prototype.getCurrentKeyboardLayout = function() {
try {
this._init();
return this._keymapping.getCurrentKeyboardLayout();
} catch(err) {
console.error(err);
return null;
}
};
NativeBinding.prototype.onDidChangeKeyboardLayout = function(callback) {
try {
this._init();
this._keymapping.onDidChangeKeyboardLayout(callback);
} catch(err) {
console.error(err);
}
}
NativeBinding.prototype.isISOKeyboard = function(callback) {
try {
this._init();
return this._keymapping.isISOKeyboard();
} catch(err) {
return false;
}
}
var binding = new NativeBinding();
exports.getCurrentKeyboardLayout = function() {
return binding.getCurrentKeyboardLayout();
};
exports.getKeyMap = function() {
return binding.getKeyMap();
};
exports.onDidChangeKeyboardLayout = function(callback) {
return binding.onDidChangeKeyboardLayout(callback);
};
exports.isISOKeyboard = function(callback) {
return binding.isISOKeyboard(callback);
};