fix: fixed button bypass of exclusion rules

This commit is contained in:
Al0cam 2025-04-14 11:24:29 +02:00
parent fca87af73e
commit b347b1fd7d
3 changed files with 22 additions and 26 deletions

View file

@ -4,20 +4,16 @@ import type { MovingRule } from "Models/MovingRule";
export interface AutoMoverSettings {
moveOnOpen: boolean;
moveOnSave: boolean;
moveOnClose: boolean;
moveOnCreate: boolean;
// moveOnSave: boolean;
movingRules: MovingRule[];
excludedFolders: ExclusionRule[];
exclusionRules: ExclusionRule[];
}
export const DEFAULT_SETTINGS: Partial<AutoMoverSettings> = {
moveOnOpen: true,
moveOnSave: true,
moveOnClose: false,
moveOnCreate: false,
// moveOnSave: true,
movingRules: [],
excludedFolders: [],
exclusionRules: [],
};
function loadSettings(

View file

@ -182,14 +182,14 @@ export class SettingsTab extends obsidian.PluginSettingTab {
/**
* Header for excluded folders
*/
const excludedFoldersContainer = containerEl.createDiv({
const exclusionRuleContainer = containerEl.createDiv({
cls: "moving_rules_container",
});
new obsidian.Setting(excludedFoldersContainer)
new obsidian.Setting(exclusionRuleContainer)
.setName("Exclusion rules")
.setHeading();
const exclusionList = excludedFoldersContainer.createDiv({
const exclusionList = exclusionRuleContainer.createDiv({
cls: "rule_list",
});
const exclusionHeader = exclusionList.createDiv({
@ -205,21 +205,21 @@ export class SettingsTab extends obsidian.PluginSettingTab {
cls: "rule_button",
});
addExclusionButton.addEventListener("click", () => {
this.plugin.settings.excludedFolders.push(new ExclusionRule());
this.plugin.settings.exclusionRules.push(new ExclusionRule());
this.display();
});
/**
* List of excluded folders
*/
for (const exclusion of this.plugin.settings.excludedFolders) {
for (const exclusion of this.plugin.settings.exclusionRules) {
const child = exclusionList.createDiv({ cls: "rule" });
child.createEl("input", {
value: exclusion.regex,
cls: "rule_input",
}).onchange = (e) => {
exclusion.regex = (e.target as HTMLInputElement).value;
this.plugin.settings.excludedFolders.map((ef) =>
this.plugin.settings.exclusionRules.map((ef) =>
ef === exclusion ? exclusion : ef,
);
this.plugin.saveData(this.plugin.settings);
@ -230,7 +230,7 @@ export class SettingsTab extends obsidian.PluginSettingTab {
cls: "rule_button rule_button_duplicate",
});
duplicateExclusionButton.addEventListener("click", () => {
this.plugin.settings.excludedFolders.push(
this.plugin.settings.exclusionRules.push(
new ExclusionRule(exclusion.regex),
);
this.display();
@ -241,8 +241,8 @@ export class SettingsTab extends obsidian.PluginSettingTab {
cls: "rule_button rule_button_remove",
});
deleteExclusionButton.addEventListener("click", () => {
this.plugin.settings.excludedFolders =
this.plugin.settings.excludedFolders.filter((r) => r !== exclusion);
this.plugin.settings.exclusionRules =
this.plugin.settings.exclusionRules.filter((r) => r !== exclusion);
this.display();
});
}

18
main.ts
View file

@ -45,6 +45,10 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
goThroughAllFiles() {
const files = this.app.vault.getFiles();
for (const file of files) {
if (file == null || file.path == null) continue;
console.log("Going through file: ", file.path);
console.log("File excluded: ", this.isFileExcluded(file));
if (this.isFileExcluded(file)) continue;
this.matchAndMoveFile(file);
}
new obsidian.Notice("All files moved!", 5000);
@ -62,7 +66,7 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
return exclusionMatcherUtil.isFilePathExcluded(
file,
this.settings.excludedFolders,
this.settings.exclusionRules,
);
}
@ -108,12 +112,8 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
* @returns boolean
*/
areMovingTriggersEnabled(): boolean {
return (
this.settings.moveOnClose ||
this.settings.moveOnCreate ||
this.settings.moveOnOpen ||
this.settings.moveOnSave
);
return this.settings.moveOnOpen;
// || this.settings.moveOnSave
}
/**
@ -134,7 +134,7 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
* @returns boolean
*/
areThereExcludedFolders(): boolean {
return this.settings.excludedFolders.length > 0;
return this.settings.exclusionRules.length > 0;
}
/**
@ -152,6 +152,6 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
* @returns boolean
*/
areExcludedFoldersValid(): boolean {
return this.settings.excludedFolders.every((rule) => rule.regex !== "");
return this.settings.exclusionRules.every((rule) => rule.regex !== "");
}
}