theme-package.js
1 const path = require('path'); 2 const Package = require('./package'); 3 4 module.exports = class ThemePackage extends Package { 5 getType() { 6 return 'theme'; 7 } 8 9 getStyleSheetPriority() { 10 return 1; 11 } 12 13 enable() { 14 this.config.unshiftAtKeyPath('core.themes', this.name); 15 } 16 17 disable() { 18 this.config.removeAtKeyPath('core.themes', this.name); 19 } 20 21 preload() { 22 this.loadTime = 0; 23 this.configSchemaRegisteredOnLoad = this.registerConfigSchemaFromMetadata(); 24 } 25 26 finishLoading() { 27 this.path = path.join(this.packageManager.resourcePath, this.path); 28 } 29 30 load() { 31 this.loadTime = 0; 32 this.configSchemaRegisteredOnLoad = this.registerConfigSchemaFromMetadata(); 33 return this; 34 } 35 36 activate() { 37 if (this.activationPromise == null) { 38 this.activationPromise = new Promise((resolve, reject) => { 39 this.resolveActivationPromise = resolve; 40 this.rejectActivationPromise = reject; 41 this.measure('activateTime', () => { 42 try { 43 this.loadStylesheets(); 44 this.activateNow(); 45 } catch (error) { 46 this.handleError( 47 `Failed to activate the ${this.name} theme`, 48 error 49 ); 50 } 51 }); 52 }); 53 } 54 55 return this.activationPromise; 56 } 57 };