ags: sync

This commit is contained in:
end-4
2024-01-25 22:25:27 +07:00
parent ed24fe4ae3
commit 7e73e24dd8
64 changed files with 2674 additions and 1723 deletions
+13 -11
View File
@@ -32,24 +32,26 @@ class TodoService extends Service {
return this._todoJson;
}
add(content) {
this._todoJson.push({ content, done: false });
_save() {
Utils.writeFile(JSON.stringify(this._todoJson), this._todoPath)
.catch(print);
}
add(content) {
this._todoJson.push({ content, done: false });
this._save();
this.emit('updated');
}
check(index) {
this._todoJson[index].done = true;
Utils.writeFile(JSON.stringify(this._todoJson), this._todoPath)
.catch(print);
this._save();
this.emit('updated');
}
uncheck(index) {
this._todoJson[index].done = false;
Utils.writeFile(JSON.stringify(this._todoJson), this._todoPath)
.catch(print);
this._save();
this.emit('updated');
}
@@ -63,17 +65,17 @@ class TodoService extends Service {
constructor() {
super();
this._todoPath = `${GLib.get_user_cache_dir()}/ags/user/todo.json`;
if (!fileExists(this._todoPath)) { // No? create file with empty array
try {
const fileContents = Utils.readFile(this._todoPath);
this._todoJson = JSON.parse(fileContents);
}
catch {
Utils.exec(`bash -c 'mkdir -p ${GLib.get_user_cache_dir()}/ags/user'`);
Utils.exec(`touch ${this._todoPath}`);
Utils.writeFile("[]", this._todoPath).then(() => {
this._todoJson = JSON.parse(Utils.readFile(this._todoPath))
}).catch(print);
}
else {
const fileContents = Utils.readFile(this._todoPath);
this._todoJson = JSON.parse(fileContents);
}
}
}