add langauge debugging. fix corner cases with favorite device selection

This commit is contained in:
Stewart Allen 2019-04-12 22:06:53 -04:00
commit 99b2d4a021
2 changed files with 33 additions and 5 deletions

View file

@ -15,16 +15,29 @@ var gs_kiri_lang = exports;
LANG.set = (key) => { LANG.set = (key) => {
if (LANG[key]) { if (LANG[key]) {
let map = LANG[key]; let map = LANG[key];
let missing = [];
let invalid = [];
// default to EN values when missing // default to EN values when missing
Object.keys(LANG.en).forEach(key => { Object.keys(LANG.en).forEach(key => {
if (!map[key]) { if (!map[key]) {
map[key] = LANG.en[key]; map[key] = LANG.en[key];
missing.push(key);
} }
}); });
// update current map from chosen map // update current map from chosen map
Object.keys(map).forEach(key => { Object.keys(map).forEach(key => {
LANG.current[key] = map[key]; if (LANG.en[key]) {
LANG.current[key] = map[key];
} else {
invalid.push(key);
}
}); });
if (missing.length) {
console.log(`language map "${key}" missing keys [${missing.length}]: ${missing.join(', ')}`);
}
if (invalid.length) {
console.log(`language map "${key}" invalid keys [${invalid.length}]: ${invalid.join(', ')}`);
}
} }
} }
@ -54,6 +67,7 @@ var gs_kiri_lang = exports;
}; };
LANG.test = { LANG.test = {
bogus: "not a valid key",
version: "_version_", version: "_version_",
dev_name: "_name_" dev_name: "_name_"
}; };

View file

@ -3229,6 +3229,9 @@ self.kiri.license = exports.LICENSE;
}; };
UI.deviceSelect.innerHTML = ''; UI.deviceSelect.innerHTML = '';
let incr = 0;
let found = false;
let first = devices[0];
devices.forEach(function(device, index) { devices.forEach(function(device, index) {
var opt = DOC.createElement('option'), var opt = DOC.createElement('option'),
fav = isFavoriteDevice(device), fav = isFavoriteDevice(device),
@ -3236,13 +3239,20 @@ self.kiri.license = exports.LICENSE;
if (showFavorites && !(fav || loc)) { if (showFavorites && !(fav || loc)) {
return; return;
} }
if (incr === 0) {
first = device;
}
opt.appendChild(DOC.createTextNode(device)); opt.appendChild(DOC.createTextNode(device));
opt.onclick = function() { selectDevice(device) }; opt.onclick = function() { selectDevice(device) };
opt.ondblclick = function() { opt.ondblclick = function() {
if (settings.favorites[device]) { if (settings.favorites[device]) {
delete settings.favorites[device]; if (confirm(`remove "${device}" from favorites`)) {
delete settings.favorites[device];
}
} else { } else {
settings.favorites[device] = true; if (confirm(`add "${device}" to favorites`)) {
settings.favorites[device] = true;
}
} }
showDevices(); showDevices();
}; };
@ -3251,7 +3261,11 @@ self.kiri.license = exports.LICENSE;
if (loc) opt.setAttribute("local", 1); if (loc) opt.setAttribute("local", 1);
} }
UI.deviceSelect.appendChild(opt); UI.deviceSelect.appendChild(opt);
if (device === selected) selectedIndex = index; if (device === selected) {
selectedIndex = incr;
found = true;
}
incr++;
}); });
if (selectedIndex >= 0) { if (selectedIndex >= 0) {
@ -3259,7 +3273,7 @@ self.kiri.license = exports.LICENSE;
selectDevice(selected); selectDevice(selected);
} else { } else {
UI.deviceSelect.selectedIndex = 0; UI.deviceSelect.selectedIndex = 0;
selectDevice(devices[0]); selectDevice(first);
} }
showDialog('devices', true); showDialog('devices', true);