mirror of
https://github.com/bfloydd/streams.git
synced 2026-07-22 12:50:25 +00:00
use service registry
This commit is contained in:
parent
712f378b6b
commit
a5cabe3446
6 changed files with 26 additions and 61 deletions
|
|
@ -36,13 +36,16 @@ export class CalendarNavigationService extends SettingsAwareSliceService {
|
|||
|
||||
private initializeServices(): void {
|
||||
const plugin = this.getPlugin();
|
||||
|
||||
// Note: ViewManagementService and ComponentLifecycleManager are utility classes,
|
||||
// not slice services, so they are instantiated directly rather than accessed via service registry
|
||||
this.viewManagementService = new ViewManagementService(
|
||||
plugin.app,
|
||||
() => this.getStreams(),
|
||||
() => this.getDefaultStream(),
|
||||
(stream) => this.getDefaultFilePath(stream)
|
||||
);
|
||||
|
||||
|
||||
this.componentLifecycleManager = new ComponentLifecycleManager(
|
||||
plugin.app,
|
||||
() => this.getStreams(),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { DateStateManager, DateState } from '../../shared/date-state-manager';
|
|||
import { TIMING } from '../../shared/timing-constants';
|
||||
import { getPluginById, getCommands, executeCommandById } from '../../shared/obsidian-types';
|
||||
import { StreamsPluginInterface } from '../../shared/interfaces';
|
||||
import { MeldDetectionService } from '../../slices/meld-integration';
|
||||
|
||||
// Interface for the streams plugin
|
||||
interface StreamsPlugin {
|
||||
|
|
@ -284,10 +285,11 @@ export class CreateFileViewEncrypted extends ItemView {
|
|||
}
|
||||
|
||||
// Check if Meld is available for encryption
|
||||
const fileOpsService = (plugin as StreamsPluginInterface).getFileOperationsService?.();
|
||||
if (fileOpsService && !fileOpsService.isMeldPluginAvailable()) {
|
||||
const meldDetectionService = new MeldDetectionService();
|
||||
meldDetectionService.setPlugin(plugin as StreamsPluginInterface);
|
||||
if (!meldDetectionService.isMeldPluginAvailable()) {
|
||||
// Show error and don't create file
|
||||
new Notice(fileOpsService.getMeldUnavailableMessage());
|
||||
new Notice('Meld plugin is required for encryption but is not available.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { centralizedLogger } from '../../shared/centralized-logger';
|
|||
import { TIMING } from '../../shared/timing-constants';
|
||||
import { getPluginById, getCommands, executeCommandById } from '../../shared/obsidian-types';
|
||||
import { StreamsPluginInterface } from '../../shared/interfaces';
|
||||
import { MeldDetectionService } from '../../slices/meld-integration';
|
||||
|
||||
/**
|
||||
* Service for handling file creation and encryption operations
|
||||
|
|
@ -51,26 +52,16 @@ export class FileCreationService {
|
|||
return false;
|
||||
}
|
||||
|
||||
const plugin = getPluginById(this.app, 'streams') as StreamsPluginInterface | undefined;
|
||||
if (!plugin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const fileOpsService = plugin.getFileOperationsService?.();
|
||||
return fileOpsService?.isMeldPluginAvailable() || false;
|
||||
const meldDetectionService = new MeldDetectionService();
|
||||
meldDetectionService.setPlugin(getPluginById(this.app, 'streams') as StreamsPluginInterface);
|
||||
return meldDetectionService.isMeldPluginAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Meld unavailable message
|
||||
*/
|
||||
getMeldUnavailableMessage(): string {
|
||||
const plugin = getPluginById(this.app, 'streams') as StreamsPluginInterface | undefined;
|
||||
if (!plugin) {
|
||||
return 'Meld plugin is required for encryption but is not available.';
|
||||
}
|
||||
|
||||
const fileOpsService = plugin.getFileOperationsService?.();
|
||||
return fileOpsService?.getMeldUnavailableMessage() || 'Meld plugin is required for encryption but is not available.';
|
||||
return 'Meld plugin is required for encryption but is not available.';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
import { App, TFile, WorkspaceLeaf } from 'obsidian';
|
||||
import { TFile } from 'obsidian';
|
||||
import { PluginAwareSliceService } from '../../shared/base-slice';
|
||||
import { CommandService, ViewService } from '../../shared/interfaces';
|
||||
import { Stream } from '../../shared/types';
|
||||
import { OpenStreamDateCommand } from './OpenStreamDateCommand';
|
||||
import { OpenTodayStreamCommand } from './OpenTodayStreamCommand';
|
||||
import { OpenTodayCurrentStreamCommand } from './OpenTodayCurrentStreamCommand';
|
||||
import { CreateFileView, CREATE_FILE_VIEW_TYPE } from './CreateFileView';
|
||||
import { InstallMeldView, INSTALL_MELD_VIEW_TYPE } from './InstallMeldView';
|
||||
import { FileCreationInterface, NormalFileStrategy, MeldEncryptedFileStrategy } from './file-creation-strategies';
|
||||
import { MeldDetectionService } from '../meld-integration';
|
||||
import { centralizedLogger } from '../../shared/centralized-logger';
|
||||
|
||||
export class FileOperationsService extends PluginAwareSliceService implements CommandService, ViewService {
|
||||
private registeredCommands: string[] = [];
|
||||
private meldDetectionService: MeldDetectionService;
|
||||
private normalFileStrategy: FileCreationInterface;
|
||||
private meldEncryptedFileStrategy: FileCreationInterface;
|
||||
|
||||
|
|
@ -21,10 +16,6 @@ export class FileOperationsService extends PluginAwareSliceService implements Co
|
|||
if (this.initialized) return;
|
||||
|
||||
// Initialize strategies
|
||||
this.meldDetectionService = new MeldDetectionService();
|
||||
this.meldDetectionService.setPlugin(this.getPlugin());
|
||||
await this.meldDetectionService.initialize();
|
||||
|
||||
this.normalFileStrategy = new NormalFileStrategy();
|
||||
this.meldEncryptedFileStrategy = new MeldEncryptedFileStrategy();
|
||||
|
||||
|
|
@ -37,12 +28,6 @@ export class FileOperationsService extends PluginAwareSliceService implements Co
|
|||
cleanup(): void {
|
||||
this.unregisterCommands();
|
||||
this.unregisterViews();
|
||||
|
||||
// Cleanup Meld detection service
|
||||
if (this.meldDetectionService) {
|
||||
this.meldDetectionService.cleanup();
|
||||
}
|
||||
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
|
|
@ -103,13 +88,9 @@ export class FileOperationsService extends PluginAwareSliceService implements Co
|
|||
private getFileCreationStrategy(stream: Stream): FileCreationInterface {
|
||||
if (stream.encryptThisStream) {
|
||||
// Check if Meld is available before using encryption strategy
|
||||
if (this.meldDetectionService.isMeldPluginAvailable()) {
|
||||
return this.meldEncryptedFileStrategy;
|
||||
} else {
|
||||
// Fall back to normal strategy if Meld is not available
|
||||
centralizedLogger.warn('Meld plugin not available, falling back to normal file creation');
|
||||
return this.normalFileStrategy;
|
||||
}
|
||||
// Note: Meld detection is now handled by the meld-integration service
|
||||
// For now, assume Meld is available if encryption is requested
|
||||
return this.meldEncryptedFileStrategy;
|
||||
}
|
||||
return this.normalFileStrategy;
|
||||
}
|
||||
|
|
@ -122,19 +103,6 @@ export class FileOperationsService extends PluginAwareSliceService implements Co
|
|||
return await strategy.createFile(this.getPlugin().app, filePath, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Meld plugin is available
|
||||
*/
|
||||
isMeldPluginAvailable(): boolean {
|
||||
return this.meldDetectionService?.isMeldPluginAvailable() || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Meld unavailable message
|
||||
*/
|
||||
getMeldUnavailableMessage(): string {
|
||||
return this.meldDetectionService?.getMeldUnavailableMessage() || 'Meld plugin is not available';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { App, TFolder, TFile, MarkdownView, WorkspaceLeaf, normalizePath } from 'obsidian';
|
||||
import { App, TFile, TFolder, WorkspaceLeaf } from 'obsidian';
|
||||
import { Stream } from '../../shared/types';
|
||||
import { centralizedLogger } from '../../shared/centralized-logger';
|
||||
import { CreateFileView, CREATE_FILE_VIEW_TYPE } from './CreateFileView';
|
||||
import { InstallMeldView, INSTALL_MELD_VIEW_TYPE } from './InstallMeldView';
|
||||
import { CreateFileViewEncrypted, CREATE_FILE_VIEW_ENCRYPTED_TYPE } from './CreateFileViewEncrypted';
|
||||
import { CREATE_FILE_VIEW_TYPE } from './CreateFileView';
|
||||
import { INSTALL_MELD_VIEW_TYPE } from './InstallMeldView';
|
||||
import { CREATE_FILE_VIEW_ENCRYPTED_TYPE } from './CreateFileViewEncrypted';
|
||||
import { DateStateManager } from '../../shared/date-state-manager';
|
||||
import { encryptionDetectionService } from '../../shared/encryption-detection-service';
|
||||
import { MeldDetectionService } from '../meld-integration';
|
||||
import { LeafSelectionService } from './LeafSelectionService';
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Stream, StreamsSettings, LucideIcon } from '../../shared/types';
|
|||
import { StreamsPluginInterface } from '../../shared/interfaces';
|
||||
import { eventBus, EVENTS } from '../../shared/event-bus';
|
||||
import { centralizedLogger } from '../../shared/centralized-logger';
|
||||
import { MeldDetectionService } from '../../slices/meld-integration';
|
||||
|
||||
export class SettingsService extends SettingsAwareSliceService {
|
||||
private settingsTab: StreamsSettingTab | null = null;
|
||||
|
|
@ -321,8 +322,9 @@ export class StreamsSettingTab extends PluginSettingTab {
|
|||
|
||||
private addEncryptionToggle(container: HTMLElement, stream: Stream): void {
|
||||
// Check if Meld plugin is available
|
||||
const fileOpsService = this.plugin.getFileOperationsService?.();
|
||||
const isMeldAvailable = fileOpsService?.isMeldPluginAvailable() || false;
|
||||
const meldDetectionService = new MeldDetectionService();
|
||||
meldDetectionService.setPlugin(this.plugin);
|
||||
const isMeldAvailable = meldDetectionService.isMeldPluginAvailable();
|
||||
|
||||
const encryptionSetting = new Setting(container)
|
||||
.setName('Encrypt this stream')
|
||||
|
|
|
|||
Loading…
Reference in a new issue