From d931ff87c71b02a4b6f78eee14d0372e916dfece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5lsson?= <007701@lt-tdc-118.getaccess.no> Date: Tue, 3 Oct 2017 14:02:20 +0200 Subject: [PATCH 1/3] Disable update notification for disabled packages --- lib/package-updates-status-view.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/package-updates-status-view.js b/lib/package-updates-status-view.js index fa72cfda..85a940c1 100644 --- a/lib/package-updates-status-view.js +++ b/lib/package-updates-status-view.js @@ -27,6 +27,7 @@ export default class PackageUpdatesStatusView { this.disposables.add(packageManager.on('package-updating theme-updating', ({pack, error}) => { this.onPackageUpdating(pack) })) this.disposables.add(packageManager.on('package-updated theme-updated package-uninstalled theme-uninstalled', ({pack, error}) => { this.onPackageUpdated(pack) })) this.disposables.add(packageManager.on('package-update-failed theme-update-failed', ({pack, error}) => { this.onPackageUpdateFailed(pack) })) + this.disposables.add(atom.config.onDidChange('core.disabledPackages', () => { this.updateTile() })) const clickHandler = () => { atom.commands.dispatch(atom.views.getView(atom.workspace), 'settings-view:check-for-package-updates') @@ -120,6 +121,16 @@ export default class PackageUpdatesStatusView { } updateTile () { + const disabledPackages = [] + if (this.updates.length){ + for (let index = 0; index < this.updates.length; index++) { + const update = this.updates[index] + if (atom.packages.isPackageDisabled(update.name)) { + disabledPackages.push(update) + this.updates.splice(index, 1) + } + } + } if (this.updates.length) { if (this.tooltip) { this.tooltip.dispose() @@ -152,5 +163,8 @@ export default class PackageUpdatesStatusView { this.tile = null this.destroyed = true } + for(index=0; index < disabledPackages.length; index++) { + this.updates.push(disabledPackages[index]) + } } } From b2de5eed6eb166fb63bb0b20d2497d8fda747d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5lsson?= <007701@lt-722-004.getaccess.no> Date: Tue, 31 Oct 2017 00:12:17 +0100 Subject: [PATCH 2/3] Fixes bug with this.update and adds specs --- lib/package-updates-status-view.js | 8 +++++++- spec/package-updates-status-view-spec.coffee | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/package-updates-status-view.js b/lib/package-updates-status-view.js index 85a940c1..36d0ca38 100644 --- a/lib/package-updates-status-view.js +++ b/lib/package-updates-status-view.js @@ -127,10 +127,16 @@ export default class PackageUpdatesStatusView { const update = this.updates[index] if (atom.packages.isPackageDisabled(update.name)) { disabledPackages.push(update) - this.updates.splice(index, 1) + } + } + for (let index = 0; index < disabledPackages.length; index++) { + if (this.updates.includes(disabledPackages[index])){ + const location = this.updates.indexOf(disabledPackages[index]) + this.updates.splice(location,1) } } } + if (this.updates.length) { if (this.tooltip) { this.tooltip.dispose() diff --git a/spec/package-updates-status-view-spec.coffee b/spec/package-updates-status-view-spec.coffee index 510f1efe..fb998a95 100644 --- a/spec/package-updates-status-view-spec.coffee +++ b/spec/package-updates-status-view-spec.coffee @@ -150,3 +150,17 @@ describe "PackageUpdatesStatusView", -> packageManager.emitPackageEvent('update-failed', outdatedPackage1) packageManager.emitPackageEvent('uninstalled', outdatedPackage1) expect(document.querySelector('status-bar .package-updates-status-view').textContent).toBe '1 update' + + describe "when one packages is disabled", -> + it "updates the tile", -> + spyOn(atom.packages, 'isPackageDisabled').andCallFake (args) -> + if args is outdatedPackage1.name + return true + atom.config.set('core.disabledPackages', ['something']) + expect(document.querySelector('status-bar .package-updates-status-view').textContent).toBe '1 update' + + describe "when all packages are disabled", -> + it "destroys the tile", -> + spyOn(atom.packages, 'isPackageDisabled').andReturn true + atom.config.set('core.disabledPackages', ['something']) + expect(document.querySelector('status-bar .package-updates-status-view')).not.toExist() From 1e465d24725e23e8b68b832a141275a24bfa5696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5lsson?= <007701@lt-722-004.getaccess.no> Date: Tue, 31 Oct 2017 02:36:16 +0100 Subject: [PATCH 3/3] Refactors code to use filter instead of for-loop --- lib/package-updates-status-view.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/package-updates-status-view.js b/lib/package-updates-status-view.js index 36d0ca38..dec2dd41 100644 --- a/lib/package-updates-status-view.js +++ b/lib/package-updates-status-view.js @@ -123,18 +123,9 @@ export default class PackageUpdatesStatusView { updateTile () { const disabledPackages = [] if (this.updates.length){ - for (let index = 0; index < this.updates.length; index++) { - const update = this.updates[index] - if (atom.packages.isPackageDisabled(update.name)) { - disabledPackages.push(update) - } - } - for (let index = 0; index < disabledPackages.length; index++) { - if (this.updates.includes(disabledPackages[index])){ - const location = this.updates.indexOf(disabledPackages[index]) - this.updates.splice(location,1) - } - } + const updatesWithoutDisabled = this.updates.filter(update => atom.packages.isPackageDisabled(update.name)) + updatesWithoutDisabled.filter(update => this.updates.splice(this.updates.indexOf(update),1)) + updatesWithoutDisabled.filter(update => disabledPackages.push(update)) } if (this.updates.length) { @@ -169,8 +160,8 @@ export default class PackageUpdatesStatusView { this.tile = null this.destroyed = true } - for(index=0; index < disabledPackages.length; index++) { - this.updates.push(disabledPackages[index]) + if (disabledPackages.length){ + disabledPackages.filter(update => this.updates.push(update)) } } }