import gui.Gui;

import java.util.Scanner;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import api.ApiClient;
import controller.Controller;
import settings.Settings;
import utils.SysTray;

public class Start {

	public static void main(String args[])
	{	
		boolean cli = false;
		
		for(String arg: args)
		{
			if(arg.equals("-cli"))
			{
				cli = true;
			}
		}
		
		if(!cli)
		{			
			try
			{
				//ONE MUST BE ENABLED
				if(!Settings.getInstance().isGuiEnabled() && !Settings.getInstance().isRpcEnabled())
				{
					throw new Exception("Both gui and rpc cannot be disabled!");
				}
				
				//STARTING NETWORK/BLOCKCHAIN/RPC
				Controller.getInstance().start();
				
				if(Settings.getInstance().isGuiEnabled())
				{
					//START GUI
					Gui.getInstance();
					
					SysTray.getInstance().createTrayIcon();
				}
			}
			catch(Exception e)
			{
				e.printStackTrace();
				
				//USE SYSTEM STYLE
		        try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (Exception e2) {
					e2.printStackTrace();
				}
				
				//ERROR STARTING
				System.out.println("STARTUP ERROR: " + e.getMessage());
				
				if(Gui.isGuiStarted())
				{
					JOptionPane.showMessageDialog(null, e.getMessage(), "Startup Error", JOptionPane.ERROR_MESSAGE);
				}
				
				//FORCE SHUTDOWN
				System.exit(0);
			}
		}
		else
		{
			Scanner scanner = new Scanner(System.in);
			ApiClient client = new ApiClient();
			
			while(true)
			{
				
				System.out.print("[COMMAND] ");
				String command = scanner.nextLine();
				
				if(command.equals("quit"))
				{
					scanner.close();
					System.exit(0);
				}
				
				String result = client.executeCommand(command);
				System.out.println("[RESULT] " + result);
			}
		}		
	}
}

@@ -685,24 +685,39 @@
 art();%0A%09%09%09%09%0A
+%09%09%09%09try%0A%09%09%09%09%7B%0A%09
 %09%09%09%09if(Setti
@@ -750,26 +750,28 @@
 bled())%0A%09%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09%09//START
@@ -780,16 +780,20 @@
 UI%0A%09%09%09%09%09
+%09
+if(
 Gui.getI
@@ -805,16 +805,33 @@
 ce()
-;%0A%09%09%09%09%09%0A
+ != null)%0A%09%09%09%09%09%09%7B%09%09%09%09%09%0A%09%09
 %09%09%09%09
@@ -879,18 +879,25 @@
 %09%09%09%09
+%09%09
 %7D%0A%09%09%09
+%09
+%09
 %7D%0A%09%09%09
+%09
+%7D 
 catc
@@ -910,21 +910,117 @@
 ption e)
+ %7B
 %0A%09%09%09
-%7B
+%09%09System.out.println(%22GUI ERROR: %22 + e.getMessage());%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%7D catch(Exception e) %7B%0A%09%09%09%09
 %0A%09%09%09%09e.p

fix error if no gui