mirror of
https://github.com/heroblackink/ultimate-todoist-sync-for-obsidian.git
synced 2026-07-22 07:40:27 +00:00
增加了projects 手动同步按钮
This commit is contained in:
parent
9ce479b999
commit
a98d80f87c
3 changed files with 55 additions and 3 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"id": "ultimate-todoist-sync-for-obsidian",
|
||||
"name": "Ultimate Todoist Sync for Obsidian",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.15.0",
|
||||
"minAppVersion": "1.0.0",
|
||||
"description": "This is the best Todoist task synchronization plugin for Obsidian so far.",
|
||||
"author": "Obsidian",
|
||||
"authorUrl": "https://obsidian.md",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
||||
import { App, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
||||
|
||||
|
||||
export interface MyPluginSettings {
|
||||
|
|
@ -50,6 +50,25 @@ export class SampleSettingTab extends PluginSettingTab {
|
|||
})
|
||||
);
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Sync Projects')
|
||||
.setDesc('When there are changes in Todoist projects, please click this button to manually synchronize.')
|
||||
.addButton(button => button
|
||||
.setButtonText('Sync projects')
|
||||
.onClick(() => {
|
||||
// Add code here to handle exporting Todoist data
|
||||
try{
|
||||
this.plugin.cacheOperation.saveProjectsToCache()
|
||||
this.plugin.saveSettings()
|
||||
new Notice(`projects synchronization successful`)
|
||||
}catch(error){
|
||||
new Notice(`projects synchronization failed:${error}`)
|
||||
}
|
||||
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Backup Todoist Data')
|
||||
.setDesc('Click to backup Todoist data, backup data is saved in the path ".obsidian/plugins/ultimate-todoist-sync-for-obsidian/userData"')
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export class TodoistSyncAPI {
|
|||
console.error(error);
|
||||
throw new Error('Failed to fetch completed items due to network error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -206,6 +206,39 @@ export class TodoistSyncAPI {
|
|||
const filteredArray = updatedItemsActivityEvents.filter(obj => !obj.extra_data.client.includes("obsidian"));
|
||||
return(filteredArray)
|
||||
}
|
||||
|
||||
|
||||
//get completed items activity
|
||||
//result {count:number,events:[]}
|
||||
async getProjectsActivity() {
|
||||
const accessToken = this.settings.todoistAPIToken
|
||||
const url = 'https://api.todoist.com/sync/v9/activity/get';
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
'object_type': 'project'
|
||||
})
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch projects activities: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw new Error('Failed to fetch projects activities due to network error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue