Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding an event to listen to for package state changes (closes #36) #38

Merged
merged 5 commits into from

2 participants

@bjtitus

Not sure if this is the best way to do this but it seemed to be the easiest way for now. This will at least patch the potentially harmful ability to be able to install packages multiple times.

Obviously, I'm very new to this codebase (and not too experienced with CoffeeScript either) so let me know if this can be improved somehow.

bjtitus and others added some commits
@bjtitus bjtitus Adding an event to key off for package state changes (closes #36)
Not sure if this is the best way to do this but it seemed to be the easiest way for now. This will at least patch the potentially harmful ability to be able to install packages multiple times.
07dc0db
@kevinsawicki kevinsawicki Merge pull request #44 from jsmecham/prevent-text-selection-in-config…
…-menu

Prevent text selection in the config menu
139dfaf
lib/available-package-view.coffee
@@ -18,21 +18,37 @@ class AvailablePackageView extends View
initialize: (@pack, @packageManager) ->
@type = if @pack.theme then 'theme' else 'package'
+ @eventName = @pack.name + "-event"
+ @document = $(atom.workspaceView)
@kevinsawicki Owner

atom.workspaceView already extends the jQuery prototype so you shouldn't need to wrap it in $().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/available-package-view.coffee
@@ -18,21 +18,37 @@ class AvailablePackageView extends View
initialize: (@pack, @packageManager) ->
@type = if @pack.theme then 'theme' else 'package'
+ @eventName = @pack.name + "-event"
+ @document = $(atom.workspaceView)
+
+ @document.on @eventName, (event, status, error) =>
@kevinsawicki Owner

The @packageManager object is probably a better place to listen for and emit events since the same instance if used across all panels/views in the settings view.

That way atom.workspaceView doesn't have to be involved, just the single PackageManager instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bjtitus

Thanks @kevinsawicki!

I learned about the jQuery element deal later. Great to know about PackageManager and emissary! It would be nice to have a list of the core events somewhere in the API docs if possible. I added a custom "package-installing" (which really covers package & theme installation). This should probably be added to the core instead, but I figured it was worth adding in here for now.

Let me know if there's any other way this can be improved.

@kevinsawicki

Thanks for this, sorry it took a bit long to merge in.

@kevinsawicki kevinsawicki merged commit 2e73de8 into atom:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2014
  1. @bjtitus

    Adding an event to key off for package state changes (closes #36)

    bjtitus authored
    Not sure if this is the best way to do this but it seemed to be the easiest way for now. This will at least patch the potentially harmful ability to be able to install packages multiple times.
Commits on Feb 28, 2014
  1. @kevinsawicki

    Merge pull request #44 from jsmecham/prevent-text-selection-in-config…

    kevinsawicki authored
    …-menu
    
    Prevent text selection in the config menu
Commits on Mar 1, 2014
Commits on Mar 2, 2014
  1. Using Package Manager events

    Brandon authored
  2. Forgot theme-install-failed event

    Brandon authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 6 deletions.
  1. +18 −6 lib/available-package-view.coffee
View
24 lib/available-package-view.coffee
@@ -18,20 +18,32 @@ class AvailablePackageView extends View
initialize: (@pack, @packageManager) ->
@type = if @pack.theme then 'theme' else 'package'
+ @handlePackageEvents()
+
@installButton.on 'click', =>
- @installButton.prop('disabled', true)
- @setStatusIcon('cloud-download')
+ @packageManager.emit('package-installing', @pack)
+
@packageManager.install @pack, (error) =>
- if error?
+ if error
+ console.error("Installing #{@type} #{@pack.name} failed", error.stack ? error, error.stderr)
+
+ @learnMoreButton.on 'click', =>
+ shell.openExternal "https://atom.io/packages/#{@pack.name}"
+
+ handlePackageEvents: ->
+ @subscribe @packageManager, 'package-installed package-install-failed theme-installed theme-install-failed', (pack, error) =>
+ if pack.name == @pack.name
+ if error
@setStatusIcon('alert')
@installButton.prop('disabled', false)
- console.error("Installing #{@type} #{@pack.name} failed", error.stack ? error, error.stderr)
else
@setStatusIcon('check')
@installButton.text('Installed')
- @learnMoreButton.on 'click', =>
- shell.openExternal "https://atom.io/packages/#{@pack.name}"
+ @subscribe @packageManager, 'package-installing', (pack) =>
+ if pack.name == @pack.name
+ @installButton.prop('disabled', true)
+ @setStatusIcon('cloud-download')
setStatusIcon: (iconName) ->
@status.removeClass('icon-check icon-alert icon-cloud-download')
Something went wrong with that request. Please try again.