|
| 1 | +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- |
| 2 | + |
| 3 | + |
| 4 | +import { |
| 5 | + Docking, |
| 6 | + AppIconIndicators, |
| 7 | + Utils, |
| 8 | +} from './imports.js'; |
| 9 | + |
| 10 | +import { |
| 11 | + AppDisplay, |
| 12 | +} from './dependencies/shell/ui.js'; |
| 13 | + |
| 14 | +export class AppIconsDecorator { |
| 15 | + constructor() { |
| 16 | + this._signals = new Utils.GlobalSignalsHandler(); |
| 17 | + this._iconSignals = new Utils.GlobalSignalsHandler(); |
| 18 | + this._methodInjections = new Utils.InjectionsHandler(); |
| 19 | + this._indicators = new Set(); |
| 20 | + |
| 21 | + this._patchAppIcons(); |
| 22 | + this._decorateIcons(); |
| 23 | + } |
| 24 | + |
| 25 | + destroy() { |
| 26 | + this._signals?.destroy(); |
| 27 | + delete this._signals; |
| 28 | + this._iconSignals?.destroy(); |
| 29 | + delete this._iconSignals; |
| 30 | + this._methodInjections?.destroy(); |
| 31 | + delete this._methodInjections; |
| 32 | + this._indicators?.clear(); |
| 33 | + delete this._indicators; |
| 34 | + } |
| 35 | + |
| 36 | + _decorateIcon(parentIcon) { |
| 37 | + const indicator = new AppIconIndicators.UnityIndicator(parentIcon); |
| 38 | + this._indicators.add(indicator); |
| 39 | + this._signals.add(parentIcon, 'destroy', () => { |
| 40 | + this._indicators.delete(indicator); |
| 41 | + indicator.destroy(); |
| 42 | + }); |
| 43 | + return indicator; |
| 44 | + } |
| 45 | + |
| 46 | + _decorateIcons() { |
| 47 | + const {appDisplay} = Docking.DockManager.getDefault().overviewControls; |
| 48 | + |
| 49 | + const decorateAppIcons = () => { |
| 50 | + this._indicators.clear(); |
| 51 | + this._iconSignals.clear(); |
| 52 | + |
| 53 | + const decorateViewIcons = view => { |
| 54 | + const items = view.getAllItems(); |
| 55 | + items.forEach(i => { |
| 56 | + if (i instanceof AppDisplay.AppIcon) { |
| 57 | + this._decorateIcon(i); |
| 58 | + } else if (i instanceof AppDisplay.FolderIcon) { |
| 59 | + decorateViewIcons(i.view); |
| 60 | + this._iconSignals.add(i.view, 'view-loaded', () => |
| 61 | + decorateAppIcons()); |
| 62 | + } |
| 63 | + }); |
| 64 | + }; |
| 65 | + decorateViewIcons(appDisplay); |
| 66 | + }; |
| 67 | + |
| 68 | + this._signals.add(appDisplay, 'view-loaded', () => decorateAppIcons()); |
| 69 | + decorateAppIcons(); |
| 70 | + } |
| 71 | + |
| 72 | + _patchAppIcons() { |
| 73 | + const self = this; |
| 74 | + |
| 75 | + this._methodInjections.add(AppDisplay.AppSearchProvider.prototype, |
| 76 | + 'createResultObject', function (originalFunction, ...args) { |
| 77 | + /* eslint-disable no-invalid-this */ |
| 78 | + const result = originalFunction.call(this, ...args); |
| 79 | + if (result instanceof AppDisplay.AppIcon) |
| 80 | + self._decorateIcon(result); |
| 81 | + return result; |
| 82 | + /* eslint-enable no-invalid-this */ |
| 83 | + }); |
| 84 | + } |
| 85 | +} |
0 commit comments