Skip to content

Commit

Permalink
Merge pull request #63 from tu2-atmanand/feats-fewSmallFeats
Browse files Browse the repository at this point in the history
Feats few small feats
  • Loading branch information
tu2-atmanand authored Oct 20, 2024
2 parents 672f8fb + d369487 commit 09da327
Show file tree
Hide file tree
Showing 21 changed files with 1,744 additions and 1,559 deletions.
16 changes: 13 additions & 3 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"filters": [],
"filterPolarity": "Allow",
"filterScope": "Both",
"name": "Tag Based Board, updating",
"name": "Tag Based Board",
"index": 2,
"showColumnTags": true,
"showFilteredTags": true
Expand Down Expand Up @@ -259,11 +259,21 @@
"dailyNotesPluginComp": false,
"dueDateFormat": "yyyy-MM-DD",
"taskCompletionInLocalTime": true,
"taskCompletionShowUtcOffset": true,
"taskCompletionShowUtcOffset": false,
"autoAddDue": true,
"scanVaultAtStartup": false,
"dayPlannerPlugin": true,
"realTimeScanning": false
"realTimeScanning": true,
"columnWidth": "300px",
"showHeader": true,
"showFooter": true,
"showVerticalScroll": false,
"tagColors": {
"Test": "#22ee1fef",
"Bug": "#ef1120dd",
"bug/solver": "#22f7de99",
"feat": "#b50df2f2"
}
}
}
}
139 changes: 96 additions & 43 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {
App,
Editor,
MarkdownFileInfo,
MarkdownView,
Modal,
Notice,
Expand All @@ -11,7 +12,10 @@ import {
PluginManifest,
PluginSettingTab,
Setting,
TAbstractFile,
TFile,
WorkspaceLeaf,
requireApiVersion,
} from "obsidian";
import {
DEFAULT_SETTINGS,
Expand All @@ -22,7 +26,7 @@ import {
VIEW_TYPE_TASKBOARD,
} from "src/interfaces/GlobalVariables";
import {
loadTasksRawDisk,
loadTasksJsonFromDiskToSS,
onUnloadSave,
startPeriodicSave,
} from "src/utils/tasksCache";
Expand All @@ -43,6 +47,9 @@ export default class TaskBoard extends Plugin {
realTimeScanning: RealTimeScanning;
fileStack: string[] = [];
scanTimer: number;
editorModified: boolean;
currentModifiedFile: TFile | null;
IsTasksJsonChanged: boolean;

constructor(app: App, menifest: PluginManifest) {
super(app, menifest);
Expand All @@ -52,6 +59,9 @@ export default class TaskBoard extends Plugin {
this.scanTimer = 0;
this.scanningVault = new ScanningVault(this.app, this.plugin);
this.realTimeScanning = new RealTimeScanning(this.app, this.plugin);
this.editorModified = false;
this.currentModifiedFile = null;
this.IsTasksJsonChanged = false;
}

async onload() {
Expand Down Expand Up @@ -129,63 +139,60 @@ export default class TaskBoard extends Plugin {
console.log("MAIN.ts : Loading the setting values : ", this.settings);

// Following line will create a localStorage if the realTimeScanning value is TRUE. And then it will scan the previous files which got left scanning, becaues the Obsidian was closed before that or crashed.
console.log("Creating localStorage ...");
this.realTimeScanning.initializeStack(
this.settings.data.globalSettings.realTimeScanning
);
this.realTimeScanning.processStack();

// Creating Few Events

// this.registerEvent(
// this.app.vault.on("modify", (file: TFile) =>
// this.realTimeScanning.onFileChange(
// file,
// this.settings.data.globalSettings.realTimeScanning,
// this.settings.data.globalSettings.scanFilters
// )
// )
// );
// Register an event for the 'editor-blur' event
// Track if the editor has been modified
let editorModified = false;
// Listen for editor-change event using workspace.trigger
// TODO : Find out which of the below two methods are optized one. I think the first method is the best one.
this.registerEvent(
this.app.workspace.on(
"editor-change",
(editor: CodeMirror.Editor) => {
console.log("EVENT : editor-change event working...");
// Set editorModified to true when any change occurs
editorModified = true;
this.app.vault.on("modify", (file: TAbstractFile) => {
this.editorModified = true;
if (file instanceof TFile) {
this.currentModifiedFile = file;
console.log(
"Modified file is : ",
this.currentModifiedFile
);
}
)
})
);
// this.registerEvent(
// this.app.workspace.on(
// "editor-change",
// (editor: Editor, info: MarkdownView | MarkdownFileInfo) => {
// // console.log("EVENT : editor-change event working...");
// // Set editorModified to true when any change occurs
// this.editorModified = true;
// this.currentModifiedFile =
// this.app.workspace.getActiveFile();
// }
// )
// );
// Listen for editor-blur event and trigger scanning if the editor was modified
this.registerEvent(
this.app.workspace.on(
"active-leaf-change",
(editor: CodeMirror.Editor) => {
// onblur= (this, event: "blur") => {};
// const activeEditor = this.app.workspace.activeEditor?.editor;
// console.log(
// "EVENT : editor-blur event working... | Value of blur : ",
// activeEditor?.focus()
// );
const file = this.app.workspace.getActiveFile();
if (editorModified && file) {
console.log("EVENT : activeEditor.focus() ...");
this.realTimeScanning.onFileChange(
file,
this.settings.data.globalSettings.realTimeScanning,
this.settings.data.globalSettings.scanFilters
);

// Reset the editorModified flag after the scan
editorModified = false;
}
(leaf: WorkspaceLeaf | null) => {
this.onFileModifiedAndLostFocus();
}
)
);
this.registerDomEvent(window, "blur", () => {
console.log(
"User switched away from Obsidian or Obsidian lost focus."
);
this.onFileModifiedAndLostFocus();
});

// window.addEventListener("focus", () => {
// console.log(
// "User switched back to Obsidian or Obsidian gained focus."
// );
// // Trigger your custom code when the app gains focus
// });

this.registerEvent(
this.app.vault.on("create", (file) => {
Expand All @@ -210,15 +217,47 @@ export default class TaskBoard extends Plugin {
})
);

// requireApiVersion("0.15.0")
// ? (activeDocument = activeWindow.document)
// : (activeDocument = window.document);
const closeButton = document.querySelector(
".titlebar-button.mod-close"
);
if (closeButton) {
this.registerDomEvent(
window,
"mouseenter",
() => {
console.log(
"User hovered over the close button. Storing SessionStorage data to Disk."
);
// onUnloadSave(this.plugin);
}
);
}

// Old method :
// const closeButton = document.querySelector(
// ".titlebar-button.mod-close"
// );
// if (closeButton) {
// closeButton.addEventListener("mouseenter", () => {
// console.log(
// "User hovered over the close button. Storing SessionStorage data to Disk."
// );
// onUnloadSave(this.plugin);
// });
// }

// Run scanVaultForTasks if scanVaultAtStartup is true
// TODO : This feature havent been tested. Also the way you are reading the variable scanVaultAtStartup is not correct.
this.settings.data.globalSettings.scanVaultAtStartup
? this.scanningVault.scanVaultForTasks()
: "";

// Load all the tasks from the tasks.json into sessionStorage
const _ = loadTasksRawDisk(this.plugin);
startPeriodicSave(this.plugin);
const _ = loadTasksJsonFromDiskToSS(this.plugin);
// startPeriodicSave(this.plugin);

// Register the Kanban view
this.registerView(
Expand Down Expand Up @@ -252,6 +291,20 @@ export default class TaskBoard extends Plugin {
// });
}

onFileModifiedAndLostFocus() {
if (this.editorModified && this.currentModifiedFile) {
console.log("EVENT : activeEditor.focus() ...");
this.realTimeScanning.onFileChange(
this.currentModifiedFile,
this.settings.data.globalSettings.realTimeScanning,
this.settings.data.globalSettings.scanFilters
);

// Reset the editorModified flag after the scan
this.editorModified = false;
}
}

onunload() {
console.log("TaskBoard : unloading plugin...");
onUnloadSave(this.plugin);
Expand Down
Loading

0 comments on commit 09da327

Please sign in to comment.