All files / src main.ts

0% Statements 0/66
0% Branches 0/2
0% Functions 0/19
0% Lines 0/63

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183                                                                                                                                                                                                                                                                                                                                                                             
import { Component, Plugin, Setting } from 'obsidian';
import { SettingTab } from 'src/classes/SettingsTab';
import { IPrjSettings as IPrjSettings } from 'src/types/PrjSettings';
import API from './classes/API';
import Lng from './classes/Lng';
import type IMetadataCache from './interfaces/IMetadataCache';
import { Inject } from './libs/DependencyInjection/decorators/Inject';
import { DIContainer } from './libs/DependencyInjection/DIContainer';
import { HelperObsidian } from './libs/Helper/Obsidian';
import KanbanSync from './libs/KanbanSync/KanbanSync';
import { LifecycleManager } from './libs/LifecycleManager/LifecycleManager';
import AddAnnotationModal from './libs/Modals/AddAnnotationModal';
import ChangeStatusModal from './libs/Modals/ChangeStatusModal';
import CreateNewMetadataModal from './libs/Modals/CreateNewMetadataModal';
import CreateNewNoteModal from './libs/Modals/CreateNewNoteModal';
import CreateNewProjectModal from './libs/Modals/CreateNewProjectModal';
import CreateNewTaskManagementModal from './libs/Modals/CreateNewTaskManagementModal';
import CreateNewTaskModal from './libs/Modals/CreateNewTaskModal';
import { DEFAULT_SETTINGS } from './types/PrjSettings';
// This file is generated by esbuild and imports all classes that use the `Lifecycle` decorator.
import './auto-imports';
 
/**
 * The main plugin class
 */
export default class Prj extends Plugin {
    public settings: IPrjSettings;
    public api: API = API;
 
    @Inject('IMetadataCache')
    private readonly _IMetadataCache!: IMetadataCache;
 
    /**
     * Will be called when the plugin is loaded
     */
    async onload(): Promise<void> {
        // eslint-disable-next-line no-console
        console.log("Loading plugin 'PRJ'");
 
        DIContainer.getInstance().register('IPrj', this);
        DIContainer.getInstance().register('IApp', this.app);
        DIContainer.getInstance().register('Obsidian.Component_', Component);
        DIContainer.getInstance().register('Obsidian.Setting_', Setting);
 
        await this.loadSettings();
 
        LifecycleManager.register('before', 'init', () => {
            // eslint-disable-next-line no-console
            console.log('Layout ready');
        });
 
        LifecycleManager.register(
            'on',
            'init',
            async () => await this._IMetadataCache.waitForCacheReady(),
        );
 
        LifecycleManager.register('after', 'init', () => this.onLayoutReady());
 
        if (this.app.workspace.layoutReady) {
            await new LifecycleManager().onInit();
        } else {
            this.app.workspace.onLayoutReady(async () => {
                await new LifecycleManager().onInit();
            });
        }
    }
 
    /**
     * Will be called when the layout is ready
     */
    async onLayoutReady(): Promise<void> {
        // Copy Markdown Link Context Menu
        //CopyMarkdownLink.getInstance();
 
        // Register Commands and Events
        this.registerCommandsAndEvents();
 
        /**
         * Run rebuild active view after 500ms
         * This is a workaround for the problem
         * that the plugin is not loaded when the
         * start page is loaded.
         */
        setTimeout(() => {
            // Possibly no longer necessary with the current Obsidian version...
            HelperObsidian.rebuildActiveView();
        }, 500);
 
        new LifecycleManager().onLoad();
    }
 
    /**
     * Register the Obsidian Commands an Events
     */
    private registerCommandsAndEvents(): void {
        // Create New Metadata File Command
        CreateNewMetadataModal.registerCommand();
 
        // Create new Task Managment Command
        CreateNewTaskManagementModal.registerCommand();
        // Create new Task Command
        CreateNewTaskModal.registerCommand();
        // Create new Project Command
        CreateNewProjectModal.registerCommand();
        // Add Annotation Command
        AddAnnotationModal.registerCommand();
        // Add new note Command
        CreateNewNoteModal.registerCommand();
 
        // Change Status Command
        ChangeStatusModal.registerCommand();
 
        //
        //Register event on `Status` change..
        this._IMetadataCache.on(
            'prj-task-management-changed-status-event',
            (file) => {
                API.prjTaskManagementModel.syncStatusToPath(file);
            },
        );
 
        //Register event on `task-file` change..
        this._IMetadataCache.on(
            'prj-task-management-file-changed-event',
            (file) => {
                API.prjTaskManagementModel.syncTitleToFilename(file);
            },
        );
 
        //Register event on `Document Metadata` change..
        this._IMetadataCache.on('document-changed-metadata-event', (file) => {
            API.documentModel.syncMetadataToFile(file);
        });
 
        //Register event Kanban Check
        KanbanSync.registerEvent();
 
        // Register rebuild View command:
        this.addCommand({
            id: 'rebuild-active-view',
            name: Lng.gt('Rebuild active view'),
            /**
             * Rebuild the active view
             */
            callback: async () => {
                HelperObsidian.rebuildActiveView();
            },
        });
    }
 
    /**
     * Will be called when the plugin is unloaded
     */
    onunload(): void {
        // eslint-disable-next-line no-console
        console.log("Unloading plugin 'PRJ'");
        new LifecycleManager().onUnload();
    }
 
    /**
     * Load the settings
     */
    async loadSettings(): Promise<void> {
        this.settings = Object.assign(
            {},
            DEFAULT_SETTINGS,
            await this.loadData(),
        );
 
        DIContainer.getInstance().register('IPrjSettings', this.settings);
 
        this.addSettingTab(new SettingTab(this.app, this));
    }
 
    /**
     * Save the settings
     */
    async saveSettings(): Promise<void> {
        await this.saveData(this.settings);
    }
}
 
Zur TypeDoc-Dokumentation