| 492 | var selectedPinIndex = 0; |
| 493 | |
| 494 | function chooseAndCreateKey() { |
| 495 | selectedPinIndex = 0; |
| 496 | |
| 497 | var keyTypeChoices = {}; |
| 498 | var brandNames = Object.keys(keys).sort(); |
| 499 | for (var i = 0; i < brandNames.length; i++) { |
| 500 | var brand = brandNames[i]; |
| 501 | var displayName = keys[brand].displayName || brand; |
| 502 | keyTypeChoices[displayName] = brand; |
| 503 | } |
| 504 | keyTypeChoices.Load = "Load"; |
| 505 | keyTypeChoices.Exit = "Exit"; |
| 506 | |
| 507 | var type = dialog.choice(keyTypeChoices); |
| 508 | if (!type) type = "Exit"; |
| 509 | |
| 510 | var outline, show; |
| 511 | |
| 512 | if (type !== "Exit") { |
| 513 | if (type === "Load") { |
| 514 | key = new Key(type, "", "decode"); |
| 515 | var filePath = dialog.pickFile("/keys", {withFileTypes: true}); |
| 516 | if (!filePath) { |
| 517 | return chooseAndCreateKey(); |
| 518 | } |
| 519 | var fileContent = storage.read(filePath); |
| 520 | if (!fileContent) { |
| 521 | return chooseAndCreateKey(); |
| 522 | } |
| 523 | key.load(fileContent); |
| 524 | } else { |
| 525 | var outlines = keys[String(type)].outlines || []; |
| 526 | var outlineChoices = {}; |
| 527 | for (var j = 0; j < outlines.length; j++) { |
| 528 | var o = outlines[j]; |
| 529 | outlineChoices[o] = o; |
| 530 | } |
| 531 | outlineChoices.Cancel = "Cancel"; |
| 532 | |
| 533 | outline = dialog.choice(outlineChoices); |
| 534 | if (!outline || outline === "Cancel") { |
| 535 | return chooseAndCreateKey(); |
| 536 | } |
| 537 | |
| 538 | show = dialog.choice({ |
| 539 | Decode: "decode", |
| 540 | Random: "random", |
| 541 | Cancel: "Cancel" |
| 542 | }); |
| 543 | if (!show || show === "Cancel") { |
| 544 | return chooseAndCreateKey(); |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (type !== "Load") { |
| 550 | key = new Key(type, outline, show); |
| 551 | } |