From 7d551915bf4832a4cfa78473d79c04d95d246eb0 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Jul 2023 18:09:04 +0200 Subject: [PATCH 1/6] changed in node tool added: filter on notes title added: put modified note on top --- tools/nodeclient/app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index aa8bccb..e301632 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -9,6 +9,7 @@ var rl = readline.createInterface({ }); var settings = JSON.parse(fs.readFileSync("settings.json", { encoding: "utf8", flag: "r" })); +var filter = process.argv.length > 2 ? process.argv[2] : ""; axios.post(`${settings.url}/handler.php`, { @@ -24,7 +25,10 @@ axios.post(`${settings.url}/handler.php`, .then(res => { var notes = res.data; - notes.every( (note, i) => + + notes + .filter(n => n.title.includes(filter)) + .every( (note, i) => { console.log(`[${i}] ${note.title}`) return i < settings.maxcount; @@ -33,7 +37,7 @@ axios.post(`${settings.url}/handler.php`, rl.prompt(); rl.on("line", (line) => { - var note = notes[line] + var note = notes.filter(n => n.title.includes(filter))[line]; fs.writeFileSync("note.md", note.content); @@ -44,6 +48,10 @@ axios.post(`${settings.url}/handler.php`, if (note.content != newcontent) { note.content = newcontent; + + notes.splice(notes.indexOf(note), 1); + notes.unshift(note); + axios.post(`${settings.url}/handler.php`, { action: "push", From 9ca9083c45474f4ce923881b59de39bec7dbd2b6 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Jul 2023 18:16:51 +0200 Subject: [PATCH 2/6] added: logs in node app --- tools/nodeclient/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index e301632..1c16854 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -52,6 +52,7 @@ axios.post(`${settings.url}/handler.php`, notes.splice(notes.indexOf(note), 1); notes.unshift(note); + console.log("sending data file to server..."); axios.post(`${settings.url}/handler.php`, { action: "push", @@ -63,8 +64,14 @@ axios.post(`${settings.url}/handler.php`, { "Content-type": "application/x-www-form-urlencoded" } + }).then(res => { + console.log("done."); }); } + else + { + console.log("no change."); + } }) rl.close(); }); From 1b73d010433a48081661696e6af75fbf6d309f5f Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Jul 2023 18:24:30 +0200 Subject: [PATCH 3/6] node tool: editor in settings --- tools/nodeclient/app.js | 2 +- tools/nodeclient/settings.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index 1c16854..a664167 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -41,7 +41,7 @@ axios.post(`${settings.url}/handler.php`, fs.writeFileSync("note.md", note.content); - cp.exec("sublime_text.exe -w note.md", function (err, stdout, stderr) + cp.exec(`${settings.command} note.md`, function (err, stdout, stderr) { var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); diff --git a/tools/nodeclient/settings.json b/tools/nodeclient/settings.json index f2f3f5c..01c787c 100644 --- a/tools/nodeclient/settings.json +++ b/tools/nodeclient/settings.json @@ -2,4 +2,6 @@ "password": "", "url": "http://localhost:8000", "maxcount": 50 + "maxcount": 50, + "command": "sublime_text.exe -w" } From 477365d56e567c904fbf3fe22f4c899ca981c741 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 12 Jul 2023 16:28:21 +0200 Subject: [PATCH 4/6] fixed: handle middle word underscores --- main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main.js b/main.js index cf9b3d1..30ea86e 100644 --- a/main.js +++ b/main.js @@ -1538,6 +1538,7 @@ function md2html(content) converter.setOption("simpleLineBreaks", true); converter.setOption("metadata", true); converter.setOption("tasklists", true); + converter.setOption("literalMidWordUnderscores", true); if (settings.linksinnewtab) { From 961ec84588852b0cadb034834e4928adec90e7f4 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 12 Jul 2023 18:07:32 +0200 Subject: [PATCH 5/6] node client: autosave every 10 seconds --- tools/nodeclient/app.js | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index a664167..c4312ba 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -10,6 +10,14 @@ var rl = readline.createInterface({ var settings = JSON.parse(fs.readFileSync("settings.json", { encoding: "utf8", flag: "r" })); var filter = process.argv.length > 2 ? process.argv[2] : ""; +var intervalid = null; +var notes = null; + +function filteredlist() +{ + return notes + .filter(n => n.title.toLowerCase().includes(filter.toLowerCase())); +} axios.post(`${settings.url}/handler.php`, { @@ -24,27 +32,28 @@ axios.post(`${settings.url}/handler.php`, }) .then(res => { - var notes = res.data; + notes = res.data; - notes - .filter(n => n.title.includes(filter)) + filteredlist() .every( (note, i) => { console.log(`[${i}] ${note.title}`) return i < settings.maxcount; }); + // todo: open if only one match. quit if no match rl.prompt(); rl.on("line", (line) => { - var note = notes.filter(n => n.title.includes(filter))[line]; + var note = filteredlist()[line]; + // todo: use title instead? To put in data folder? fs.writeFileSync("note.md", note.content); cp.exec(`${settings.command} note.md`, function (err, stdout, stderr) { + clearInterval(intervalid); var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); - if (note.content != newcontent) { note.content = newcontent; @@ -73,6 +82,36 @@ axios.post(`${settings.url}/handler.php`, console.log("no change."); } }) + + intervalid = setInterval(function() + { + //todo: refactor "save" + var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); + if (note.content != newcontent) + { + note.content = newcontent; + + notes.splice(notes.indexOf(note), 1); + notes.unshift(note); + + console.log("sending data file to server..."); + axios.post(`${settings.url}/handler.php`, + { + action: "push", + password: settings.password, + data: JSON.stringify(notes) + }, + { + headers: + { + "Content-type": "application/x-www-form-urlencoded" + } + }).then(res => { + console.log("done."); + }); + } + }, 10000); + rl.close(); }); }); From 575a47ce5090c637385791bca883ec91a2590389 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 12 Jul 2023 18:27:19 +0200 Subject: [PATCH 6/6] fixed: default font size --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 30ea86e..6e62e84 100644 --- a/main.js +++ b/main.js @@ -77,7 +77,7 @@ var themes = { bgcolor: "white", fontfamily: "'Inconsolata', 'Consolas', monospace", - fontsize: "90%", + fontsize: "16px", fontcolor: "black", lineheight: "130%", accentcolor: "#5AA7CE"