|
23 | 23 | const WS = /^\s*$/; // KV:regexes for parsing env vars |
24 | 24 | const maxl = 1000; |
25 | 25 | const cnFile = `${D.el.app.getPath('userData')}/connections.json`; |
| 26 | + const lcnFile = `${D.el.app.getPath('userData')}/last_configuration.json`; |
26 | 27 | const trunc = x => (x.length > maxl ? `${x.slice(0, maxl - 3)}...` : x); |
27 | 28 | const shEsc = x => `'${x.replace(/'/g, "'\\''")}'`; // shell escape |
28 | 29 | const toBuf = (x) => { |
|
98 | 99 | ); |
99 | 100 | return; |
100 | 101 | } |
101 | | - if (((+fs.statSync(cnFile).mtime) !== D.conns_modified)) { |
| 102 | + if (fs.existsSync(cnFile) && ((+fs.statSync(cnFile).mtime) !== D.conns_modified)) { |
102 | 103 | const r = $.confirm('Connections file has been modified, do you want to overwrite with your changes?'); |
103 | 104 | if (!r) return; |
104 | 105 | } |
105 | 106 | const a = q.favs.children; |
106 | 107 | const b = []; |
107 | | - for (let i = 0; i < a.length; i++) b[i] = a[i].cnData; |
| 108 | + for (let i = 0; i < a.length; i++) { |
| 109 | + const conf = a[i].cnData; |
| 110 | + conf.name != 'last configuration' && b.push(conf); |
| 111 | + } |
108 | 112 | D.conns = b; |
109 | 113 | try { |
110 | 114 | fs.writeFileSync(cnFile, JSON.stringify(D.conns)); |
|
114 | 118 | toastr.error(`${e.name}: ${e.message}`, 'Save failed'); |
115 | 119 | } |
116 | 120 | }; |
| 121 | + const saveLastConf = (conf) => { |
| 122 | + try { |
| 123 | + fs.writeFileSync(lcnFile, JSON.stringify({ ...conf, name: 'last configuration' })); |
| 124 | + } catch (e) { } |
| 125 | + }; |
117 | 126 | const favText = x => x.name || 'unnamed'; |
118 | 127 | const favDOM = (x) => { |
119 | 128 | const e = document.createElement('div'); |
|
353 | 362 | const go = (conf) => { // "Go" buttons in the favs or the "Go" button at the bottom |
354 | 363 | const x = conf || sel; |
355 | 364 | if (!validate(x)) return 0; |
| 365 | + saveLastConf(x); |
356 | 366 | D.spawned = 0; |
357 | 367 | try { |
358 | 368 | switch (x.type || 'connect') { |
|
588 | 598 | if (fs.existsSync(cnFile)) { |
589 | 599 | D.conns = JSON.parse(fs.readFileSync(cnFile).toString()); |
590 | 600 | D.conns_modified = +fs.statSync(cnFile).mtime; |
591 | | - } else { |
592 | | - fs.writeFileSync(cnFile, JSON.stringify([{ type: 'connect' }])); |
593 | | - D.conns_modified = +fs.statSync(cnFile).mtime; |
| 601 | + } |
| 602 | + if (fs.existsSync(lcnFile)) { |
| 603 | + D.conns = [ |
| 604 | + JSON.parse(fs.readFileSync(lcnFile).toString()), |
| 605 | + ...(D.conns || []) |
| 606 | + ]; |
594 | 607 | } |
595 | 608 | D.conns = D.conns || [{ type: 'connect' }]; |
596 | 609 | I.cn.onkeyup = (x) => { |
|
768 | 781 | .on('click', '.go', (e) => { |
769 | 782 | const t = $(e.target); |
770 | 783 | const i = t.parentsUntil(q.favs).last().index(); |
771 | | - D.prf.connectFav(i); |
772 | 784 | $(q.favs).list('select', i); |
773 | 785 | q.go.click(); |
774 | 786 | }) |
|
946 | 958 | return; |
947 | 959 | } |
948 | 960 | } |
949 | | - setTimeout(() => $(q.favs).list('select', D.prf.connectFav()), 1); |
| 961 | + setTimeout(() => $(q.favs).list('select', 0), 1); |
950 | 962 | }; |
951 | 963 |
|
952 | 964 | module.exports = () => { |
|
0 commit comments