Skip to content

Commit f864d28

Browse files
committed
Add reset application, Allow selecting intervals in hours or weeks, fix #3, add link to wiki
1 parent 076d6ed commit f864d28

File tree

9 files changed

+76
-19
lines changed

9 files changed

+76
-19
lines changed

.idea/modules/blobsaver.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/blobsaver_main.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/blobsaver_test.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ If you have an antivirus or firewall, you may need to disable some other setting
2323
Please send feedback via [Github Issue](https://github.com/airsquared/blobsaver/issues/new/choose) or [Reddit PM](https://www.reddit.com//message/compose?to=01110101_00101111&subject=Blobsaver+Feedback) if you encounter any bugs/problems or have a feature request.
2424

2525
## TODO:
26+
- Change interval to hours, days, weeks
2627
- Use macOS menu bar
2728
- Package into .app/.exe [maybe this](https://github.com/Jorl17/jar2app)
2829
- New UI (material design?)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'java'
44
}
55

6-
version '2.0'
6+
version '2.1-beta'
77

88
sourceCompatibility = 1.8
99

src/main/java/blobsaver/Background.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,33 @@ static void startBackground() {
135135
}
136136
log("in tray");
137137

138+
TimeUnit timeUnit;
139+
int timeAmount = appPrefs.getInt("Time to run", 1);
140+
switch (appPrefs.get("Time unit for background", "Days")) {
141+
case "Minutes":
142+
timeUnit = TimeUnit.MINUTES;
143+
break;
144+
case "Hours":
145+
timeUnit = TimeUnit.HOURS;
146+
break;
147+
case "Days":
148+
timeUnit = TimeUnit.DAYS;
149+
break;
150+
case "Weeks":
151+
timeUnit = TimeUnit.DAYS;
152+
timeAmount = timeAmount * 7;
153+
break;
154+
default:
155+
timeUnit = TimeUnit.DAYS;
156+
break;
157+
}
138158
executor.scheduleAtFixedRate(() -> {
139159
if (!presetsToSave.isEmpty()) {
140160
log("there are some presets to save");
141161
presetsToSave.forEach(Background::saveBackgroundBlobs);
142162
}
143163
log("done w execution of executor");
144-
}, 0, appPrefs.getInt("Time to run", 7), TimeUnit.DAYS);
164+
}, 0, timeAmount, timeUnit);
145165
executor.scheduleAtFixedRate(() -> checkForUpdates(false), 4, 4, TimeUnit.DAYS);
146166
}
147167

src/main/java/blobsaver/Controller.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javafx.scene.control.*;
3131
import javafx.scene.effect.DropShadow;
3232
import javafx.scene.input.MouseEvent;
33+
import javafx.scene.layout.HBox;
3334
import javafx.scene.layout.VBox;
3435
import javafx.scene.paint.Color;
3536
import javafx.stage.DirectoryChooser;
@@ -48,6 +49,7 @@
4849
import java.net.URL;
4950
import java.util.ArrayList;
5051
import java.util.Arrays;
52+
import java.util.prefs.BackingStoreException;
5153
import java.util.prefs.Preferences;
5254
import java.util.zip.ZipEntry;
5355
import java.util.zip.ZipInputStream;
@@ -254,6 +256,7 @@ public void initialize() {
254256
} else {
255257
path = path + "/Blobs";
256258
}
259+
path = path.replaceAll("%20", " ");
257260
pathField.setText(path);
258261

259262
}
@@ -851,26 +854,36 @@ public void backgroundSettingsHandler() {
851854
}
852855

853856
public void chooseTimeToRunHandler() {
854-
TextInputDialog textInputDialog = new TextInputDialog(Integer.toString(appPrefs.getInt("Time to run", 7)));
855-
textInputDialog.setTitle("Every when should I check new blobs?");
856-
textInputDialog.setHeaderText("Frequency to check");
857-
textInputDialog.setContentText("In days:");
857+
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
858+
alert.setTitle("Frequency to check for new blobs");
859+
alert.setHeaderText("Frequency to check");
860+
TextField textField = new TextField(Integer.toString(appPrefs.getInt("Time to run", 1)));
858861
// make it so user can only enter integers
859-
textInputDialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
862+
textField.textProperty().addListener((observable, oldValue, newValue) -> {
860863
if (!newValue.matches("\\d*")) {
861-
textInputDialog.getEditor().setText(newValue.replaceAll("[^\\d]", ""));
864+
textField.setText(newValue.replaceAll("[^\\d]", ""));
862865
}
863866
});
864-
textInputDialog.showAndWait();
865-
String result = textInputDialog.getResult();
866-
if (result != null && !result.equals("")) {
867-
appPrefs.putInt("Time to run", Integer.valueOf(result));
867+
ChoiceBox<String> choiceBox = new ChoiceBox<>(FXCollections.observableArrayList("Minutes", "Hours", "Days", "Weeks"));
868+
choiceBox.setValue(appPrefs.get("Time unit for background", "Days"));
869+
HBox hBox = new HBox();
870+
hBox.getChildren().addAll(textField, choiceBox);
871+
alert.getDialogPane().setContent(hBox);
872+
alert.showAndWait();
873+
if ((alert.getResult() != null) && !ButtonType.CANCEL.equals(alert.getResult()) && !"".equals(textField.getText()) && (choiceBox.getValue() != null)) {
874+
log("info given");
875+
appPrefs.putInt("Time to run", Integer.valueOf(textField.getText()));
876+
appPrefs.put("Time unit for background", choiceBox.getValue());
877+
} else {
878+
log("alert menu canceled");
879+
backgroundSettingsButton.fire();
880+
return;
868881
}
869882
if (Background.inBackground) {
870883
ButtonType stopBackgroundButtonType = new ButtonType("Stop Background");
871-
Alert alert = new Alert(Alert.AlertType.INFORMATION,
884+
Alert restartBackgroundAlert = new Alert(Alert.AlertType.INFORMATION,
872885
"You will need to restart the background for changes to take effect.", stopBackgroundButtonType);
873-
alert.showAndWait();
886+
restartBackgroundAlert.showAndWait();
874887
startBackgroundButton.fire();
875888
}
876889
}
@@ -915,9 +928,30 @@ public void startBackgroundHandler() {
915928
}
916929
}
917930

931+
public void resetApp() {
932+
try {
933+
Alert confirmationAlert = new Alert(Alert.AlertType.CONFIRMATION, "Are you sure you would like to reset this application to defaults?", ButtonType.NO, ButtonType.YES);
934+
confirmationAlert.showAndWait();
935+
if ((confirmationAlert.getResult() == null) || ButtonType.CANCEL.equals(confirmationAlert.getResult()) || ButtonType.NO.equals(confirmationAlert.getResult())) {
936+
return;
937+
}
938+
Preferences prefs = Preferences.userRoot().node("airsquared/blobsaver");
939+
prefs.flush();
940+
prefs.clear();
941+
prefs.removeNode();
942+
prefs.flush();
943+
Alert applicationCloseAlert = new Alert(Alert.AlertType.INFORMATION, "The application will now exit.", ButtonType.OK);
944+
applicationCloseAlert.showAndWait();
945+
Platform.exit();
946+
System.exit(0);
947+
} catch (BackingStoreException e) {
948+
newReportableError("There was an error resetting the application.", e.getMessage());
949+
}
950+
}
951+
918952
@SuppressWarnings("unused")
919953
private void log(String msg) {
920-
// System.out.println(msg);
954+
System.out.println(msg);
921955
}
922956

923957
public void go() {

src/main/java/blobsaver/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public class Main {
3535

36-
static final String appVersion = "v2.0";
36+
static final String appVersion = "v2.1-beta";
3737
static final Preferences appPrefs = Preferences.userRoot().node("airsquared/blobsaver/prefs");
3838
static Stage primaryStage;
3939

@@ -94,6 +94,7 @@ public void start(Stage primaryStage) throws IOException {
9494
System.exit(0);
9595
}
9696
});
97+
appPrefs.put("App version", appVersion);
9798
}
9899
}
99100
}

src/main/resources/blobsaver/blobsaver.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
text="Check for valid blobs..."/>
2929
<MenuItem mnemonicParsing="false" onAction="#checkForUpdatesHandler"
3030
text="Check for Updates..."/>
31+
<MenuItem mnemonicParsing="false" onAction="#resetApp" text="Clear all data"/>
3132
</Menu>
3233
<Menu mnemonicParsing="false" text="Help">
3334
<MenuItem mnemonicParsing="false" onAction="#newGithubIssue"

0 commit comments

Comments
 (0)