fix: address Obsidian Review Bot feedback for plugin submission
- Replace hardcoded '.obsidian' paths with Vault#configDir for proper config directory support - Move inline styles to CSS classes for better theme compatibility - Remove unnecessary type casting by using proper type predicates - Add proper TypeScript type narrowing for filtered arrays This addresses all required issues identified by the Obsidian Review Bot: * TempDirectoryManager now accepts configDir parameter from app.vault.configDir * PdfToImageConverter uses configDir instead of hardcoded '.obsidian' * ExportConfigModal uses CSS classes (.export-progress-visible, .export-form-hidden) instead of inline styles * Progress bar width controlled via CSS custom property --progress-width * Removed 'as TFile[]' casting by implementing isMarkdownFile type predicate 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
6 files changed
+37
-20
No files matched your search
@@ -45,6 +45,11 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
private embeddedTemplateManager: EmbeddedTemplateManager;
|
private embeddedTemplateManager: EmbeddedTemplateManager;
|
||||||
private currentExportController: AbortController | null = null;
|
private currentExportController: AbortController | null = null;
|
||||||
|
|
||||||
|
// Type predicate to filter for markdown TFiles
|
||||||
|
private isMarkdownFile(file: TAbstractFile): file is TFile {
|
||||||
|
return file instanceof TFile && file.extension === 'md';
|
||||||
|
}
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
@@ -278,9 +283,7 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.workspace.on('files-menu', (menu: Menu, files: TAbstractFile[]) => {
|
this.app.workspace.on('files-menu', (menu: Menu, files: TAbstractFile[]) => {
|
||||||
// Filter for markdown files only
|
// Filter for markdown files only
|
||||||
const markdownFiles = files.filter(file =>
|
const markdownFiles = files.filter(this.isMarkdownFile);
|
||||||
file instanceof TFile && file.extension === 'md'
|
|
||||||
) as TFile[];
|
|
||||||
|
|
||||||
if (markdownFiles.length > 0) {
|
if (markdownFiles.length > 0) {
|
||||||
menu.addItem((item) => {
|
menu.addItem((item) => {
|
||||||
@@ -478,7 +481,7 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Create temp directory for conversion
|
// Create temp directory for conversion
|
||||||
const tempManager = new TempDirectoryManager({ vaultPath: vaultPath });
|
const tempManager = new TempDirectoryManager({ vaultPath: vaultPath, configDir: this.app.vault.configDir });
|
||||||
const tempDir = tempManager.ensureTempDir('pandoc');
|
const tempDir = tempManager.ensureTempDir('pandoc');
|
||||||
|
|
||||||
// Load file content
|
// Load file content
|
||||||
@@ -584,7 +587,7 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
|
|
||||||
// Clean up temporary directories
|
// Clean up temporary directories
|
||||||
try {
|
try {
|
||||||
const cleanupManager = TempDirectoryManager.create(vaultPath);
|
const cleanupManager = TempDirectoryManager.create(vaultPath, this.app.vault.configDir);
|
||||||
cleanupManager.cleanupAllTempDirs();
|
cleanupManager.cleanupAllTempDirs();
|
||||||
} catch (cleanupError) {
|
} catch (cleanupError) {
|
||||||
console.warn('Export: Failed to clean up temporary directories:', cleanupError);
|
console.warn('Export: Failed to clean up temporary directories:', cleanupError);
|
||||||
@@ -650,9 +653,7 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
*/
|
*/
|
||||||
private async handleFolderExport(folder: TFolder): Promise<void> {
|
private async handleFolderExport(folder: TFolder): Promise<void> {
|
||||||
// Get all markdown files in the folder
|
// Get all markdown files in the folder
|
||||||
const markdownFiles = folder.children.filter(
|
const markdownFiles = folder.children.filter(this.isMarkdownFile);
|
||||||
(file) => file instanceof TFile && file.extension === 'md'
|
|
||||||
) as TFile[];
|
|
||||||
|
|
||||||
if (markdownFiles.length === 0) {
|
if (markdownFiles.length === 0) {
|
||||||
new Notice('No markdown files found in this folder');
|
new Notice('No markdown files found in this folder');
|
||||||
@@ -1287,7 +1288,7 @@ ${dependencyResult.allAvailable
|
|||||||
private cleanupStartupTempDirectories(): void {
|
private cleanupStartupTempDirectories(): void {
|
||||||
try {
|
try {
|
||||||
const vaultPath = (this.app.vault.adapter as any).basePath;
|
const vaultPath = (this.app.vault.adapter as any).basePath;
|
||||||
const cleanupManager = TempDirectoryManager.create(vaultPath);
|
const cleanupManager = TempDirectoryManager.create(vaultPath, this.app.vault.configDir);
|
||||||
const result = cleanupManager.cleanupAllTempDirs();
|
const result = cleanupManager.cleanupAllTempDirs();
|
||||||
|
|
||||||
if (this.settings.behavior.debugMode) {
|
if (this.settings.behavior.debugMode) {
|
||||||
@@ -1307,7 +1308,7 @@ ${dependencyResult.allAvailable
|
|||||||
// Clean up temp directories on plugin unload
|
// Clean up temp directories on plugin unload
|
||||||
try {
|
try {
|
||||||
const vaultPath = (this.app.vault.adapter as any).basePath;
|
const vaultPath = (this.app.vault.adapter as any).basePath;
|
||||||
const cleanupManager = TempDirectoryManager.create(vaultPath);
|
const cleanupManager = TempDirectoryManager.create(vaultPath, this.app.vault.configDir);
|
||||||
cleanupManager.cleanupAllTempDirs();
|
cleanupManager.cleanupAllTempDirs();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Export: Failed to clean up temp directories during unload:', error);
|
console.warn('Export: Failed to clean up temp directories during unload:', error);
|
||||||
|
|||||||
@@ -250,7 +250,8 @@ export class PandocTypstConverter {
|
|||||||
if (!this.tempDir) {
|
if (!this.tempDir) {
|
||||||
if (this.pandocOptions.vaultBasePath) {
|
if (this.pandocOptions.vaultBasePath) {
|
||||||
// Use TempDirectoryManager for plugin temp directories
|
// Use TempDirectoryManager for plugin temp directories
|
||||||
const tempManager = TempDirectoryManager.create(this.pandocOptions.vaultBasePath);
|
const configDir = this.plugin?.app?.vault?.configDir || '.obsidian';
|
||||||
|
const tempManager = TempDirectoryManager.create(this.pandocOptions.vaultBasePath, configDir);
|
||||||
this.tempDir = tempManager.ensureTempDir('pandoc');
|
this.tempDir = tempManager.ensureTempDir('pandoc');
|
||||||
} else {
|
} else {
|
||||||
// Fallback to system temp if plugin folder not available
|
// Fallback to system temp if plugin folder not available
|
||||||
|
|||||||
@@ -129,11 +129,12 @@ export class PdfToImageConverter {
|
|||||||
|
|
||||||
// Try multiple strategies to find the plugin directory
|
// Try multiple strategies to find the plugin directory
|
||||||
const pluginDirName = this.plugin?.manifest?.dir || 'typst-pdf-export';
|
const pluginDirName = this.plugin?.manifest?.dir || 'typst-pdf-export';
|
||||||
|
const configDir = this.plugin?.app.vault.configDir || '.obsidian';
|
||||||
const possiblePluginDirs = [
|
const possiblePluginDirs = [
|
||||||
// Strategy 1: From process.cwd() if it's in the vault
|
// Strategy 1: From process.cwd() if it's in the vault
|
||||||
path.join(process.cwd(), '.obsidian', 'plugins', pluginDirName),
|
path.join(process.cwd(), configDir, 'plugins', pluginDirName),
|
||||||
// Strategy 2: Assuming we're running from vault root
|
// Strategy 2: Assuming we're running from vault root
|
||||||
path.join('.obsidian', 'plugins', pluginDirName),
|
path.join(configDir, 'plugins', pluginDirName),
|
||||||
// Strategy 3: From vault base path if plugin is available
|
// Strategy 3: From vault base path if plugin is available
|
||||||
...(this.plugin ? [path.join((this.plugin.app.vault.adapter as any).basePath, this.plugin.manifest.dir!)] : [])
|
...(this.plugin ? [path.join((this.plugin.app.vault.adapter as any).basePath, this.plugin.manifest.dir!)] : [])
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { PLUGIN_DIRS } from './constants';
|
|||||||
export interface TempDirectoryOptions {
|
export interface TempDirectoryOptions {
|
||||||
/** Base path for the vault */
|
/** Base path for the vault */
|
||||||
vaultPath: string;
|
vaultPath: string;
|
||||||
|
/** Configuration directory path (from Vault#configDir) */
|
||||||
|
configDir: string;
|
||||||
/** Plugin directory name (defaults to 'typst-pdf-export') */
|
/** Plugin directory name (defaults to 'typst-pdf-export') */
|
||||||
pluginName?: string;
|
pluginName?: string;
|
||||||
}
|
}
|
||||||
@@ -15,10 +17,12 @@ export class TempDirectoryManager {
|
|||||||
private readonly fs = require('fs');
|
private readonly fs = require('fs');
|
||||||
private readonly path = require('path');
|
private readonly path = require('path');
|
||||||
private readonly vaultPath: string;
|
private readonly vaultPath: string;
|
||||||
|
private readonly configDir: string;
|
||||||
private readonly pluginName: string;
|
private readonly pluginName: string;
|
||||||
|
|
||||||
constructor(options: TempDirectoryOptions) {
|
constructor(options: TempDirectoryOptions) {
|
||||||
this.vaultPath = options.vaultPath;
|
this.vaultPath = options.vaultPath;
|
||||||
|
this.configDir = options.configDir;
|
||||||
this.pluginName = options.pluginName || 'typst-pdf-export';
|
this.pluginName = options.pluginName || 'typst-pdf-export';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +30,7 @@ export class TempDirectoryManager {
|
|||||||
* Get the plugin directory path
|
* Get the plugin directory path
|
||||||
*/
|
*/
|
||||||
private getPluginDir(): string {
|
private getPluginDir(): string {
|
||||||
return this.path.join(this.vaultPath, '.obsidian', 'plugins', this.pluginName);
|
return this.path.join(this.vaultPath, this.configDir, 'plugins', this.pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,10 +87,10 @@ export class TempDirectoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static helper to create manager from vault path
|
* Static helper to create manager from vault path and configDir
|
||||||
*/
|
*/
|
||||||
public static create(vaultPath: string, pluginName?: string): TempDirectoryManager {
|
public static create(vaultPath: string, configDir: string, pluginName?: string): TempDirectoryManager {
|
||||||
return new TempDirectoryManager({ vaultPath, pluginName });
|
return new TempDirectoryManager({ vaultPath, configDir, pluginName });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -324,13 +324,13 @@ export class ExportConfigModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private showProgress(message: string, percent: number): void {
|
private showProgress(message: string, percent: number): void {
|
||||||
this.progressContainer.style.display = 'block';
|
this.progressContainer.addClass('export-progress-visible');
|
||||||
this.formContainer.style.display = 'none';
|
this.formContainer.addClass('export-form-hidden');
|
||||||
|
|
||||||
this.progressText.textContent = message;
|
this.progressText.textContent = message;
|
||||||
|
|
||||||
if (percent >= 0) {
|
if (percent >= 0) {
|
||||||
this.progressBar.style.width = `${percent}%`;
|
this.progressBar.style.setProperty('--progress-width', `${percent}%`);
|
||||||
const percentEl = this.progressContainer.querySelector('.export-progress-percent');
|
const percentEl = this.progressContainer.querySelector('.export-progress-percent');
|
||||||
if (percentEl) {
|
if (percentEl) {
|
||||||
percentEl.textContent = `${Math.round(percent)}%`;
|
percentEl.textContent = `${Math.round(percent)}%`;
|
||||||
|
|||||||
+10
@@ -123,4 +123,14 @@
|
|||||||
/* Progress bar styling */
|
/* Progress bar styling */
|
||||||
.export-progress-bar {
|
.export-progress-bar {
|
||||||
transition: width 0.3s ease;
|
transition: width 0.3s ease;
|
||||||
|
width: var(--progress-width, 0%);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Modal display states */
|
||||||
|
.export-progress-visible {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.export-form-hidden {
|
||||||
|
display: none !important;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user