mirror of
https://github.com/fantasy-ke/obsidian-cf-imgbed.git
synced 2026-07-22 06:43:08 +00:00
- Add I18n class for language management and translations. - Update settings tab and image handler to utilize internationalization for labels and messages. - Modify event handlers to support localized menu titles. - Ensure language settings are configurable and persist across sessions.
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { Plugin } from 'obsidian';
|
|
import { CFImageBedSettings, DEFAULT_SETTINGS } from './src/types';
|
|
import { UploadService } from './src/upload/uploadService';
|
|
import { ImageHandler } from './src/upload/imageHandler';
|
|
import { EventHandlers } from './src/events/eventHandlers';
|
|
import { CFImageBedSettingTab } from './src/settings/settingsTab';
|
|
import { I18n } from './src/utils/i18n';
|
|
|
|
export default class CFImageBedPlugin extends Plugin {
|
|
settings: CFImageBedSettings;
|
|
private uploadService: UploadService;
|
|
private imageHandler: ImageHandler;
|
|
private eventHandlers: EventHandlers;
|
|
private i18n: I18n;
|
|
|
|
async onload() {
|
|
await this.loadSettings();
|
|
|
|
// 初始化i18n
|
|
this.i18n = new I18n(this.settings.language || 'zh');
|
|
|
|
// 初始化服务
|
|
this.uploadService = new UploadService(this.settings);
|
|
this.imageHandler = new ImageHandler(this.app, this.uploadService, () => this.settings, this.i18n);
|
|
this.eventHandlers = new EventHandlers(this.imageHandler, this.i18n);
|
|
|
|
// 注册事件处理器
|
|
this.eventHandlers.registerDragAndDropEvents(this);
|
|
this.eventHandlers.registerPasteEvents(this);
|
|
this.eventHandlers.registerEditorMenuEvents(this);
|
|
|
|
// 移动端专用命令:支持相机拍照和相册选择
|
|
this.addCommand({
|
|
id: 'upload-image-mobile',
|
|
name: '📷 拍照或相册选择',
|
|
icon: 'camera',
|
|
callback: () => {
|
|
this.imageHandler.selectImageForMobile();
|
|
}
|
|
});
|
|
|
|
// 添加设置页面
|
|
this.addSettingTab(new CFImageBedSettingTab(this.app, this));
|
|
}
|
|
|
|
onunload() {
|
|
|
|
}
|
|
|
|
|
|
|
|
async loadSettings() {
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
}
|
|
|
|
async saveSettings() {
|
|
await this.saveData(this.settings);
|
|
}
|
|
}
|