'use babel';
/* @flow */

import install from './installer';
import child_process from 'child_process';
import log4js from 'log4js';

const logger = log4js.getLogger('installer');

export function activate () {
	install();
}

export function getAutoCompleteProvider(): AutocompleteProvider {
	logger.trace('Registering auto-complete provider.');
	return require('./autocomplete-provider').provider;
}

export function getHyperclickProvider(): HyperclickProvider {
	logger.trace('Registering hyperclick provider.');
	return require('./hyperclick-provider').provider;
}

var toolBarSection = null;
export function consumeToolBar(toolBar) {
	logger.trace('Setting up toolbar.');

  toolBarSection = toolBar('love-ide');
	var runButton = toolBarSection.addButton({
		icon: 'play',
		tooltip: 'Run Love App',
		iconset: 'ion',
		callback() {
			var [dir] = atom.project.getPaths();
			child_process.exec('love .', {cwd: dir}, (err, stdout, stderr) => {
				// TODO: Report error.
			});
		}
	});
}

export function deactivate() {
	if (toolBarSection) {
		toolBarSection.removeItems();
	}
}

@@ -174,16 +174,401 @@
 ler');%0A%0A
+export var config = %7B%0A%09lovePath: %7B%0A%09%09title: 'Path to Love Executable',%0A%09%09description: %60This should be the full path to the LOVE executable.%0AOn OSX, this is likely '/Applications/love.app/Contents/MacOS/love'.%0AOn Windows, this is likely 'C:%5C%5CProgram Files (x86)%5C%5CLOVE%5C%5Clove.exe'%0ALeave blank to use the executable found in the PATH.%60,%0A%09%09type: 'string',%0A%09%09default: '',%0A%09%09order: 1,%0A%09%7D,%0A%7D%0A%0A
 export f
@@ -1255,16 +1255,82 @@
 aths();%0A
+%09%09%09var lovePath = atom.config.get('love-ide.lovePath') %7C%7C 'love';%0A
 %09%09%09child
@@ -1347,16 +1347,23 @@
 xec(
-'
+%60$%7B
 love
+Path%7D
  .
-'
+%60
 , %7Bc
@@ -1407,30 +1407,116 @@
 %09%09%09%09
-// TODO: Report error.
+if(err) %7B%0A%09%09%09%09%09atom.notifications.addFatalError('Error running LOVE.', %7B%0A%09%09%09%09%09%09detail: stderr%0A%09%09%09%09%09%7D);%0A%09%09%09%09%7D
 %0A%09%09%09

Allow user to specify path to LOVE executable in config.