Skip to content

Commit

Permalink
Implement remembering the first time user selection
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 22, 2023
1 parent 5662a1d commit e3f9728
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Properties;

public class GUIClientProps {
Expand All @@ -37,6 +38,10 @@ private GUIClientProps() {
}

public static void loadSettings() {
if (!Files.exists(SETTINGS_PATH)) {
return;
}

try (var is = Files.newInputStream(SETTINGS_PATH)) {
SETTINGS.load(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (Exception e) {
Expand All @@ -45,7 +50,7 @@ public static void loadSettings() {
}

public static void saveSettings() {
try (var os = Files.newOutputStream(SETTINGS_PATH)) {
try (var os = Files.newOutputStream(SETTINGS_PATH, StandardOpenOption.CREATE)) {
SETTINGS.store(new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)), "ServerWrecker GUI Settings");
} catch (Exception e) {
e.printStackTrace();
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/net/pistonmaster/serverwrecker/gui/GUIFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import net.pistonmaster.serverwrecker.gui.libs.HintManager;
import net.pistonmaster.serverwrecker.gui.navigation.CardsContainer;
import net.pistonmaster.serverwrecker.gui.navigation.ControlPanel;
import net.pistonmaster.serverwrecker.util.TimeUtil;

import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

public class GUIFrame extends JFrame {
public static final String MAIN_MENU = "MainMenu";
Expand Down Expand Up @@ -63,6 +65,11 @@ public void initComponents(Injector injector) {
public void open(Injector injector) {
setVisible(true);

if (GUIClientProps.getBoolean("firstTimeUser", false)) {
SwingUtilities.invokeLater(() -> showHints(injector));
return;
}

if (GUIClientProps.getBoolean("firstRun", true)) {
var result = JOptionPane.showConfirmDialog(
this,
Expand All @@ -71,7 +78,11 @@ public void open(Injector injector) {
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
showHints(injector);
GUIClientProps.setBoolean("firstTimeUser", true);

// Give the window a bit of time to close
TimeUtil.waitTime(50, TimeUnit.MILLISECONDS);
SwingUtilities.invokeLater(() -> showHints(injector));
}

GUIClientProps.setBoolean("firstRun", false);
Expand Down Expand Up @@ -117,6 +128,6 @@ public void showHints(Injector injector) {
logPanel,
SwingConstants.LEFT, "hint.logPanel", settingsHint);

SwingUtilities.invokeLater(() -> HintManager.showHint(logsHint));
HintManager.showHint(logsHint);
}
}

0 comments on commit e3f9728

Please sign in to comment.