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

Fixed a glitch in write to file function

parent 38bf7348
{
"name": "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",
"synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"category": "ProjectManagement",
......
......@@ -47,7 +47,7 @@ function saveFilter(newFilter, oldFilter, category) {
setUserData("selectedFilters", []);
//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
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
if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter renamed"]);
return Promise.resolve("Success: Filter renamed");
......@@ -71,7 +71,7 @@ function deleteFilter(filter, category) {
setUserData("selectedFilters", []);
//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
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
if(userData.matomoEvents) _paq.push(["trackEvent", "Filter-Drawer", "Filter deleted"]);
return Promise.resolve("Success: Filter deleted");
......
"use strict";
import { userData } from "../render.js";
import { userData, getActiveFile } from "../render.js";
import { items } from "./todos.mjs";
import { convertDate } from "./date.mjs";
......@@ -40,7 +40,7 @@ function generateRecurrence(todo) {
recurringTodo.complete = false;
recurringTodo.completed = null;
// adjust due and threshold dates
// adjust due and threshold dates
let recSplit = splitRecurrence(todo.rec);
if (recSplit.plus) {
// strict recurrence is based on previous date value
......@@ -81,9 +81,8 @@ function generateRecurrence(todo) {
// only add recurring todo if it is not already in the list
if(index===-1) {
items.objects.push(recurringTodo);
//tableContainerDue.appendChild(generateTableRow(recurringTodo));
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]);
return Promise.resolve("Success: Recurring todo created and written into file: " + recurringTodo);
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: Recurring todo created and written into file: " + getActiveFile());
} else {
return Promise.resolve("Info: Recurring todo already in file, won't write anything");
}
......
"use strict";
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 { categories } from "./filters.mjs";
import { generateRecurrence } from "./recurrences.mjs";
......@@ -477,8 +477,8 @@ function setTodoComplete(todo) {
if(todo.rec) generateRecurrence(todo)
}
//write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]);
return Promise.resolve("Success: Changes written to file: " + userData.file);
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: Changes written to file: " + getActiveFile());
} catch(error) {
error.functionName = setTodoComplete.name;
return Promise.reject(error);
......@@ -506,8 +506,8 @@ function setTodoDelete(todo) {
}
items.objects.splice(index, 1);
//write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]);
return Promise.resolve("Success: Changes written to file: " + userData.file);
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: Changes written to file: " + getActiveFile());
} catch(error) {
error.functionName = setTodoDelete.name;
return Promise.reject(error);
......@@ -527,8 +527,8 @@ function addTodo(todo) {
items.objects.push(todo);
//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
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n", userData.file]);
return Promise.resolve("Success: New todo added to file: " + userData.file);
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
return Promise.resolve("Success: New todo added to file: " + getActiveFile());
} else {
return Promise.resolve("Info: Todo already in file, nothing will be written");
}
......
......@@ -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 () {
a0 = performance.now();
userData = await getUserData();
......@@ -787,9 +793,8 @@ window.onload = async function () {
drawer = await import("./js/drawer.mjs");
files = await import("./js/files.mjs");
//TODO: Refactoring
if(userData.files) {
const index = userData.files.findIndex(file => file[0] ===1 );
window.api.send("startFileWatcher", [userData.files[index][1], 0]);
if(userData.files && userData.files.length > 0) {
window.api.send("startFileWatcher", [getActiveFile(), 0]);
} else {
showOnboarding(true).then(function(response) {
console.info(response);
......@@ -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