Skip to content

Commit 6d6eeef

Browse files
committed
minor code cleanup
1 parent 577ad44 commit 6d6eeef

File tree

5 files changed

+34
-83
lines changed

5 files changed

+34
-83
lines changed

src/main/java/com/airsquared/blobsaver/Background.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ static void startBackground(boolean runOnlyOnce) {
128128
// add the application tray icon to the system tray.
129129
try {
130130
tray.add(trayIcon);
131-
log("in tray");
131+
System.out.println("in tray");
132132
} catch (AWTException e) {
133133
e.printStackTrace();
134134
}
135135
}
136136
if (runOnlyOnce) {
137137
if (!presetsToSave.isEmpty()) {
138-
log("there are some presets to save");
138+
System.out.println("there are some presets to save");
139139
presetsToSave.forEach(Background::saveBackgroundBlobs);
140140
}
141141
inBackground = false;
@@ -162,25 +162,24 @@ static void startBackground(boolean runOnlyOnce) {
162162
}
163163
executor.scheduleAtFixedRate(() -> {
164164
if (!presetsToSave.isEmpty()) {
165-
log("there are some presets to save");
165+
System.out.println("there are some presets to save");
166166
presetsToSave.forEach(Background::saveBackgroundBlobs);
167167
}
168-
log("done w execution of executor");
168+
System.out.println("done with executor");
169169
}, 0, timeAmount, timeUnit);
170170
executor.scheduleAtFixedRate(() -> checkForUpdates(false), 4, 4, TimeUnit.DAYS);
171171
}
172172
}
173173

174174
private static void saveBackgroundBlobs(int preset) {
175-
log("attempting to save for preset " + preset);
175+
System.out.println("attempting to save for preset " + preset);
176176
Preferences presetPrefs = Preferences.userRoot().node("airsquared/blobsaver/preset" + preset);
177177
String identifier;
178178
if ("none".equals(presetPrefs.get("Device Model", ""))) {
179179
identifier = presetPrefs.get("Device Identifier", "");
180180
} else {
181181
identifier = textToIdentifier(presetPrefs.get("Device Model", ""));
182182
}
183-
log("identifier:" + identifier);
184183
List<Map<String, Object>> signedFirmwares;
185184
try {
186185
signedFirmwares = getAllSignedFirmwares(identifier);
@@ -259,7 +258,7 @@ private static void saveBackgroundBlobs(int preset) {
259258
});
260259
Notification.Notifier.INSTANCE.notify(notification);
261260

262-
log("displayed message");
261+
System.out.println("displayed message");
263262

264263
} else if (containsIgnoreCase(tsscheckerLog, "Could not resolve host")) {
265264
Notification notification = new Notification("Saving blobs failed", "Check your internet connection. If it is working, click here to report this error.", Notification.ERROR_ICON);
@@ -293,7 +292,7 @@ private static void saveBackgroundBlobs(int preset) {
293292
});
294293
Notification.Notifier.INSTANCE.notify(notification);
295294
}
296-
log("it worked");
295+
System.out.println("Success");
297296
}
298297
}
299298

@@ -313,10 +312,6 @@ static void stopBackground(boolean showAlert) {
313312
alert.showAndWait();
314313
});
315314
}
316-
log("stopped background");
317-
}
318-
319-
private static void log(String msg) {
320-
System.out.println(msg);
315+
System.out.println("Stopped background");
321316
}
322317
}

src/main/java/com/airsquared/blobsaver/Controller.java

+13-63
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public class Controller {
9898
private boolean editingPresets = false;
9999
private boolean choosingRunInBackground = false;
100100

101-
static DropShadow errorBorder = new DropShadow();
102-
private static DropShadow borderGlow = new DropShadow();
101+
static DropShadow errorBorder = new DropShadow(9.5, 0f, 0f, Color.RED);
102+
private static DropShadow borderGlow = new DropShadow(9.5, 0f, 0f, Color.DARKCYAN);
103103

104104
static Controller INSTANCE;
105105

@@ -117,19 +117,6 @@ static void afterStageShowing() {
117117
@FXML
118118
public void initialize() {
119119
INSTANCE = this;
120-
// create effects
121-
borderGlow.setOffsetY(0f);
122-
borderGlow.setOffsetX(0f);
123-
borderGlow.setColor(Color.DARKCYAN);
124-
borderGlow.setWidth(20);
125-
borderGlow.setHeight(20);
126-
errorBorder.setOffsetY(0f);
127-
errorBorder.setOffsetX(0f);
128-
errorBorder.setColor(Color.RED);
129-
errorBorder.setWidth(20);
130-
errorBorder.setHeight(20);
131-
132-
deviceTypeChoiceBox.setItems(FXCollections.observableArrayList(Devices.getDeviceTypes()));
133120

134121
deviceTypeChoiceBox.getSelectionModel().selectedItemProperty().addListener((x, y, newValue) -> {
135122
deviceTypeChoiceBox.setEffect(null);
@@ -170,20 +157,8 @@ public void initialize() {
170157
presetButtons = new ArrayList<>(Arrays.asList(preset1Button, preset2Button, preset3Button, preset4Button, preset5Button, preset6Button, preset7Button, preset8Button, preset9Button, preset10Button));
171158
presetButtons.forEach(btn -> btn.setOnAction(this::presetButtonHandler));
172159

173-
// the following is to set the path to save blobs to the correct location
174-
String path = Main.jarDirectory.getAbsolutePath();
175-
if (path.endsWith("blobsaver.app/Contents/Java")) {
176-
path = path.replaceAll("blobsaver\\.app/Contents/Java", "");
177-
}
178-
if (path.contains("\\Program Files") || path.contains("/Applications")) {
179-
path = System.getProperty("user.home");
180-
}
181-
if (path.endsWith(System.getProperty("file.separator"))) {
182-
path = path + "Blobs";
183-
} else {
184-
path = path + System.getProperty("file.separator") + "Blobs";
185-
}
186-
pathField.setText(path);
160+
161+
pathField.setText(new File(System.getProperty("user.home"), "Blobs").getAbsolutePath());
187162

188163

189164
if (PlatformUtil.isMac()) {
@@ -250,7 +225,6 @@ public void versionCheckBoxHandler() {
250225
versionField.setText("");
251226
} else {
252227
versionField.setEffect(borderGlow);
253-
254228
versionField.setDisable(false);
255229
}
256230
}
@@ -367,12 +341,12 @@ private void presetButtonHandler(ActionEvent evt) {
367341
if (presetsToSaveFor.isEmpty()) {
368342
appPrefs.putBoolean("Background setup", false);
369343
}
370-
log("removed " + preset + " from list");
344+
System.out.println("removed " + preset + " from list");
371345
backgroundSettingsButton.fire();
372346
} else {
373347
presetsToSaveFor.add(Integer.toString(preset));
374348
appPrefs.putBoolean("Background setup", true);
375-
log("added preset" + preset + " to list");
349+
System.out.println("added preset" + preset + " to list");
376350
Alert alert = new Alert(Alert.AlertType.INFORMATION, "If it doesn't work, please remove it, fix the error, and add it back");
377351
alert.setTitle("Testing preset " + preset);
378352
alert.setHeaderText("Testing preset");
@@ -657,7 +631,7 @@ private void useMacOSMenuBar() {
657631

658632
// needs to be run with Platform.runLater(), otherwise the application menu doesn't show up
659633
Platform.runLater(() -> tk.setGlobalMenuBar(macOSMenuBar));
660-
log("using macOS menu bar");
634+
System.out.println("using macOS menu bar");
661635
}
662636

663637
public void backgroundSettingsHandler() {
@@ -733,11 +707,9 @@ public void chooseTimeToRunHandler() {
733707
alert.getDialogPane().setContent(hBox);
734708
alert.showAndWait();
735709
if ((alert.getResult() != null) && !ButtonType.CANCEL.equals(alert.getResult()) && !"".equals(textField.getText()) && (choiceBox.getValue() != null)) {
736-
log("info given");
737710
appPrefs.putInt("Time to run", Integer.parseInt(textField.getText()));
738711
appPrefs.put("Time unit for background", choiceBox.getValue());
739712
} else {
740-
log("alert menu canceled");
741713
backgroundSettingsButton.fire(); //goes back to main menu
742714
return;
743715
}
@@ -797,8 +769,6 @@ public void resetAppHandler() {
797769
prefs.clear();
798770
prefs.removeNode();
799771
prefs.flush();
800-
File blobsaver_bin = new File(System.getProperty("user.home"), ".blobsaver_bin");
801-
deleteFolder(blobsaver_bin);
802772
Alert applicationCloseAlert = new Alert(Alert.AlertType.INFORMATION, "The application data and files have been removed. If you are running Windows, you still will need to run the uninstall .exe. Otherwise, you can just delete the .app or .jar file.\nThe application will now exit.", ButtonType.OK);
803773
applicationCloseAlert.showAndWait();
804774
Platform.exit();
@@ -807,22 +777,6 @@ public void resetAppHandler() {
807777
}
808778
}
809779

810-
@SuppressWarnings("ResultOfMethodCallIgnored")
811-
private static void deleteFolder(File folder) {
812-
if (folder.exists()) {
813-
File[] files = folder.listFiles();
814-
if (files != null) {
815-
Arrays.asList(files).forEach(file -> {
816-
if (file.isDirectory()) {
817-
deleteFolder(file);
818-
} else {
819-
file.delete();
820-
}
821-
});
822-
}
823-
}
824-
}
825-
826780
public void debugLogHandler() {
827781
if (DebugWindow.isShowing()) {
828782
DebugWindow.hide();
@@ -907,8 +861,6 @@ public void readInfo() {
907861

908862
public void donate() { openURL("https://www.paypal.me/airsqrd"); }
909863

910-
private static void log(String msg) { System.out.println(msg); }
911-
912864
@SuppressWarnings("Duplicates")
913865
public void goButtonHandler() {
914866
boolean doReturn = false;
@@ -928,22 +880,20 @@ public void goButtonHandler() {
928880
doReturn = doReturn || isTextFieldInvalid(!versionCheckBox.isSelected(), versionField);
929881
doReturn = doReturn || isTextFieldInvalid(betaCheckBox, buildIDField);
930882
doReturn = doReturn || isTextFieldInvalid(betaCheckBox, ipswField);
931-
if (doReturn) {
932-
return;
933-
}
883+
if (doReturn) return;
884+
934885
String deviceModel = (String) deviceModelChoiceBox.getValue();
935886
if ("".equals(deviceModel)) {
936887
String identifierText = identifierField.getText();
937888
try {
938889
if (identifierText.startsWith("iPad") || identifierText.startsWith("iPod") || identifierText.startsWith("iPhone") || identifierText.startsWith("AppleTV")) {
939890
TSSChecker.run(identifierText);
940-
} else {
941-
identifierField.setEffect(errorBorder);
942-
newUnreportableError("\"" + identifierText + "\" is not a valid identifier");
891+
return;
943892
}
944-
} catch (StringIndexOutOfBoundsException e) {
945-
newUnreportableError("\"" + identifierText + "\" is not a valid identifier");
893+
} catch (StringIndexOutOfBoundsException ignored) {
946894
}
895+
identifierField.setEffect(errorBorder);
896+
newUnreportableError("\"" + identifierText + "\" is not a valid identifier");
947897
} else {
948898
TSSChecker.run(textToIdentifier(deviceModel));
949899
}

src/main/java/com/airsquared/blobsaver/Devices.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.Map;
2727
import java.util.Properties;
2828

29-
class Devices {
29+
public class Devices {
3030

3131
private static final ObservableList<String> iPhones = FXCollections.observableArrayList("iPhone 3G[S]", "iPhone 4 (GSM)",
3232
"iPhone 4 (GSM 2012)", "iPhone 4 (CDMA)", "iPhone 4[S]", "iPhone 5 (GSM)", "iPhone 5 (Global)",
@@ -91,7 +91,7 @@ static ObservableList<String> getAppleTVs() {
9191
return AppleTVs;
9292
}
9393

94-
static ObservableList<String> getDeviceTypes() {
94+
public static ObservableList<String> getDeviceTypes() {
9595
return deviceTypes;
9696
}
9797

src/main/java/com/airsquared/blobsaver/Main.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,13 @@ static void showStage() {
9595
if (PlatformUtil.isMac()) {
9696
DockVisibility.show();
9797
}
98-
System.out.println(1);
9998
try {
10099
primaryStage.show();
101100
} catch (Throwable t) {
102101
t.printStackTrace();
103102
}
104-
System.out.println(2);
105103
primaryStage.centerOnScreen();
106-
System.out.println(3);
107104
primaryStage.requestFocus();
108-
System.out.println(4);
109105
}
110106

111107
static void hideStage() {
@@ -153,7 +149,13 @@ public void init() {
153149
@SuppressWarnings("unchecked")
154150
public void start(Stage primaryStage) throws IOException, ReflectiveOperationException {
155151
Main.primaryStage = primaryStage;
156-
Parent root = FXMLLoader.load(getClass().getResource("blobsaver.fxml"));
152+
Parent root = null;
153+
try {
154+
root = FXMLLoader.load(getClass().getResource("blobsaver.fxml"));
155+
} catch (Exception e) {
156+
e.printStackTrace();
157+
System.exit(-1);
158+
}
157159
primaryStage.setTitle("blobsaver " + Main.appVersion);
158160
primaryStage.setScene(new Scene(root));
159161
primaryStage.getScene().getStylesheets().add(getClass().getResource("app.css").toExternalForm());

src/main/resources/com/airsquared/blobsaver/blobsaver.fxml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
~ along with blobsaver. If not, see <https://www.gnu.org/licenses/>.
1919
-->
2020

21+
<?import com.airsquared.blobsaver.Devices?>
2122
<?import javafx.geometry.*?>
2223
<?import javafx.scene.control.*?>
2324
<?import javafx.scene.layout.*?>
@@ -119,6 +120,9 @@
119120
<HBox.margin>
120121
<Insets left="10.0"/>
121122
</HBox.margin>
123+
<items>
124+
<Devices fx:factory="getDeviceTypes"/>
125+
</items>
122126
</ChoiceBox>
123127
<ChoiceBox fx:id="deviceModelChoiceBox" prefWidth="150.0">
124128
<HBox.margin>

0 commit comments

Comments
 (0)