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

+9 -46
View File
@@ -7,30 +7,20 @@ import {
App, App,
addIcon, addIcon,
Plugin, Plugin,
PluginSettingTab,
Setting,
TFile, TFile,
TFolder, TFolder,
TAbstractFile, TAbstractFile,
Notice, Notice,
Menu, Menu,
MarkdownView, MarkdownView
Editor,
AbstractInputSuggest,
normalizePath
} from 'obsidian'; } from 'obsidian';
import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings'; import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS } from './src/core/settings';
import { FALLBACK_FONTS, PLUGIN_DIRS } from './src/core/constants';
import { DependencyChecker } from './src/core/DependencyChecker'; import { DependencyChecker } from './src/core/DependencyChecker';
import { SecurityUtils } from './src/core/SecurityUtils';
import { ExportErrorHandler } from './src/core/ExportErrorHandler'; import { ExportErrorHandler } from './src/core/ExportErrorHandler';
import { TempDirectoryManager } from './src/core/TempDirectoryManager';
import { PandocTypstConverter } from './src/converters/PandocTypstConverter'; import { PandocTypstConverter } from './src/converters/PandocTypstConverter';
import { MarkdownPreprocessor } from './src/converters/MarkdownPreprocessor';
import { TemplateManager } from './src/templates/TemplateManager'; import { TemplateManager } from './src/templates/TemplateManager';
import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates'; import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates';
import { SUPPORTED_PAPER_SIZES } from './src/utils/paperSizeMapper';
import { PluginLifecycle } from './src/plugin/PluginLifecycle'; import { PluginLifecycle } from './src/plugin/PluginLifecycle';
import { CommandRegistry } from './src/plugin/CommandRegistry'; import { CommandRegistry } from './src/plugin/CommandRegistry';
import { EventHandlers } from './src/plugin/EventHandlers'; import { EventHandlers } from './src/plugin/EventHandlers';
@@ -184,48 +174,21 @@ export class obsidianTypstPDFExport extends Plugin {
* Show dependency status modal * Show dependency status modal
*/ */
async showDependencyStatus(): Promise<void> { async showDependencyStatus(): Promise<void> {
const dependencyResult = await DependencyChecker.checkAllDependencies( return DependencyChecker.showDependencyStatus(
this.settings.pandocPath, this.settings.pandocPath,
this.settings.typstPath, this.settings.typstPath,
this.settings.executablePaths?.imagemagickPath, this.settings.executablePaths?.imagemagickPath,
this.settings.executablePaths?.additionalPaths || [] this.settings.executablePaths?.additionalPaths || []
); );
const formatVersion = (dep: any) => 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)
} }
async checkDependenciesAsync(): Promise<void> { async checkDependenciesAsync(): Promise<void> {
// Check dependencies silently on startup return DependencyChecker.checkDependenciesAsync(
try { this.settings.pandocPath,
const missingDeps = DependencyChecker.checkDependenciesSync( this.settings.typstPath,
this.settings.pandocPath, this.settings.executablePaths?.imagemagickPath,
this.settings.typstPath, this.settings.executablePaths?.additionalPaths || []
this.settings.executablePaths?.imagemagickPath, );
this.settings.executablePaths?.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);
}
} }
/** /**
+63
View File
@@ -2,7 +2,9 @@
* Dependency checking utilities for Obsidian Typst PDF Export plugin * Dependency checking utilities for Obsidian Typst PDF Export plugin
*/ */
import { Notice } from 'obsidian';
import { DEPENDENCY_CONSTANTS } from './constants'; import { DEPENDENCY_CONSTANTS } from './constants';
import { ExportErrorHandler } from './ExportErrorHandler';
export interface DependencyInfo { export interface DependencyInfo {
name: string; name: string;
@@ -317,4 +319,65 @@ export class DependencyChecker {
return missingDeps; 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);
}
}
} }