mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 05:39:06 +00:00
Implement sync interval setting and enhance synchronization timer in Khoj plugin
- Added a new setting for users to configure the sync interval in minutes, allowing for more flexible automatic synchronization. - Introduced methods to start and restart the synchronization timer based on the configured interval. - Updated the synchronization logic to use the user-defined interval instead of a fixed 60 minutes. - Improved code readability and organization by refactoring the sync timer logic.
This commit is contained in:
@@ -43,8 +43,8 @@ export default class Khoj extends Plugin {
|
||||
this.app.vault,
|
||||
this.settings,
|
||||
this.settings.lastSync,
|
||||
false, // regenerate = false pour ne synchroniser que les nouvelles modifications
|
||||
true // userTriggered = true pour afficher une notification
|
||||
false,
|
||||
true
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -59,12 +59,32 @@ export default class Khoj extends Plugin {
|
||||
// Add a settings tab so the user can configure khoj
|
||||
this.addSettingTab(new KhojSettingTab(this.app, this));
|
||||
|
||||
// Add scheduled job to update index every 60 minutes
|
||||
// Démarrer le timer de synchronisation
|
||||
this.startSyncTimer();
|
||||
}
|
||||
|
||||
// Méthode pour démarrer le timer de synchronisation
|
||||
private startSyncTimer() {
|
||||
// Nettoyer l'ancien timer s'il existe
|
||||
if (this.indexingTimer) {
|
||||
clearInterval(this.indexingTimer);
|
||||
}
|
||||
|
||||
// Démarrer un nouveau timer avec l'intervalle configuré
|
||||
this.indexingTimer = setInterval(async () => {
|
||||
if (this.settings.autoConfigure) {
|
||||
this.settings.lastSync = await updateContentIndex(this.app.vault, this.settings, this.settings.lastSync);
|
||||
this.settings.lastSync = await updateContentIndex(
|
||||
this.app.vault,
|
||||
this.settings,
|
||||
this.settings.lastSync
|
||||
);
|
||||
}
|
||||
}, 60 * 60 * 1000);
|
||||
}, this.settings.syncInterval * 60 * 1000); // Convertir les minutes en millisecondes
|
||||
}
|
||||
|
||||
// Méthode publique pour redémarrer le timer (appelée depuis les paramètres)
|
||||
public restartSyncTimer() {
|
||||
this.startSyncTimer();
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
@@ -77,7 +97,7 @@ export default class Khoj extends Plugin {
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
this.saveData(this.settings);
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
|
||||
async onunload() {
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface KhojSetting {
|
||||
syncFileType: SyncFileTypes;
|
||||
userInfo: UserInfo | null;
|
||||
syncFolders: string[];
|
||||
syncInterval: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: KhojSetting = {
|
||||
@@ -42,6 +43,7 @@ export const DEFAULT_SETTINGS: KhojSetting = {
|
||||
},
|
||||
userInfo: null,
|
||||
syncFolders: [],
|
||||
syncInterval: 60,
|
||||
}
|
||||
|
||||
export class KhojSettingTab extends PluginSettingTab {
|
||||
@@ -158,6 +160,28 @@ export class KhojSettingTab extends PluginSettingTab {
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
// Add setting for sync interval
|
||||
const syncIntervalValues = [1, 5, 10, 20, 30, 45, 60, 120, 1440];
|
||||
new Setting(containerEl)
|
||||
.setName('Sync Interval')
|
||||
.setDesc('Minutes between automatic synchronizations')
|
||||
.addDropdown(dropdown => dropdown
|
||||
.addOptions(Object.fromEntries(
|
||||
syncIntervalValues.map(value => [
|
||||
value.toString(),
|
||||
value === 1 ? '1 minute' :
|
||||
value === 1440 ? '24 hours' :
|
||||
`${value} minutes`
|
||||
])
|
||||
))
|
||||
.setValue(this.plugin.settings.syncInterval.toString())
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.syncInterval = parseInt(value);
|
||||
await this.plugin.saveSettings();
|
||||
// Redémarrer le timer avec le nouvel intervalle
|
||||
this.plugin.restartSyncTimer();
|
||||
}));
|
||||
|
||||
// Add setting to manage sync folders
|
||||
const syncFoldersContainer = containerEl.createDiv('sync-folders-container');
|
||||
const foldersSetting = new Setting(syncFoldersContainer)
|
||||
|
||||
Reference in New Issue
Block a user