mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 23:31:33 +08:00 
			
		
		
		
	widgets now use options object
This commit is contained in:
		
							parent
							
								
									9622b046e0
								
							
						
					
					
						commit
						1f092c2656
					
				@ -1,5 +1,6 @@
 | 
				
			|||||||
import bundleService from "./bundle.js";
 | 
					import bundleService from "./bundle.js";
 | 
				
			||||||
import messagingService from "./messaging.js";
 | 
					import messagingService from "./messaging.js";
 | 
				
			||||||
 | 
					import optionsService from "./options.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Sidebar {
 | 
					class Sidebar {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -61,6 +62,8 @@ class Sidebar {
 | 
				
			|||||||
            import("../widgets/what_links_here.js")
 | 
					            import("../widgets/what_links_here.js")
 | 
				
			||||||
        ])).map(m => m.default);
 | 
					        ])).map(m => m.default);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const options = await optionsService.waitForOptions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const widgetRelations = await this.ctx.note.getRelations('widget');
 | 
					        const widgetRelations = await this.ctx.note.getRelations('widget');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const widgetRelation of widgetRelations) {
 | 
					        for (const widgetRelation of widgetRelations) {
 | 
				
			||||||
@ -73,7 +76,7 @@ class Sidebar {
 | 
				
			|||||||
            const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
 | 
					            const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                const widget = new widgetClass(this.ctx, state);
 | 
					                const widget = new widgetClass(this.ctx, options, state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (await widget.isEnabled()) {
 | 
					                if (await widget.isEnabled()) {
 | 
				
			||||||
                    const $el = await widget.render();
 | 
					                    const $el = await widget.render();
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,12 @@ const WIDGET_TPL = `
 | 
				
			|||||||
class StandardWidget {
 | 
					class StandardWidget {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @param {TabContext} ctx
 | 
					     * @param {TabContext} ctx
 | 
				
			||||||
 | 
					     * @param {Options} options
 | 
				
			||||||
     * @param {object} state
 | 
					     * @param {object} state
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    constructor(ctx, state) {
 | 
					    constructor(ctx, options, state) {
 | 
				
			||||||
        this.ctx = ctx;
 | 
					        this.ctx = ctx;
 | 
				
			||||||
 | 
					        this.options = options;
 | 
				
			||||||
        this.state = state;
 | 
					        this.state = state;
 | 
				
			||||||
        // construct in camelCase
 | 
					        // construct in camelCase
 | 
				
			||||||
        this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1);
 | 
					        this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1);
 | 
				
			||||||
@ -84,7 +86,7 @@ class StandardWidget {
 | 
				
			|||||||
    async doRenderBody() {}
 | 
					    async doRenderBody() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async isEnabled() {
 | 
					    async isEnabled() {
 | 
				
			||||||
        const option = await optionsService.getJsonOption(this.widgetName + 'Widget');
 | 
					        const option = this.options.getJson(this.widgetName + 'Widget');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return option ? option.enabled : true;
 | 
					        return option ? option.enabled : true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user