refactor(main): move dependency methods to DependencyChecker

- Move showDependencyStatus() and checkDependenciesAsync() from main.ts to DependencyChecker.ts as static methods
- Replace 31-line implementations with 12-line delegation calls in main.ts
- Add necessary imports (Notice, ExportErrorHandler) to DependencyChecker.ts
- Maintain same public API while improving separation of concerns
- Reduce main.ts from 280 to 253 lines (total 79% reduction from original 1233 lines)

This completes Step 1.10 of the refactoring plan, achieving clean delegation
of dependency management functionality while preserving backward compatibility.

Build verified: ✅ TypeScript compilation successful
This commit is contained in:
Jarvis committed 2025-09-09 10:23:22 +02:00
1 parent 9427444015
commit 3c384f1f1b
2 files changed
+72 -46

No files matched your search

+63
View File
@@ -2,7 +2,9 @@
* Dependency checking utilities for Obsidian Typst PDF Export plugin
*/
import { Notice } from 'obsidian';
import { DEPENDENCY_CONSTANTS } from './constants';
import { ExportErrorHandler } from './ExportErrorHandler';
export interface DependencyInfo {
name: string;
@@ -317,4 +319,65 @@ export class DependencyChecker {
return missingDeps;
}
/**
* Show dependency status modal
*/
public static async showDependencyStatus(
pandocPath?: string,
typstPath?: string,
imagemagickPath?: string,
additionalPaths: string[] = []
): Promise<void> {
const dependencyResult = await this.checkAllDependencies(
pandocPath,
typstPath,
imagemagickPath,
additionalPaths
);
const formatVersion = (dep: DependencyInfo) => dep.isAvailable ? (dep.version || 'Available') : 'Not found';
const message = `Dependency Status:
Pandoc: ${formatVersion(dependencyResult.pandoc)}
Typst: ${formatVersion(dependencyResult.typst)}
ImageMagick: ${formatVersion(dependencyResult.imagemagick)}
${dependencyResult.allAvailable
? 'All dependencies found!'
: `Missing dependencies: ${dependencyResult.missingDependencies.join(', ')}. Please install them and check the paths in settings.`}`;
new Notice(message, 12000); // Show for 12 seconds (longer due to more content)
}
/**
* Check dependencies silently on startup and show notice if missing
*/
public static async checkDependenciesAsync(
pandocPath?: string,
typstPath?: string,
imagemagickPath?: string,
additionalPaths: string[] = []
): Promise<void> {
// Check dependencies silently on startup
try {
const missingDeps = this.checkDependenciesSync(
pandocPath,
typstPath,
imagemagickPath,
additionalPaths
);
// Only show notice if dependencies are missing
if (missingDeps.length > 0) {
new Notice(
`Typst PDF Export: Missing dependencies: ${missingDeps.join(', ')}. ` +
`Run "Check Dependencies" command for details.`,
8000
);
}
} catch (error) {
ExportErrorHandler.handleDependencyError('Dependencies', error, false);
}
}
}