import Resolver from 'resolver';

var App = Ember.Application.extend({
  LOG_ACTIVE_GENERATION: true,
  LOG_MODULE_RESOLVER: true,
  LOG_TRANSITIONS: true,
  LOG_TRANSITIONS_INTERNAL: true,
  LOG_VIEW_LOOKUPS: true,
  modulePrefix: 'appkit', // TODO: loaded via config
  Resolver: Resolver['default'],
  init: function () {
    window.ENV.firebase = new Firebase("https://" + window.ENV.dbName + ".firebaseio.com/" + window.ENV.dbBucket);

    // Open a connection to the local web socket, and set up send command
    var localSocket = new window.WebSocket('ws://localhost:6557');
    var connected = false;
    var storedCommands = [];

    window.ENV.sendGruntCommand = function(command) {
      if(connected) {
        localSocket.send(command);
      } else {
        storedCommands.push(command);
      }
    };

    localSocket.onopen = function() {
      connected = true;

      storedCommands.forEach(function(item) {
        window.ENV.sendGruntCommand(item);
      });
      storedCommands = [];
    };

    this._super.apply(this, arguments);
  }
});

// This helps ember-validations not blow up
// https://github.com/dockyard/ember-validations/issues/26#issuecomment-31877071
DS.Model.reopen({
  isValid: false
});

export default App;

@@ -629,16 +629,94 @@
 ds = %5B%5D;
+%0A    var emptyCallback = function() %7B %7D;%0A    var doneCallback = emptyCallback;
 %0A%0A    wi
@@ -759,16 +759,26 @@
 (command
+, callback
 ) %7B%0A    
@@ -840,54 +840,299 @@
     
-%7D else %7B%0A        storedCommands.push(command);
+  if(callback) doneCallback = callback;%0A      %7D else %7B%0A        storedCommands.push(command);%0A      %7D%0A    %7D;%0A%0A    localSocket.onmessage = function(event) %7B%0A      if(event.data === 'done') %7B%0A        doneCallback();%0A        doneCallback = emptyCallback; //Reset so done doesn't get called twice
 %0A   

set up done callback for multi step commands