Skip to content

Commit

Permalink
refactor: 🔥 Remove refreshIndexInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 22, 2021
1 parent 6134417 commit 3b1309f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 54 deletions.
78 changes: 39 additions & 39 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export class BCSettingTab extends PluginSettingTab {
)
.addToggle((toggle) =>
toggle
.setValue(settings.refreshIndexOnActiveLeafChange)
.setValue(settings.refreshOnNoteChange)
.onChange(async (value) => {
settings.refreshIndexOnActiveLeafChange = value;
settings.refreshOnNoteChange = value;
await plugin.saveSettings();
})
);
Expand Down Expand Up @@ -207,43 +207,43 @@ export class BCSettingTab extends PluginSettingTab {
);
}

new Setting(generalDetails)
.setName("Refresh Interval")
.setDesc(
"Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)"
)
.addText((text) =>
text
.setPlaceholder("Seconds")
.setValue(settings.refreshIntervalTime.toString())
.onChange(async (value) => {
clearInterval(plugin.refreshIntervalID);
const num = Number(value);

if (num > 0) {
settings.refreshIntervalTime = num;
await plugin.saveSettings();

plugin.refreshIntervalID = window.setInterval(async () => {
plugin.mainG = await plugin.initGraphs();
if (settings.showTrail) {
await plugin.drawTrail();
}
const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW);
if (activeMatrix) {
await activeMatrix.draw();
}
}, num * 1000);
plugin.registerInterval(plugin.refreshIntervalID);
} else if (num === 0) {
settings.refreshIntervalTime = num;
await plugin.saveSettings();
clearInterval(plugin.refreshIntervalID);
} else {
new Notice("The interval must be a non-negative number");
}
})
);
// new Setting(generalDetails)
// .setName("Refresh Interval")
// .setDesc(
// "Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)"
// )
// .addText((text) =>
// text
// .setPlaceholder("Seconds")
// .setValue(settings.refreshIntervalTime.toString())
// .onChange(async (value) => {
// clearInterval(plugin.refreshIntervalID);
// const num = Number(value);

// if (num > 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();

// plugin.refreshIntervalID = window.setInterval(async () => {
// plugin.mainG = await plugin.initGraphs();
// if (settings.showTrail) {
// await plugin.drawTrail();
// }
// const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW);
// if (activeMatrix) {
// await activeMatrix.draw();
// }
// }, num * 1000);
// plugin.registerInterval(plugin.refreshIntervalID);
// } else if (num === 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();
// clearInterval(plugin.refreshIntervalID);
// } else {
// new Notice("The interval must be a non-negative number");
// }
// })
// );

const MLViewDetails: HTMLDetailsElement = containerEl.createEl("details");
MLViewDetails.createEl("summary", { text: "Matrix/List View" });
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export const DEFAULT_SETTINGS: BCSettings = {
indexNotes: [""],
hierarchyNotes: [""],
HNUpField: "",
refreshIndexOnActiveLeafChange: false,
refreshOnNoteChange: false,
useAllMetadata: true,
parseJugglLinksWithoutJuggl: false,
refreshIntervalTime: 0,
// refreshIntervalTime: 0,
orderField: "order",
showNameOrType: true,
showRelationType: true,
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface BCSettings {
noPathMessage: string;
orderField: string;
parseJugglLinksWithoutJuggl: boolean;
refreshIndexOnActiveLeafChange: boolean;
refreshIntervalTime: number;
refreshOnNoteChange: boolean;
// refreshIntervalTime: number;
respectReadableLineLength: boolean;
showNameOrType: boolean;
showRelationType: boolean;
Expand Down
21 changes: 10 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class BCPlugin extends Plugin {
this.activeLeafChange = this.app.workspace.on(
"active-leaf-change",
async () => {
if (this.settings.refreshIndexOnActiveLeafChange) {
if (this.settings.refreshOnNoteChange) {
await this.refreshIndex();
} else {
const activeView = this.getActiveTYPEView(MATRIX_VIEW);
Expand All @@ -105,17 +105,16 @@ export default class BCPlugin extends Plugin {

this.registerActiveLeafEvent();

// ANCHOR autorefresh interval
if (settings.refreshIntervalTime > 0) {
this.refreshIntervalID = window.setInterval(async () => {
this.mainG = await this.initGraphs();
if (settings.showBCs) await this.drawTrail();
// if (settings.refreshIntervalTime > 0) {
// this.refreshIntervalID = window.setInterval(async () => {
// this.mainG = await this.initGraphs();
// if (settings.showBCs) await this.drawTrail();

const activeView = this.getActiveTYPEView(MATRIX_VIEW);
if (activeView) await activeView.draw();
}, settings.refreshIntervalTime * 1000);
this.registerInterval(this.refreshIntervalID);
}
// const activeView = this.getActiveTYPEView(MATRIX_VIEW);
// if (activeView) await activeView.draw();
// }, settings.refreshIntervalTime * 1000);
// this.registerInterval(this.refreshIntervalID);
// }
};

async onload(): Promise<void> {
Expand Down

0 comments on commit 3b1309f

Please sign in to comment.