package com.fatico.winthing;

import com.fatico.winthing.gui.WindowGUI;
import com.fatico.winthing.messaging.Engine;
import com.google.inject.Guice;
import com.google.inject.Injector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Application {
	public static boolean APPDEBUG = false;
    private static final Logger logger = LoggerFactory.getLogger(Application.class);

    public static void main(final String[] args) {
        try {
        	parseArgs(args);
        	
        	WindowGUI gui = WindowGUI.getInstance();
        	gui.tray();
        	 
        	final Injector injector = Guice.createInjector(new ApplicationModule());
        	final Engine engine = injector.getInstance(Engine.class);
        	engine.run();
        	
        } catch (final Throwable throwable) {
            logger.error("Critical error.", throwable);
            System.exit(1);
        }
    }
    
    public static void parseArgs(String[] args) {
    	for (String arg : args) {
    		if (arg.equals("-debug")) {
    			APPDEBUG = true;
    		}
    	}
    }
}

@@ -265,28 +265,22 @@
 ion %7B%0A%09p
-ublic static
+rivate
  boolean
@@ -280,24 +280,21 @@
 boolean 
-APPDEBUG
+debug
  = false
@@ -295,16 +295,69 @@
  false;%0A
+%09private static Application app = new Application();%0A
     priv
@@ -432,17 +432,364 @@
 .class);
-%0A
+    %0A    %0A    private void parseArgs(String%5B%5D args) %7B%0A    %09for (String arg : args) %7B%0A    %09%09if (arg.equals(%22-debug%22)) %7B%0A    %09%09%09debug = true;%0A    %09%09%7D%0A    %09%7D%0A    %7D    %0A    %0A    public static boolean debug() %7B%0A    %09return app.debug;%0A    %7D%0A    %0A    public static void quit() %7B%0A    %09logger.info(%22Application terminated.%22);%0A    %09System.exit(0);%0A    %7D%0A    
 %0A    pub
@@ -855,16 +855,20 @@
        %09
+app.
 parseArg
@@ -1280,16 +1280,16 @@
 xit(1);%0A
+
         
@@ -1300,171 +1300,6 @@
   %7D%0A
-    %0A    public static void parseArgs(String%5B%5D args) %7B%0A    %09for (String arg : args) %7B%0A    %09%09if (arg.equals(%22-debug%22)) %7B%0A    %09%09%09APPDEBUG = true;%0A    %09%09%7D%0A    %09%7D%0A    %7D%0A
 %7D%0A

Change how we provide if debug parameter has been passed. Add function to quit application - we call simply system.exit, proper thread cleanup would be perhaps better.