forked from greenaddress/WalletCrx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
53 lines (51 loc) · 1.7 KB
/
background.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
var lang, usbDevices = {};
var start = function() {
chrome.app.window.create(lang+'/wallet.html', {
'bounds': {
'width': 992,
'height': 700,
},
'id': 'wallet'
}, function() {
chrome.app.window.get('wallet').onClosed.removeListener(start);
chrome.app.window.get('wallet').onClosed.addListener(function () {
for (var i in usbDevices) {
winUSBInterface.prototype.close.apply(usbDevices[i]);
}
});
});
}
var SUPPORTED_LANGS = ['de', 'en', 'es', 'fr', 'it', 'pl', 'ru', 'uk', 'sv', 'nl', 'el', 'th'];
chrome.app.runtime.onLaunched.addListener(function() {
chrome.storage.local.get('language', function(items) {
lang = items.language;
if (!lang) {
chrome.i18n.getAcceptLanguages(function(langs) {
lang = 'en';
for (var i = 0; i < langs.length; i++) {
if (SUPPORTED_LANGS.indexOf(langs[i]) != -1) {
lang = langs[i];
break;
}
}
console.log(lang);
start();
});
} else {
start();
}
});
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.changeLang) {
var win = chrome.app.window.get('wallet');
lang = request.lang;
win.onClosed.addListener(start);
win.close();
} else if (request.usbClaimed) {
usbDevices[request.usbClaimed.device.handle] = request.usbClaimed;
} else if (request.usbClosed) {
delete usbDevices[request.usbClosed.device.handle];
}
return true;
});