From 3bf5e656fe35c916dacf444c0f19e168cdfddf67 Mon Sep 17 00:00:00 2001 From: CoocooFroggy Date: Tue, 4 May 2021 14:06:59 -0400 Subject: [PATCH 1/3] - Fix automatic dark mode on Mac - Add an option to manually force light or dark mode --- build.gradle | 2 +- src/main/java/MainMenu.java | 52 ++++++++++----- src/main/java/SettingsMenu.form | 93 ++++++++++++++++++++++----- src/main/java/SettingsMenu.java | 110 +++++++++++++++++++++++++++++--- 4 files changed, 214 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index 901b4f1..87be374 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ dependencies { implementation group: 'org.tukaani', name: 'xz', version: '1.8' implementation group: 'org.rauschig', name: 'jarchivelib', version: '0.7.1' implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13' - implementation 'com.github.Dansoftowner:jSystemThemeDetector:2.1' + implementation 'com.github.Dansoftowner:jSystemThemeDetector:3.6' implementation 'com.github.oshi:oshi-core:5.6.1' implementation group: 'commons-io', name: 'commons-io', version: '2.8.0' } diff --git a/src/main/java/MainMenu.java b/src/main/java/MainMenu.java index ebadfe3..5cb617f 100644 --- a/src/main/java/MainMenu.java +++ b/src/main/java/MainMenu.java @@ -26,7 +26,7 @@ import java.util.regex.Pattern; public class MainMenu { - static String futureRestoreGUIVersion = "1.73"; + static String futureRestoreGUIVersion = "1.74"; private JButton selectBlobFileButton; private JButton selectTargetIPSWFileButton; @@ -439,17 +439,41 @@ public void actionPerformed(ActionEvent e) { static JFrame settingsMenuFrame; public static void main(String[] args) { - final OsThemeDetector detector = OsThemeDetector.getDetector(); - final boolean isDarkThemeUsed = detector.isDark(); - //Must set L&F before we create instance of MainMenu - if (isDarkThemeUsed) { - FlatDarculaLaf.install(); - } else { - //Only set if not Mac - if (!System.getProperty("os.name").toLowerCase().contains("mac")) - FlatIntelliJLaf.install(); + //load and init prefs + initializePreferences(); + + boolean isDarkThemeUsed = false; + switch (properties.getProperty("theme_preference")) { + case "auto": { + final OsThemeDetector detector = OsThemeDetector.getDetector(); + isDarkThemeUsed = detector.isDark(); + //Must set L&F before we create instance of MainMenu + if (isDarkThemeUsed) { + FlatDarculaLaf.install(); + } else { + //Only set if not Mac + if (!System.getProperty("os.name").toLowerCase().contains("mac")) + FlatIntelliJLaf.install(); + } + break; + } + case "light": { + //Good practice + isDarkThemeUsed = false; + //Only set if not Mac + if (!System.getProperty("os.name").toLowerCase().contains("mac")) + FlatIntelliJLaf.install(); + break; + } + case "dark": { + isDarkThemeUsed = true; + FlatDarculaLaf.install(); + break; + } + } + final boolean finalIsDarkThemeUsed = isDarkThemeUsed; SwingUtilities.invokeLater(() -> { mainMenuFrame = new JFrame("FutureRestore GUI"); settingsMenuFrame = new JFrame("Settings"); @@ -471,9 +495,6 @@ public static void main(String[] args) { //Centers it on screen mainMenuFrame.setLocationRelativeTo(null); - //load and init prefs - initializePreferences(); - // init SettingsMenu SettingsMenu.initializeSettingsMenu(settingsMenuInstance); @@ -486,7 +507,7 @@ public static void main(String[] args) { settingsMenuFrame.setLocationRelativeTo(null); //Prepare for dark mode - if (isDarkThemeUsed) + if (finalIsDarkThemeUsed) turnDark(mainMenuInstance); else { //Custom light UI setup @@ -531,7 +552,6 @@ public static void main(String[] args) { } }); - } /*UTILITIES*/ @@ -952,6 +972,8 @@ static void initializePreferences() { properties.setProperty("preview_command", "false"); if (properties.getProperty("check_updates") == null) properties.setProperty("check_updates", "true"); + if (properties.getProperty("theme_preference") == null) + properties.setProperty("theme_preference", "auto"); savePreferences(); } diff --git a/src/main/java/SettingsMenu.form b/src/main/java/SettingsMenu.form index 762307b..d65fff6 100644 --- a/src/main/java/SettingsMenu.form +++ b/src/main/java/SettingsMenu.form @@ -2,14 +2,14 @@
- + - + @@ -18,7 +18,7 @@ - + @@ -27,13 +27,13 @@ - + - + @@ -42,13 +42,13 @@ - + - + @@ -57,7 +57,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -88,7 +88,7 @@ - + @@ -99,21 +99,21 @@ - + - + - + @@ -122,7 +122,7 @@ - + @@ -132,7 +132,7 @@ - + @@ -141,13 +141,72 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/SettingsMenu.java b/src/main/java/SettingsMenu.java index 150b52d..cec2ace 100644 --- a/src/main/java/SettingsMenu.java +++ b/src/main/java/SettingsMenu.java @@ -15,6 +15,9 @@ public class SettingsMenu { private JTextArea discordTextArea; private JCheckBox previewCommandCheckBox; private JCheckBox GUIUpdatesCheckBox; + private JRadioButton autoRadioButton; + private JRadioButton lightRadioButton; + private JRadioButton darkRadioButton; public SettingsMenu() { shareLogsCheckBox.addActionListener(new ActionListener() { @@ -78,6 +81,30 @@ public void actionPerformed(ActionEvent e) { } } }); + + //Changing theme pref + ActionListener listener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JRadioButton buttonPressed = (JRadioButton) e.getSource(); + + //I'm sorry, tried to get a switch statement to work here but nothing was constant it seemed + if (buttonPressed.equals(autoRadioButton)) { + MainMenu.properties.setProperty("theme_preference", "auto"); + MainMenu.savePreferences(); + } else if (buttonPressed.equals(lightRadioButton)) { + MainMenu.properties.setProperty("theme_preference", "light"); + MainMenu.savePreferences(); + } else if (buttonPressed.equals(darkRadioButton)) { + MainMenu.properties.setProperty("theme_preference", "dark"); + MainMenu.savePreferences(); + } + + } + }; + autoRadioButton.addActionListener(listener); + lightRadioButton.addActionListener(listener); + darkRadioButton.addActionListener(listener); } static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { @@ -104,6 +131,13 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { settingsMenuInstance.GUIUpdatesCheckBox.setSelected(true); else settingsMenuInstance.GUIUpdatesCheckBox.setSelected(false); + + //Theme prefs radio buttons + switch (MainMenu.properties.getProperty("theme_preference")) { + case "auto": settingsMenuInstance.autoRadioButton.setSelected(true); break; + case "light": settingsMenuInstance.lightRadioButton.setSelected(true); break; + case "dark": settingsMenuInstance.darkRadioButton.setSelected(true); break; + } } { @@ -129,13 +163,14 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 2; + gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 10, 0, 0); settingsMenuView.add(shareLogsCheckBox, gbc); final JSeparator separator1 = new JSeparator(); separator1.setOrientation(1); gbc = new GridBagConstraints(); - gbc.gridx = 1; + gbc.gridx = 3; gbc.gridy = 2; gbc.gridheight = 2; gbc.fill = GridBagConstraints.BOTH; @@ -144,12 +179,13 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; + gbc.gridwidth = 3; gbc.fill = GridBagConstraints.VERTICAL; settingsMenuView.add(spacer1, gbc); final JLabel label1 = new JLabel(); label1.setText("(Optional) Let us contact you about your logs by providing your Discord"); gbc = new GridBagConstraints(); - gbc.gridx = 2; + gbc.gridx = 4; gbc.gridy = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 0, 0, 10); @@ -157,7 +193,8 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { final JPanel spacer2 = new JPanel(); gbc = new GridBagConstraints(); gbc.gridx = 0; - gbc.gridy = 8; + gbc.gridy = 10; + gbc.gridwidth = 3; gbc.fill = GridBagConstraints.VERTICAL; settingsMenuView.add(spacer2, gbc); previewCommandCheckBox = new JCheckBox(); @@ -165,13 +202,14 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 5; + gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 10, 0, 0); settingsMenuView.add(previewCommandCheckBox, gbc); final JLabel label2 = new JLabel(); label2.setText("See a preview of the final command before it runs"); gbc = new GridBagConstraints(); - gbc.gridx = 2; + gbc.gridx = 4; gbc.gridy = 5; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 0, 0, 10); @@ -183,13 +221,14 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 3; + gbc.gridwidth = 3; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(0, 10, 0, 0); settingsMenuView.add(discordTextArea, gbc); final JLabel label3 = new JLabel(); label3.setText("Automatically share logs to help make FutureRestore better"); gbc = new GridBagConstraints(); - gbc.gridx = 2; + gbc.gridx = 4; gbc.gridy = 2; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 0, 0, 10); @@ -202,6 +241,7 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; + gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.insets = new Insets(10, 10, 0, 0); settingsMenuView.add(label4, gbc); @@ -209,20 +249,20 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 4; - gbc.gridwidth = 3; + gbc.gridwidth = 5; gbc.fill = GridBagConstraints.BOTH; settingsMenuView.add(separator2, gbc); final JSeparator separator3 = new JSeparator(); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 6; - gbc.gridwidth = 3; + gbc.gridwidth = 5; gbc.fill = GridBagConstraints.BOTH; settingsMenuView.add(separator3, gbc); final JSeparator separator4 = new JSeparator(); separator4.setOrientation(1); gbc = new GridBagConstraints(); - gbc.gridx = 1; + gbc.gridx = 3; gbc.gridy = 5; gbc.fill = GridBagConstraints.BOTH; settingsMenuView.add(separator4, gbc); @@ -232,13 +272,14 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 7; + gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 10, 0, 0); settingsMenuView.add(GUIUpdatesCheckBox, gbc); final JLabel label5 = new JLabel(); label5.setText("Automatically check for updates for FutureRestore GUI"); gbc = new GridBagConstraints(); - gbc.gridx = 2; + gbc.gridx = 4; gbc.gridy = 7; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 0, 0, 10); @@ -246,10 +287,59 @@ static void initializeSettingsMenu(SettingsMenu settingsMenuInstance) { final JSeparator separator5 = new JSeparator(); separator5.setOrientation(1); gbc = new GridBagConstraints(); - gbc.gridx = 1; + gbc.gridx = 3; gbc.gridy = 7; gbc.fill = GridBagConstraints.BOTH; settingsMenuView.add(separator5, gbc); + autoRadioButton = new JRadioButton(); + autoRadioButton.setText("Auto"); + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 9; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(0, 10, 0, 0); + settingsMenuView.add(autoRadioButton, gbc); + lightRadioButton = new JRadioButton(); + lightRadioButton.setText("Light"); + gbc = new GridBagConstraints(); + gbc.gridx = 1; + gbc.gridy = 9; + gbc.anchor = GridBagConstraints.WEST; + settingsMenuView.add(lightRadioButton, gbc); + darkRadioButton = new JRadioButton(); + darkRadioButton.setText("Dark"); + gbc = new GridBagConstraints(); + gbc.gridx = 2; + gbc.gridy = 9; + gbc.anchor = GridBagConstraints.WEST; + settingsMenuView.add(darkRadioButton, gbc); + final JSeparator separator6 = new JSeparator(); + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 8; + gbc.gridwidth = 5; + gbc.fill = GridBagConstraints.BOTH; + settingsMenuView.add(separator6, gbc); + final JSeparator separator7 = new JSeparator(); + separator7.setOrientation(1); + gbc = new GridBagConstraints(); + gbc.gridx = 3; + gbc.gridy = 9; + gbc.fill = GridBagConstraints.BOTH; + settingsMenuView.add(separator7, gbc); + final JLabel label6 = new JLabel(); + label6.setText("Set the theme of the GUI. Requires a restart to take effect."); + gbc = new GridBagConstraints(); + gbc.gridx = 4; + gbc.gridy = 9; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(0, 0, 0, 10); + settingsMenuView.add(label6, gbc); + ButtonGroup buttonGroup; + buttonGroup = new ButtonGroup(); + buttonGroup.add(autoRadioButton); + buttonGroup.add(lightRadioButton); + buttonGroup.add(darkRadioButton); } /** From 331fc678584fb88e1972eccf8fa5eb36170ce34d Mon Sep 17 00:00:00 2001 From: CoocooFroggy Date: Tue, 4 May 2021 14:27:35 -0400 Subject: [PATCH 2/3] - Better regex --- src/main/java/MainMenu.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/MainMenu.java b/src/main/java/MainMenu.java index 5cb617f..bec34c9 100644 --- a/src/main/java/MainMenu.java +++ b/src/main/java/MainMenu.java @@ -215,7 +215,7 @@ public MainMenu() { } //If blob name has a build number in it - Pattern blobPattern = Pattern.compile(".*([A-Z0-9]{5})_"); + Pattern blobPattern = Pattern.compile("(?<=_|-)[A-Z0-9]{5,10}[a-z]?(?=_|-)"); Matcher blobMatcher = blobPattern.matcher(blobName); String blobBuild = null; if (blobMatcher.find()) { @@ -224,7 +224,7 @@ public MainMenu() { } //If IPSW has a build name in it - Pattern ipswPattern = Pattern.compile(".*_([A-Z0-9]{5})"); + Pattern ipswPattern = Pattern.compile("(?<=_|-)[A-Z0-9]{5,10}[a-z]?(?=_|-)"); Matcher ipswMatcher = ipswPattern.matcher(targetIpswName); String targetIpswBuild = null; if (ipswMatcher.find()) { @@ -295,6 +295,7 @@ public MainMenu() { runCommand(new ArrayList<>(Arrays.asList("--exit-recovery")), false); }); + basebandComboBox.addActionListener(e -> { switch (basebandComboBox.getSelectedItem().toString()) { case "Latest Baseband": From c0a74244882e97b124fdaef08d5a4083e8eacff2 Mon Sep 17 00:00:00 2001 From: CoocooFroggy Date: Tue, 4 May 2021 14:39:03 -0400 Subject: [PATCH 3/3] - Better regex (fix for group) --- src/main/java/MainMenu.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/MainMenu.java b/src/main/java/MainMenu.java index bec34c9..3b1d997 100644 --- a/src/main/java/MainMenu.java +++ b/src/main/java/MainMenu.java @@ -219,8 +219,8 @@ public MainMenu() { Matcher blobMatcher = blobPattern.matcher(blobName); String blobBuild = null; if (blobMatcher.find()) { - System.out.println("Blob build is " + blobMatcher.group(1)); - blobBuild = blobMatcher.group(1); +// System.out.println("Blob build is " + blobMatcher.group(0)); + blobBuild = blobMatcher.group(0); } //If IPSW has a build name in it @@ -228,8 +228,8 @@ public MainMenu() { Matcher ipswMatcher = ipswPattern.matcher(targetIpswName); String targetIpswBuild = null; if (ipswMatcher.find()) { - System.out.println("IPSW build is " + ipswMatcher.group(1)); - targetIpswBuild = ipswMatcher.group(1); +// System.out.println("IPSW build is " + ipswMatcher.group(0)); + targetIpswBuild = ipswMatcher.group(0); } //If they're different