Commit 158569e5 authored by ransome1's avatar ransome1
Browse files

Fixed a glitch in write to file function

parent 38bf7348
{ {
"name": "sleek", "name": "sleek",
"productName": "sleek", "productName": "sleek",
"version": "1.1.0-rc.5", "version": "1.1.0-rc.6",
"description": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source", "description": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source", "synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"category": "ProjectManagement", "category": "ProjectManagement",
......
...@@ -47,7 +47,7 @@ function saveFilter(newFilter, oldFilter, category) { ...@@ -47,7 +47,7 @@ function saveFilter(newFilter, oldFilter, category) {
setUserData("selectedFilters", []); setUserData("selectedFilters", []);
//write the data to the file //write the data to the file
// a newline character is added to prevent other todo.txt apps to append new todos to the last line // a newline character is added to prevent other todo.txt apps to append new todos to the last line
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
// trigger matomo event // trigger matomo event
if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter renamed"]); if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter renamed"]);
return Promise.resolve("Success: Filter renamed"); return Promise.resolve("Success: Filter renamed");
...@@ -71,7 +71,7 @@ function deleteFilter(filter, category) { ...@@ -71,7 +71,7 @@ function deleteFilter(filter, category) {
setUserData("selectedFilters", []); setUserData("selectedFilters", []);
//write the data to the file //write the data to the file
// a newline character is added to prevent other todo.txt apps to append new todos to the last line // a newline character is added to prevent other todo.txt apps to append new todos to the last line
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
// trigger matomo event // trigger matomo event
if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter deleted"]); if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter deleted"]);
return Promise.resolve("Success: Filter deleted"); return Promise.resolve("Success: Filter deleted");
......
"use strict"; "use strict";
import { userData } from "../render.js"; import { userData, getActiveFile } from "../render.js";
import { items } from "./todos.mjs"; import { items } from "./todos.mjs";
import { convertDate } from "./date.mjs"; import { convertDate } from "./date.mjs";
...@@ -40,7 +40,7 @@ function generateRecurrence(todo) { ...@@ -40,7 +40,7 @@ function generateRecurrence(todo) {
recurringTodo.complete = false; recurringTodo.complete = false;
recurringTodo.completed = null; recurringTodo.completed = null;
// adjust due and threshold dates // adjust due and threshold dates
let recSplit = splitRecurrence(todo.rec); let recSplit = splitRecurrence(todo.rec);
if (recSplit.plus) { if (recSplit.plus) {
// strict recurrence is based on previous date value // strict recurrence is based on previous date value
...@@ -81,9 +81,8 @@ function generateRecurrence(todo) { ...@@ -81,9 +81,8 @@ function generateRecurrence(todo) {
// only add recurring todo if it is not already in the list // only add recurring todo if it is not already in the list
if(index===-1) { if(index===-1) {
items.objects.push(recurringTodo); items.objects.push(recurringTodo);
//tableContainerDue.appendChild(generateTableRow(recurringTodo)); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); return Promise.resolve("Success: Recurring todo created and written into file: " + getActiveFile());
return Promise.resolve("Success: Recurring todo created and written into file: " + recurringTodo);
} else { } else {
return Promise.resolve("Info: Recurring todo already in file, won't write anything"); return Promise.resolve("Info: Recurring todo already in file, won't write anything");
} }
......
"use strict"; "use strict";
import "../../node_modules/jstodotxt/jsTodoExtensions.js"; import "../../node_modules/jstodotxt/jsTodoExtensions.js";
import { userData, appData, handleError, translations, setUserData, startBuilding, getConfirmation, resetModal } from "../render.js"; import { getActiveFile, userData, appData, handleError, translations, setUserData, startBuilding, getConfirmation, resetModal } from "../render.js";
import { _paq } from "./matomo.mjs"; import { _paq } from "./matomo.mjs";
import { categories } from "./filters.mjs"; import { categories } from "./filters.mjs";
import { generateRecurrence } from "./recurrences.mjs"; import { generateRecurrence } from "./recurrences.mjs";
...@@ -477,8 +477,8 @@ function setTodoComplete(todo) { ...@@ -477,8 +477,8 @@ function setTodoComplete(todo) {
if(todo.rec) generateRecurrence(todo) if(todo.rec) generateRecurrence(todo)
} }
//write the data to the file //write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: Changes written to file: " + userData.file); return Promise.resolve("Success: Changes written to file: " + getActiveFile());
} catch(error) { } catch(error) {
error.functionName = setTodoComplete.name; error.functionName = setTodoComplete.name;
return Promise.reject(error); return Promise.reject(error);
...@@ -506,8 +506,8 @@ function setTodoDelete(todo) { ...@@ -506,8 +506,8 @@ function setTodoDelete(todo) {
} }
items.objects.splice(index, 1); items.objects.splice(index, 1);
//write the data to the file //write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: Changes written to file: " + userData.file); return Promise.resolve("Success: Changes written to file: " + getActiveFile());
} catch(error) { } catch(error) {
error.functionName = setTodoDelete.name; error.functionName = setTodoDelete.name;
return Promise.reject(error); return Promise.reject(error);
...@@ -527,8 +527,8 @@ function addTodo(todo) { ...@@ -527,8 +527,8 @@ function addTodo(todo) {
items.objects.push(todo); items.objects.push(todo);
//write the data to the file //write the data to the file
// a newline character is added to prevent other todo.txt apps to append new todos to the last line // a newline character is added to prevent other todo.txt apps to append new todos to the last line
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]); window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: New todo added to file: " + userData.file); return Promise.resolve("Success: New todo added to file: " + getActiveFile());
} else { } else {
return Promise.resolve("Info: Todo already in file, nothing will be written"); return Promise.resolve("Info: Todo already in file, nothing will be written");
} }
......
...@@ -777,6 +777,12 @@ async function startBuilding(append, loadAll) { ...@@ -777,6 +777,12 @@ async function startBuilding(append, loadAll) {
} }
} }
function getActiveFile() {
const index = userData.files.findIndex(file => file[0] === 1);
const file = userData.files[index][1];
return file;
}
window.onload = async function () { window.onload = async function () {
a0 = performance.now(); a0 = performance.now();
userData = await getUserData(); userData = await getUserData();
...@@ -787,9 +793,8 @@ window.onload = async function () { ...@@ -787,9 +793,8 @@ window.onload = async function () {
drawer = await import("./js/drawer.mjs"); drawer = await import("./js/drawer.mjs");
files = await import("./js/files.mjs"); files = await import("./js/files.mjs");
//TODO: Refactoring //TODO: Refactoring
if(userData.files) { if(userData.files && userData.files.length > 0) {
const index = userData.files.findIndex(file => file[0] ===1 ); window.api.send("startFileWatcher", [getActiveFile(), 0]);
window.api.send("startFileWatcher", [userData.files[index][1], 0]);
} else { } else {
showOnboarding(true).then(function(response) { showOnboarding(true).then(function(response) {
console.info(response); console.info(response);
...@@ -916,4 +921,4 @@ window.api.receive("refresh", async (args) => { ...@@ -916,4 +921,4 @@ window.api.receive("refresh", async (args) => {
}); });
}); });
export { showOnboarding, resetFilters, resetModal, setUserData, startBuilding, handleError, userData, appData, translations, modal, setTheme, getConfirmation }; export { getActiveFile, showOnboarding, resetFilters, resetModal, setUserData, startBuilding, handleError, userData, appData, translations, modal, setTheme, getConfirmation };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment