refactor: migrate TempDirectoryManager to use vault.adapter exclusively
- Updated TempDirectoryManager to use vault.adapter methods exclusively - Made all temp directory operations async (ensureTempDir, cleanupTempDir, cleanupAllTempDirs) - Removed unnecessary fs fallback since App instance is always available in Obsidian plugins - Updated calling code in PandocTypstConverter and ExportOrchestrator to handle async - Updated PluginLifecycle cleanup methods to use fire-and-forget async pattern - All path operations now use normalizePath for cross-platform compatibility - Simplified interface - App parameter is now required as it should be 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
4 files changed
+62
-55
No files matched your search
@@ -140,8 +140,8 @@ export class ExportOrchestrator {
|
||||
|
||||
try {
|
||||
// Create temp directory for conversion
|
||||
const tempManager = new TempDirectoryManager({ vaultPath: vaultPath, configDir: this.plugin.app.vault.configDir });
|
||||
const tempDir = tempManager.ensureTempDir('pandoc');
|
||||
const tempManager = new TempDirectoryManager({ vaultPath: vaultPath, configDir: this.plugin.app.vault.configDir, app: this.plugin.app });
|
||||
const tempDir = await tempManager.ensureTempDir('pandoc');
|
||||
|
||||
// Load file content
|
||||
const content = await this.plugin.app.vault.read(file);
|
||||
@@ -245,8 +245,8 @@ export class ExportOrchestrator {
|
||||
|
||||
// Clean up temporary directories
|
||||
try {
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||
cleanupManager.cleanupAllTempDirs();
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app);
|
||||
await cleanupManager.cleanupAllTempDirs();
|
||||
} catch (cleanupError) {
|
||||
console.warn('Export: Failed to clean up temporary directories:', cleanupError);
|
||||
}
|
||||
|
||||
@@ -64,31 +64,36 @@ export class PluginLifecycle {
|
||||
this.plugin.currentExportController.abort();
|
||||
}
|
||||
|
||||
// Clean up temp directories on plugin unload
|
||||
try {
|
||||
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||
cleanupManager.cleanupAllTempDirs();
|
||||
} catch (error) {
|
||||
console.warn('Export: Failed to clean up temp directories during unload:', error);
|
||||
}
|
||||
// Clean up temp directories on plugin unload (fire-and-forget async)
|
||||
(async () => {
|
||||
try {
|
||||
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app);
|
||||
await cleanupManager.cleanupAllTempDirs();
|
||||
} catch (error) {
|
||||
console.warn('Export: Failed to clean up temp directories during unload:', error);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up leftover temp directories from previous sessions
|
||||
*/
|
||||
private cleanupStartupTempDirectories(): void {
|
||||
try {
|
||||
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||
const _result = cleanupManager.cleanupAllTempDirs();
|
||||
|
||||
if (this.plugin.settings.behavior.debugMode) {
|
||||
// Debug logging was here but empty in original
|
||||
// Clean up temp directories (fire-and-forget async)
|
||||
(async () => {
|
||||
try {
|
||||
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app);
|
||||
const _result = await cleanupManager.cleanupAllTempDirs();
|
||||
|
||||
if (this.plugin.settings.behavior.debugMode) {
|
||||
// Debug logging was here but empty in original
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Export: Startup temp directory cleanup failed (non-critical):', error);
|
||||
// Don't throw - this shouldn't prevent plugin from loading
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Export: Startup temp directory cleanup failed (non-critical):', error);
|
||||
// Don't throw - this shouldn't prevent plugin from loading
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user