diff --git a/src/main.ts b/src/main.ts index e054a1f..af2cde8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -92,30 +92,29 @@ export default class RustShareVaultSyncPlugin extends Plugin { this.startAutoSync(); } - // File event listeners this.registerEvent(this.app.vault.on('create', (file) => { - if (file instanceof TFile && !shouldIgnorePath(file.path)) { + if (file instanceof TFile && !shouldIgnorePath(file.path, this.app.vault.configDir)) { syncLog.debug('Event: create', file.path); this.syncQueue.add({ path: file.path, type: 'create' }); } })); this.registerEvent(this.app.vault.on('delete', (file) => { - if (file instanceof TFile && !shouldIgnorePath(file.path)) { + if (file instanceof TFile && !shouldIgnorePath(file.path, this.app.vault.configDir)) { syncLog.debug('Event: delete', file.path); this.syncQueue.add({ path: file.path, type: 'delete' }); } })); this.registerEvent(this.app.vault.on('rename', (file, oldPath) => { - if (file instanceof TFile && !shouldIgnorePath(file.path)) { + if (file instanceof TFile && !shouldIgnorePath(file.path, this.app.vault.configDir)) { syncLog.debug('Event: rename', `${oldPath} -> ${file.path}`); this.syncQueue.add({ path: file.path, type: 'rename', oldPath }); } })); this.registerEvent(this.app.vault.on('modify', (file) => { - if (file instanceof TFile && !shouldIgnorePath(file.path)) { + if (file instanceof TFile && !shouldIgnorePath(file.path, this.app.vault.configDir)) { syncLog.debug('Event: modify', file.path); this.syncQueue.add({ path: file.path, type: 'modify' }); } @@ -194,7 +193,7 @@ export default class RustShareVaultSyncPlugin extends Plugin { const maxWaitMs = pairing.expires_in * 1000; while (Date.now() - startTime < maxWaitMs) { - await new Promise(resolve => setTimeout(resolve, 3000)); + await new Promise(resolve => window.setTimeout(resolve, 3000)); const poll = await api.pollDevicePairing(pairing.device_code); diff --git a/src/ui/settings-tab.ts b/src/ui/settings-tab.ts index f960255..a272dbc 100644 --- a/src/ui/settings-tab.ts +++ b/src/ui/settings-tab.ts @@ -14,7 +14,7 @@ export class RustShareVaultSyncSettingTab extends PluginSettingTab { containerEl.empty(); new Setting(containerEl) - .setName('RustShare Vault Sync Settings') + .setName('Vault connection') .setHeading(); // Disclaimer @@ -74,7 +74,7 @@ export class RustShareVaultSyncSettingTab extends PluginSettingTab { })); new Setting(containerEl) - .setName('Advanced Sync Settings') + .setName('Advanced') .setHeading(); new Setting(containerEl) diff --git a/src/utils.ts b/src/utils.ts index 7a5a997..7324362 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -32,7 +32,7 @@ export function formatConflictFileName(originalPath: string, deviceName: string, return `${dir}${name} (RustShare conflicted copy ${safeDeviceName} ${timestamp})${ext}`; } -export function shouldIgnorePath(path: string, configDir = '.obsidian'): boolean { +export function shouldIgnorePath(path: string, configDir: string): boolean { const normalizedConfigDir = configDir.endsWith('/') ? configDir : configDir + '/'; const ignoredPaths = [ normalizedConfigDir, diff --git a/tests/utils.test.ts b/tests/utils.test.ts index e07f196..6d44f19 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -55,35 +55,36 @@ describe('formatConflictFileName', () => { }); describe('shouldIgnorePath', () => { - it('returns true for .obsidian/', () => { - expect(shouldIgnorePath('.obsidian/app.json')).toBe(true); - expect(shouldIgnorePath('.obsidian/')).toBe(true); + it('returns true for configDir/', () => { + expect(shouldIgnorePath('.obsidian/app.json', '.obsidian')).toBe(true); + expect(shouldIgnorePath('.obsidian/', '.obsidian')).toBe(true); + expect(shouldIgnorePath('custom-config/app.json', 'custom-config')).toBe(true); }); it('returns true for .git/', () => { - expect(shouldIgnorePath('.git/config')).toBe(true); - expect(shouldIgnorePath('notes/.git/')).toBe(true); + expect(shouldIgnorePath('.git/config', '.obsidian')).toBe(true); + expect(shouldIgnorePath('notes/.git/', '.obsidian')).toBe(true); }); it('returns true for .DS_Store', () => { - expect(shouldIgnorePath('.DS_Store')).toBe(true); - expect(shouldIgnorePath('folder/.DS_Store')).toBe(true); + expect(shouldIgnorePath('.DS_Store', '.obsidian')).toBe(true); + expect(shouldIgnorePath('folder/.DS_Store', '.obsidian')).toBe(true); }); it('returns true for node_modules/', () => { - expect(shouldIgnorePath('node_modules/')).toBe(true); - expect(shouldIgnorePath('src/node_modules/pkg/')).toBe(true); + expect(shouldIgnorePath('node_modules/', '.obsidian')).toBe(true); + expect(shouldIgnorePath('src/node_modules/pkg/', '.obsidian')).toBe(true); }); it('returns true for Thumbs.db', () => { - expect(shouldIgnorePath('Thumbs.db')).toBe(true); - expect(shouldIgnorePath('images/Thumbs.db')).toBe(true); + expect(shouldIgnorePath('Thumbs.db', '.obsidian')).toBe(true); + expect(shouldIgnorePath('images/Thumbs.db', '.obsidian')).toBe(true); }); it('returns false for normal file paths', () => { - expect(shouldIgnorePath('notes/hello.md')).toBe(false); - expect(shouldIgnorePath('README.md')).toBe(false); - expect(shouldIgnorePath('deep/nested/path/file.txt')).toBe(false); + expect(shouldIgnorePath('notes/hello.md', '.obsidian')).toBe(false); + expect(shouldIgnorePath('README.md', '.obsidian')).toBe(false); + expect(shouldIgnorePath('deep/nested/path/file.txt', '.obsidian')).toBe(false); }); });