Skip to content

Commit 5698e11

Browse files
authored
Fix issue with Mobile Login (#204)
Fix issue with Hash checking on Mobile Fix bug when local file deleted. closes #202
1 parent 7f83735 commit 5698e11

13 files changed

+54
-29
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## CHANGELOG
22

3+
### 1.0.41
4+
5+
Fix issue with Mobile Login
6+
Fix issue with Hash checking on Mobile
7+
8+
### 1.0.40
9+
See [New Date/Time handling](https://github.com/thesamim/TickTickSync/wiki/Notable-Changes#changes-from-1036-to-1040----new-datetime-handling) for details.
10+
Slight performance improvement.
11+
312
### 1.0.36
413
Keep forgetting to update the change log. Here's everything since the last update.
514
**Full Changelog**: https://github.com/thesamim/TickTickSync/compare/1.0.20...1.0.36

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Thanks to [LemurTech](https://github.com/LemurTech) and [zarb1n](https://github.
106106

107107
Thanks to [jee-ee](https://github.com/jee-ee) for pointing out the change in Device ID processing.
108108

109+
Thanks to [coneos](https://github.com/coneos) for pointing out the language disparity issue on mobile login.
110+
109111
## Disclaimer
110112

111113
This plugin was built with the author's specific use cases in mind. Additional use cases can and will be considered.

dist/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "tickticksync",
33
"name": "TickTickSync",
4-
"version": "1.0.40",
4+
"version": "1.0.41",
55
"minAppVersion": "1.0.0",
66
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
77
"author": "thesamim",

main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ export default class TickTickSync extends Plugin {
773773
if (!file) {
774774
console.log("File ", fileKey, " was deleted before last sync.");
775775
await this.cacheOperation?.deleteFilepathFromMetadata(fileKey);
776-
const toDelete = newFilesToSync.findIndex(fileKey)
777-
newFilesToSync.splice(toDelete, 1)
776+
delete newFilesToSync[fileKey]
778777
}
779778
}
780779

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "tickticksync",
33
"name": "TickTickSync",
4-
"version": "1.0.40",
4+
"version": "1.0.41",
55
"minAppVersion": "1.0.0",
66
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
77
"author": "thesamim",

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tickticksync",
3-
"version": "1.0.40",
3+
"version": "1.0.41",
44
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
55
"main": "main.js",
66
"scripts": {
@@ -21,13 +21,14 @@
2121
"author": "thesamim",
2222
"license": "GNU GPLv3",
2323
"dependencies": {
24-
"obsidian": "latest",
2524
"@popperjs/core": "2.11.8",
2625
"@types/lowdb": "^1.0.15",
2726
"bson-objectid": "2.0.4",
27+
"crypto-hash": "^3.1.0",
2828
"dependency-tree": "11.0.1",
2929
"lodash-es": "^4.17.21",
30-
"lowdb": "^7.0.1"
30+
"lowdb": "^7.0.1",
31+
"obsidian": "latest"
3132
},
3233
"repository": {
3334
"type": "git",

src/api/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,14 @@ export class Tick {
631631
const headers = {
632632
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0',
633633
'Accept': '*/*',
634-
'Accept-Language': 'en-US,en;q=0.5',
635-
'Accept-Encoding': 'gzip, deflate, br, zstd',
636-
'X-Csrftoken': '',
634+
// 'Accept-Language': 'en-US,en;q=0.5',
635+
// 'Accept-Encoding': 'gzip, deflate, br, zstd',
636+
// 'X-Csrftoken': '',
637637
'x-device': this.deviceAgent,
638638
//"x-device": "{\"platform\":\"web\",\"os\":\"Windows 10\",\"device\":\"Firefox 117.0\",\"name\":\"\",\"version\":124.0.6367.243,\"id\":\"124.0.6367.243\",\"channel\":\"website\",\"campaign\":\"\",\"websocket\":\"\"}",
639639
'Content-Type': 'application/json',
640640
'X-Requested-With': 'XMLHttpRequest',
641-
'Cookie' : this.cookieHeader
641+
// 'Cookie' : this.cookieHeader
642642
};
643643

644644
// console.log('Login headers', headers);

src/cacheOperation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class CacheOperation {
332332

333333
if (!filePath) {
334334
//Not a file that's in fileMetaData, not the inbox no default project set
335-
let errmsg = `File path not found for ${projectId}, returning ${filePath} instead. `
335+
let errmsg = `File path not found for ${projectId}`
336336
console.warn(errmsg)
337337
throw new Error(errmsg);
338338
}
@@ -606,7 +606,7 @@ export class CacheOperation {
606606

607607

608608

609-
async getProjectNameByIdFromCache(projectId: string) {
609+
async getProjectNameByIdFromCache(projectId: string|null) {
610610
try {
611611
const savedProjects = this.plugin.settings.TickTickTasksData.projects
612612
const targetProject = savedProjects.find(obj => obj.id === projectId);

src/dateMan.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ export class DateMan {
243243
dates.completedTime = this.getDateAndTime(task.completedTime, task.isAllDay, date_emoji.completedTime);
244244
}
245245
//Pick up the times that TickTick doesn't care about, but Obsidian does.
246-
if (oldTask) {
247-
if (oldTask.dateHolder.cancelled_date) {
246+
if (oldTask && oldTask.dateHolder) {
247+
if ('cancelled_date' in oldTask.dateHolder && oldTask.dateHolder.cancelled_date) {
248248
dates.cancelled_date = oldTask.dateHolder.cancelled_date;
249249
}
250-
if (oldTask.dateHolder.createdTime) {
250+
if ('createdTime' in oldTask.dateHolder && oldTask.dateHolder.createdTime) {
251251
dates.createdTime = oldTask.dateHolder.createdTime;
252252
}
253253

src/syncModule.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class SyncMan {
206206
let updatedText = await this.updateTaskLine(newTask, lineTxt, editor, cursor, fileContent, line, filePath);
207207

208208
//we want the line as it is in Obsidian.
209-
newTask.lineHash = this.plugin.taskParser?.getLineHash(updatedText);
209+
newTask.lineHash = await this.plugin.taskParser?.getLineHash(updatedText);
210210
//newTask writes to cache
211211
//Will handle meta data there.
212212
await this.plugin.cacheOperation?.appendTaskToCache(newTask, filePath)
@@ -318,7 +318,7 @@ export class SyncMan {
318318
let bHashCheckFailed;
319319
if (this.plugin.taskParser?.hasTickTickId(lineText) && this.plugin.taskParser?.hasTickTickTag(lineText)) {
320320

321-
const newHash = this.plugin.taskParser?.getLineHash(lineText);
321+
const newHash = await this.plugin.taskParser?.getLineHash(lineText);
322322
//convertLineToTask has become a pretty expensive operation avoid it.
323323
//let's see if the saved task has a lineHash.
324324
const lineTask_ticktick_id = this.plugin.taskParser?.getTickTickIdFromLineText(lineText);
@@ -355,7 +355,7 @@ export class SyncMan {
355355
await this.plugin.cacheOperation?.updateTaskToCache(savedTask, null);
356356
}
357357
if (!savedTask.lineHash) {
358-
savedTask.lineHash = this.plugin.taskParser?.getLineHash(lineText);
358+
savedTask.lineHash = await this.plugin.taskParser?.getLineHash(lineText);
359359
}
360360
}
361361

@@ -598,7 +598,7 @@ export class SyncMan {
598598
// from the line in Obsidian. Until I find that corner case, we're just going to reset the line hash here and
599599
// be done.
600600
if (!modified && bHashCheckFailed) {
601-
const updatedHash = this.plugin.taskParser?.getLineHash(lineText)
601+
const updatedHash = await this.plugin.taskParser?.getLineHash(lineText)
602602
lineTask.lineHash = updatedHash;
603603
await this.plugin.cacheOperation?.updateTaskToCache(lineTask, null);
604604
await this.plugin.saveSettings();

src/taskParser.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { App } from 'obsidian';
22
import TickTickSync from '../main';
33
import { ITask } from './api/types/Task';
4+
import {sha256} from 'crypto-hash';
45

56

67
interface dataviewTaskObject {
@@ -757,12 +758,11 @@ export class TaskParser {
757758
// // foo.forEach(tag => console.log(tag));
758759
}
759760

760-
getLineHash(resultLine: string) {
761-
// console.time("Line Hash")
762-
const crypto = require('crypto');
763-
const hash = crypto.createHash("sha256").update(resultLine).digest("hex");
764-
// console.log("TRACETHIS hashing: ", resultLine, hash);
765-
// console.timeEnd("Line Hash")
766-
return hash
761+
async getLineHash(resultLine: string) {
762+
try {
763+
return await sha256(resultLine);
764+
} catch (e) {
765+
console.error("Hashing error.", e);
766+
}
767767
}
768768
}

versions.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"1.0.36": "1.0.0",
3535
"1.0.37": "1.0.0",
3636
"1.0.38": "1.0.0",
37-
"1.0.39": "1.0.0"
38-
"1.0.40": "1.0.0"
37+
"1.0.39": "1.0.0",
38+
"1.0.40": "1.0.0",
39+
"1.0.41": "1.0.0"
3940
}

0 commit comments

Comments
 (0)