From 3c384f1f1b2011738c656dd1d9cad7c1eb6afcfa Mon Sep 17 00:00:00 2001 From: Jarvis Date: Tue, 9 Sep 2025 10:23:22 +0200 Subject: [PATCH] refactor(main): move dependency methods to DependencyChecker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- main.ts | 55 +++++------------------------- src/core/DependencyChecker.ts | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/main.ts b/main.ts index 2ec16af..2f814f6 100644 --- a/main.ts +++ b/main.ts @@ -7,30 +7,20 @@ import { App, addIcon, Plugin, - PluginSettingTab, - Setting, TFile, TFolder, TAbstractFile, Notice, Menu, - MarkdownView, - Editor, - AbstractInputSuggest, - normalizePath + MarkdownView } from 'obsidian'; -import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings'; -import { FALLBACK_FONTS, PLUGIN_DIRS } from './src/core/constants'; +import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS } from './src/core/settings'; import { DependencyChecker } from './src/core/DependencyChecker'; -import { SecurityUtils } from './src/core/SecurityUtils'; import { ExportErrorHandler } from './src/core/ExportErrorHandler'; -import { TempDirectoryManager } from './src/core/TempDirectoryManager'; import { PandocTypstConverter } from './src/converters/PandocTypstConverter'; -import { MarkdownPreprocessor } from './src/converters/MarkdownPreprocessor'; import { TemplateManager } from './src/templates/TemplateManager'; import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates'; -import { SUPPORTED_PAPER_SIZES } from './src/utils/paperSizeMapper'; import { PluginLifecycle } from './src/plugin/PluginLifecycle'; import { CommandRegistry } from './src/plugin/CommandRegistry'; import { EventHandlers } from './src/plugin/EventHandlers'; @@ -184,48 +174,21 @@ export class obsidianTypstPDFExport extends Plugin { * Show dependency status modal */ async showDependencyStatus(): Promise { - const dependencyResult = await DependencyChecker.checkAllDependencies( + return DependencyChecker.showDependencyStatus( this.settings.pandocPath, this.settings.typstPath, this.settings.executablePaths?.imagemagickPath, 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 { - // Check dependencies silently on startup - try { - const missingDeps = DependencyChecker.checkDependenciesSync( - this.settings.pandocPath, - this.settings.typstPath, - 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); - } + return DependencyChecker.checkDependenciesAsync( + this.settings.pandocPath, + this.settings.typstPath, + this.settings.executablePaths?.imagemagickPath, + this.settings.executablePaths?.additionalPaths || [] + ); } /** diff --git a/src/core/DependencyChecker.ts b/src/core/DependencyChecker.ts index 398d6b7..051e465 100644 --- a/src/core/DependencyChecker.ts +++ b/src/core/DependencyChecker.ts @@ -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 { + 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 { + // 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); + } + } } \ No newline at end of file