Skip to content

Commit

Permalink
Initialize GUI earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
MichailiK committed Oct 30, 2024
1 parent 7e1734a commit 2444fe6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
10 changes: 3 additions & 7 deletions src/main/java/com/jagrosh/jmusicbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class Bot
private final NowplayingHandler nowplaying;
private final AloneInVoiceHandler aloneInVoiceHandler;
private final YoutubeOauth2TokenHandler youTubeOauth2TokenHandler;
private final GUI gui;

private boolean shuttingDown = false;
private JDA jda;
private GUI gui;

public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings)
public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings, GUI gui)
{
this.waiter = waiter;
this.config = config;
Expand All @@ -66,6 +66,7 @@ public Bot(EventWaiter waiter, BotConfig config, SettingsManager settings)
this.nowplaying.init();
this.aloneInVoiceHandler = new AloneInVoiceHandler(this);
this.aloneInVoiceHandler.init();
this.gui = gui;
}

public BotConfig getConfig()
Expand Down Expand Up @@ -161,9 +162,4 @@ public void setJDA(JDA jda)
{
this.jda = jda;
}

public void setGUI(GUI gui)
{
this.gui = gui;
}
}
34 changes: 18 additions & 16 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,15 @@ private static void startBot()
config.load();
if(!config.isValid())
return;
LOG.info("Loaded config from " + config.getConfigLocation());

// set log level from config
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
Level.toLevel(config.getLogLevel(), Level.INFO));

// set up the listener
EventWaiter waiter = new EventWaiter();
SettingsManager settings = new SettingsManager();
Bot bot = new Bot(waiter, config, settings);
CommandClient client = createCommandClient(config, settings, bot);

GUI gui = null;

if(!prompt.isNoGUI())
{
try
try
{
GUI gui = new GUI(bot);
bot.setGUI(gui);
gui = new GUI();
gui.init();

LOG.info("Loaded config from " + config.getConfigLocation());
}
catch(Exception e)
{
Expand All @@ -113,6 +100,21 @@ private static void startBot()
}
}

LOG.info("Loaded config from " + config.getConfigLocation());

// set log level from config
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
Level.toLevel(config.getLogLevel(), Level.INFO));

// set up the listener
EventWaiter waiter = new EventWaiter();
SettingsManager settings = new SettingsManager();
Bot bot = new Bot(waiter, config, settings, gui);
if (gui != null)
gui.setBot(bot);
CommandClient client = createCommandClient(config, settings, bot);


// attempt to log in and start
try
{
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/jagrosh/jmusicbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
public class GUI extends JFrame
{
private final ConsolePanel console;
private final Bot bot;
private Bot bot;

public GUI(Bot bot)
public GUI()
{
super();
this.bot = bot;
console = new ConsolePanel();
}

public void setBot(Bot bot) {
this.bot = bot;
}

public void init()
{
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Expand All @@ -56,7 +59,8 @@ public void init()
{
try
{
bot.shutdown();
if (bot != null)
bot.shutdown();
}
catch(Exception ex)
{
Expand Down

0 comments on commit 2444fe6

Please sign in to comment.