Internal optimizations

This commit is contained in:
Elio Struyf
2024-01-17 14:18:23 +01:00
parent 71ecca3b85
commit d5adc348a2
2 changed files with 31 additions and 22 deletions
+2 -3
View File
@@ -699,9 +699,8 @@ export class ArticleHelper {
* @returns
*/
public static getActiveFile() {
const editors = window.visibleTextEditors;
if (editors.length === 1) {
const editor = editors[0];
const editor = window.activeTextEditor;
if (editor) {
const filePath = parseWinPath(editor.document.uri.fsPath);
if (isValidFile(filePath)) {
return filePath;
+29 -19
View File
@@ -21,6 +21,7 @@ import { unlinkAsync, rmdirAsync } from '../../utils';
export class PagesListener extends BaseListener {
private static watchers: { [path: string]: FileSystemWatcher } = {};
private static watchersPromises: { [path: string]: Promise<void> } = {};
private static lastPages: Page[] = [];
/**
@@ -158,29 +159,38 @@ export class PagesListener extends BaseListener {
* @param file
*/
private static async watcherExec(file: Uri) {
const ext = Extension.getInstance();
Logger.info(`File watcher execution for: ${file.fsPath}`);
const progressFile = async (file: Uri) => {
const ext = Extension.getInstance();
Logger.info(`File watcher execution for: ${file.fsPath}`);
const pageIdx = this.lastPages.findIndex((p) => p.fmFilePath === file.fsPath);
if (pageIdx !== -1) {
const stats = await workspace.fs.stat(file);
const crntPage = this.lastPages[pageIdx];
const updatedPage = await PagesParser.processPageContent(
file.fsPath,
stats.mtime,
basename(file.fsPath),
crntPage.fmFolder
);
if (updatedPage) {
this.lastPages[pageIdx] = updatedPage;
if (Dashboard.isOpen) {
this.sendPageData(this.lastPages);
const pageIdx = this.lastPages.findIndex((p) => p.fmFilePath === file.fsPath);
if (pageIdx !== -1) {
const stats = await workspace.fs.stat(file);
const crntPage = this.lastPages[pageIdx];
const updatedPage = await PagesParser.processPageContent(
file.fsPath,
stats.mtime,
basename(file.fsPath),
crntPage.fmFolder
);
if (updatedPage) {
this.lastPages[pageIdx] = updatedPage;
if (Dashboard.isOpen) {
this.sendPageData(this.lastPages);
}
await ext.setState(ExtensionState.Dashboard.Pages.Cache, this.lastPages, 'workspace');
}
await ext.setState(ExtensionState.Dashboard.Pages.Cache, this.lastPages, 'workspace');
} else {
this.getPagesData(true);
}
} else {
this.getPagesData(true);
};
const watcherPromise = this.watchersPromises[file.fsPath];
if (!watcherPromise) {
this.watchersPromises[file.fsPath] = progressFile(file);
}
await this.watchersPromises[file.fsPath];
delete this.watchersPromises[file.fsPath];
}
/**