feat: add backup file management settings
- Added settings UI to enable/disable .bak file creation when saving files - Created settings storage in .obsidian/obsiviewer.json to persist backup preferences - Added API endpoints to read/write backup settings (/api/settings) - Implemented automatic cleanup of existing .bak files when disabling backups - Modified file save operations to respect backup setting across notes, bookmarks and graph files - Removed existing .bak files from version control
This commit is contained in:
@@ -112,6 +112,34 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Backups Section -->
|
||||
<section class="parameters-section">
|
||||
<h2 class="section-title">
|
||||
<svg class="section-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
|
||||
<polyline points="7 10 12 15 17 10"/>
|
||||
<line x1="12" y1="15" x2="12" y2="3"/>
|
||||
</svg>
|
||||
Backups (.bak files)
|
||||
</h2>
|
||||
|
||||
<div class="setting-group">
|
||||
<label class="setting-label">Enable backup files when saving</label>
|
||||
<div class="toggle-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="enableBackups"
|
||||
[checked]="backupsEnabled()"
|
||||
(change)="toggleBackups()"
|
||||
class="toggle-input" />
|
||||
<label for="enableBackups" class="toggle-label">
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
<p class="setting-hint">When disabled, existing .bak files in the vault will be removed automatically.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Folder Filtering Section -->
|
||||
<section class="parameters-section">
|
||||
<h2 class="section-title">
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component, inject, signal, effect } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ThemeService, ThemeMode, ThemeId, Language } from '../../core/services/theme.service';
|
||||
import { SettingsService } from '../../services/settings.service';
|
||||
import { ToastService } from '../../shared/toast/toast.service';
|
||||
import { FolderFilterService, FolderFilterConfig } from '../../services/folder-filter.service';
|
||||
|
||||
@@ -16,11 +17,13 @@ export class ParametersPage {
|
||||
private themeService = inject(ThemeService);
|
||||
private toastService = inject(ToastService);
|
||||
private folderFilterService = inject(FolderFilterService);
|
||||
private settingsService = inject(SettingsService);
|
||||
|
||||
// Reactive prefs
|
||||
prefs = signal(this.themeService.prefsValue);
|
||||
folderFilterConfig = signal<FolderFilterConfig>(this.folderFilterService.getConfig());
|
||||
newExcludedFolder = '';
|
||||
backupsEnabled = signal<boolean>(true);
|
||||
|
||||
modes: ThemeMode[] = ['system', 'light', 'dark'];
|
||||
themes: ThemeId[] = ['light', 'dark', 'obsidian', 'nord', 'notion', 'github', 'discord', 'monokai'];
|
||||
@@ -47,6 +50,13 @@ export class ParametersPage {
|
||||
|
||||
return () => subscription.unsubscribe();
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
const sub = this.settingsService.getSettings().subscribe(({ enableBackups }) => {
|
||||
this.backupsEnabled.set(!!enableBackups);
|
||||
});
|
||||
return () => sub.unsubscribe();
|
||||
});
|
||||
}
|
||||
|
||||
setMode(mode: ThemeMode): void {
|
||||
@@ -128,4 +138,18 @@ export class ParametersPage {
|
||||
this.folderFilterConfig.set(this.folderFilterService.getConfig());
|
||||
this.showToast('Folder filters reset to defaults');
|
||||
}
|
||||
|
||||
toggleBackups(): void {
|
||||
const next = !this.backupsEnabled();
|
||||
this.settingsService.updateBackups(next).subscribe((res) => {
|
||||
this.backupsEnabled.set(res.enableBackups);
|
||||
if (!res.enableBackups && (res.deletedBakFiles ?? 0) > 0) {
|
||||
this.showToast(`Backups disabled. Deleted ${res.deletedBakFiles} .bak files`);
|
||||
} else if (!res.enableBackups) {
|
||||
this.showToast('Backups disabled');
|
||||
} else {
|
||||
this.showToast('Backups enabled');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map } from 'rxjs';
|
||||
|
||||
export interface AppSettings {
|
||||
enableBackups: boolean;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SettingsService {
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getSettings(): Observable<AppSettings> {
|
||||
return this.http.get<AppSettings>('/api/settings').pipe(
|
||||
map((res) => ({ enableBackups: res?.enableBackups !== false }))
|
||||
);
|
||||
}
|
||||
|
||||
updateBackups(enableBackups: boolean): Observable<{ success: boolean; enableBackups: boolean; deletedBakFiles?: number }>
|
||||
{
|
||||
return this.http.put<{ success: boolean; enableBackups: boolean; deletedBakFiles?: number }>(
|
||||
'/api/settings',
|
||||
{ enableBackups }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user