Skip to content

Commit a6db64d

Browse files
authored
replace connectFav with 'last configuration' (#654)
fixes #565
1 parent 4f5500a commit a6db64d

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/cn.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
const WS = /^\s*$/; // KV:regexes for parsing env vars
2424
const maxl = 1000;
2525
const cnFile = `${D.el.app.getPath('userData')}/connections.json`;
26+
const lcnFile = `${D.el.app.getPath('userData')}/last_configuration.json`;
2627
const trunc = x => (x.length > maxl ? `${x.slice(0, maxl - 3)}...` : x);
2728
const shEsc = x => `'${x.replace(/'/g, "'\\''")}'`; // shell escape
2829
const toBuf = (x) => {
@@ -98,13 +99,16 @@
9899
);
99100
return;
100101
}
101-
if (((+fs.statSync(cnFile).mtime) !== D.conns_modified)) {
102+
if (fs.existsSync(cnFile) && ((+fs.statSync(cnFile).mtime) !== D.conns_modified)) {
102103
const r = $.confirm('Connections file has been modified, do you want to overwrite with your changes?');
103104
if (!r) return;
104105
}
105106
const a = q.favs.children;
106107
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+
}
108112
D.conns = b;
109113
try {
110114
fs.writeFileSync(cnFile, JSON.stringify(D.conns));
@@ -114,6 +118,11 @@
114118
toastr.error(`${e.name}: ${e.message}`, 'Save failed');
115119
}
116120
};
121+
const saveLastConf = (conf) => {
122+
try {
123+
fs.writeFileSync(lcnFile, JSON.stringify({ ...conf, name: 'last configuration' }));
124+
} catch (e) { }
125+
};
117126
const favText = x => x.name || 'unnamed';
118127
const favDOM = (x) => {
119128
const e = document.createElement('div');
@@ -353,6 +362,7 @@
353362
const go = (conf) => { // "Go" buttons in the favs or the "Go" button at the bottom
354363
const x = conf || sel;
355364
if (!validate(x)) return 0;
365+
saveLastConf(x);
356366
D.spawned = 0;
357367
try {
358368
switch (x.type || 'connect') {
@@ -588,9 +598,12 @@
588598
if (fs.existsSync(cnFile)) {
589599
D.conns = JSON.parse(fs.readFileSync(cnFile).toString());
590600
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+
];
594607
}
595608
D.conns = D.conns || [{ type: 'connect' }];
596609
I.cn.onkeyup = (x) => {
@@ -768,7 +781,6 @@
768781
.on('click', '.go', (e) => {
769782
const t = $(e.target);
770783
const i = t.parentsUntil(q.favs).last().index();
771-
D.prf.connectFav(i);
772784
$(q.favs).list('select', i);
773785
q.go.click();
774786
})
@@ -946,7 +958,7 @@
946958
return;
947959
}
948960
}
949-
setTimeout(() => $(q.favs).list('select', D.prf.connectFav()), 1);
961+
setTimeout(() => $(q.favs).list('select', 0), 1);
950962
};
951963

952964
module.exports = () => {

src/prf.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ D.prf = {};
1616
['colourScheme', 'Default'], //name of the active colour scheme
1717
['colourSchemes', []],//objects describing user-defined colour schemes
1818
['connectOnQuit', 0], // open connection page when active session ends
19-
['connectFav', 0], // favourite connection (most recently run item)
2019
['floating', 0], //floating editor and tracer windows
2120
['floatSingle', 1], //create single floating edit window
2221
['fold', 1], //code folding

0 commit comments

Comments
 (0)