Skip to content

Commit bb73b33

Browse files
committed
Button to force check for blobs, minor changes
1 parent f864d28 commit bb73b33

File tree

5 files changed

+121
-81
lines changed

5 files changed

+121
-81
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you have an antivirus or firewall, you may need to disable some other setting
99
![Windows Screenshot](https://i.imgur.com/zlPh4JY.png)
1010

1111
## Features
12-
- **Automatically saves blobs in the background**
12+
- **Automatically save blobs in the background**
1313
- Store up to ten devices with presets
1414
- Choose where to save blobs with file picker
1515
- Save blobs for beta versions
@@ -23,10 +23,12 @@ 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
26+
- Allow only one instance
27+
- Debug log/window
2728
- Use macOS menu bar
29+
- Auto-upload to Dropbox/Google Drive
2830
- Package into .app/.exe [maybe this](https://github.com/Jorl17/jar2app)
29-
- New UI (material design?)
31+
- Better notifications
3032

3133
## Built With
3234
- JDK 8

src/main/java/blobsaver/Background.java

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Background {
6565
private static ScheduledExecutorService executor;
6666
private static TrayIcon trayIcon;
6767

68-
static void startBackground() {
68+
static void startBackground(boolean runOnlyOnce) {
6969
ArrayList<Integer> presetsToSave = new ArrayList<>();
7070
JSONArray presetsToSaveJson = new JSONArray(appPrefs.get("Presets to save in background", "[]"));
7171
for (int i = 0; i < presetsToSaveJson.length(); i++) {
@@ -78,95 +78,102 @@ static void startBackground() {
7878
inBackground = false;
7979
return;
8080
}
81-
if (Platform.isFxApplicationThread()) {
81+
if (!runOnlyOnce && Platform.isFxApplicationThread()) {
8282
Main.primaryStage.hide();
8383
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.seconds(30));
8484
Notification.Notifier.INSTANCE.notifyInfo("Background process has started", "Check your system tray/status bar for\nthe icon."
8585
+ presetsToSaveNames.toString().substring(1, presetsToSaveNames.toString().length() - 1));
86-
} else {
86+
} else if (!runOnlyOnce) {
8787
Platform.runLater(() -> {
8888
Main.primaryStage.hide();
8989
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.seconds(30));
9090
Notification.Notifier.INSTANCE.notifyInfo("Background process has started", "Check your system tray/status bar for the icon.\n"
9191
+ presetsToSaveNames.toString().substring(1, presetsToSaveNames.toString().length() - 1));
9292
});
9393
}
94+
if (!runOnlyOnce) {
95+
inBackground = true;
96+
executor = Executors.newScheduledThreadPool(1);
97+
SystemTray tray = SystemTray.getSystemTray();
9498

95-
inBackground = true;
96-
executor = Executors.newScheduledThreadPool(1);
97-
SystemTray tray = SystemTray.getSystemTray();
98-
99-
Image image = null;
100-
try {
101-
image = ImageIO.read(Background.class.getResourceAsStream("blob_emoji.png"));
102-
} catch (IOException e) {
103-
e.printStackTrace();
104-
}
99+
Image image = null;
100+
try {
101+
image = ImageIO.read(Background.class.getResourceAsStream("blob_emoji.png"));
102+
} catch (IOException e) {
103+
e.printStackTrace();
104+
}
105105

106-
//noinspection ConstantConditions
107-
trayIcon = new TrayIcon(image, "blobsaver " + Main.appVersion);
108-
trayIcon.setImageAutoSize(true);
106+
//noinspection ConstantConditions
107+
trayIcon = new TrayIcon(image, "blobsaver " + Main.appVersion);
108+
trayIcon.setImageAutoSize(true);
109109

110-
MenuItem openItem = new MenuItem("Open window");
111-
openItem.addActionListener((evt) -> Platform.runLater(Background::showStage));
112-
openItem.setFont(Font.decode(null).deriveFont(java.awt.Font.BOLD)); // bold it
110+
MenuItem openItem = new MenuItem("Open window");
111+
openItem.addActionListener((evt) -> Platform.runLater(Background::showStage));
112+
openItem.setFont(Font.decode(null).deriveFont(java.awt.Font.BOLD)); // bold it
113113

114-
MenuItem exitItem = new MenuItem("Quit");
115-
exitItem.addActionListener(event -> {
116-
executor.shutdownNow();
117-
Platform.runLater(Platform::exit);
118-
tray.remove(trayIcon);
119-
System.exit(0);
120-
});
114+
MenuItem exitItem = new MenuItem("Quit");
115+
exitItem.addActionListener(event -> {
116+
executor.shutdownNow();
117+
Platform.runLater(Platform::exit);
118+
tray.remove(trayIcon);
119+
System.exit(0);
120+
});
121121

122-
// setup the popup menu for the application.
123-
final PopupMenu popup = new PopupMenu();
124-
popup.add(openItem);
125-
popup.addSeparator();
126-
popup.add(exitItem);
127-
trayIcon.setPopupMenu(popup);
122+
// setup the popup menu for the application.
123+
final PopupMenu popup = new PopupMenu();
124+
popup.add(openItem);
125+
popup.addSeparator();
126+
popup.add(exitItem);
127+
trayIcon.setPopupMenu(popup);
128128

129129

130-
// add the application tray icon to the system tray.
131-
try {
132-
tray.add(trayIcon);
133-
} catch (AWTException e) {
134-
e.printStackTrace();
135-
}
136-
log("in tray");
137-
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;
130+
// add the application tray icon to the system tray.
131+
try {
132+
tray.add(trayIcon);
133+
log("in tray");
134+
} catch (AWTException e) {
135+
e.printStackTrace();
136+
}
157137
}
158-
executor.scheduleAtFixedRate(() -> {
138+
if (runOnlyOnce) {
159139
if (!presetsToSave.isEmpty()) {
160140
log("there are some presets to save");
161141
presetsToSave.forEach(Background::saveBackgroundBlobs);
162142
}
163-
log("done w execution of executor");
164-
}, 0, timeAmount, timeUnit);
165-
executor.scheduleAtFixedRate(() -> checkForUpdates(false), 4, 4, TimeUnit.DAYS);
143+
inBackground = false;
144+
} else {
145+
TimeUnit timeUnit;
146+
int timeAmount = appPrefs.getInt("Time to run", 1);
147+
switch (appPrefs.get("Time unit for background", "Days")) {
148+
case "Minutes":
149+
timeUnit = TimeUnit.MINUTES;
150+
break;
151+
case "Hours":
152+
timeUnit = TimeUnit.HOURS;
153+
break;
154+
case "Days":
155+
timeUnit = TimeUnit.DAYS;
156+
break;
157+
case "Weeks":
158+
timeUnit = TimeUnit.DAYS;
159+
timeAmount = timeAmount * 7;
160+
break;
161+
default:
162+
timeUnit = TimeUnit.DAYS;
163+
break;
164+
}
165+
executor.scheduleAtFixedRate(() -> {
166+
if (!presetsToSave.isEmpty()) {
167+
log("there are some presets to save");
168+
presetsToSave.forEach(Background::saveBackgroundBlobs);
169+
}
170+
log("done w execution of executor");
171+
}, 0, timeAmount, timeUnit);
172+
executor.scheduleAtFixedRate(() -> checkForUpdates(false), 4, 4, TimeUnit.DAYS);
173+
}
166174
}
167175

168176
private static void saveBackgroundBlobs(int preset) {
169-
170177
log("attempting to save for " + preset);
171178
Preferences presetPrefs = Preferences.userRoot().node("airsquared/blobsaver/preset" + preset);
172179
// presetPrefs.put("Saved Versions", "[]"); // for testing
@@ -442,6 +449,6 @@ private static void deleteTempFiles(File tsschecker) {
442449

443450
@SuppressWarnings("unused")
444451
private static void log(String msg) {
445-
// System.out.println(msg);
452+
System.out.println(msg);
446453
}
447454
}

src/main/java/blobsaver/Controller.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.sun.javafx.PlatformUtil;
2222
import com.sun.javafx.scene.control.skin.LabeledText;
23-
import eu.hansolo.enzo.notification.Notification;
2423
import javafx.application.Platform;
2524
import javafx.beans.value.ObservableValue;
2625
import javafx.collections.FXCollections;
@@ -86,6 +85,7 @@ public class Controller {
8685

8786
@FXML private Button startBackgroundButton;
8887
@FXML private Button chooseTimeToRunButton;
88+
@FXML private Button forceCheckForBlobs;
8989
@FXML private Button backgroundSettingsButton;
9090
@FXML private Button savePresetButton;
9191
@FXML private Button preset1Button;
@@ -578,12 +578,18 @@ private void presetButtonHandler(ActionEvent evt) {
578578
}
579579
if (btn.getText().startsWith("Cancel ")) {
580580
presetsToSaveFor.remove(Integer.toString(preset));
581+
if (presetsToSaveFor.isEmpty()) {
582+
appPrefs.putBoolean("Background setup", false);
583+
}
581584
log("removed " + preset + " from list");
582585
backgroundSettingsButton.fire();
583586
} else {
584587
presetsToSaveFor.add(Integer.toString(preset));
588+
appPrefs.putBoolean("Background setup", true);
585589
log("added preset" + preset + " to list");
586-
Notification.Notifier.INSTANCE.notifyInfo("Testing preset to make sure it works", "If it doesn't, please\nremove and fix the error.");
590+
Alert alert = new Alert(Alert.AlertType.INFORMATION, "If it doesn't work, please remove it, fix the error, and add it back");
591+
alert.setTitle("Testing preset " + preset);
592+
alert.setHeaderText("Testing preset");
587593
backgroundSettingsButton.fire();
588594
btn.fire();
589595
goButton.fire();
@@ -651,18 +657,20 @@ private void savePreset(int preset) {
651657
public void savePresetHandler() {
652658
editingPresets = !editingPresets;
653659
if (editingPresets) {
654-
savePresetButton.setText("Cancel");
660+
savePresetButton.setText("Back");
655661
presetVBox.setEffect(borderGlow);
656662
presetButtons.forEach((Button btn) -> btn.setText("Save in " + btn.getText().substring("Load ".length())));
657663
goButton.setDefaultButton(false);
658664
goButton.setDisable(true);
659-
backgroundSettingsButton.setDisable(true);
665+
backgroundSettingsButton.setVisible(false);
666+
backgroundSettingsButton.setManaged(false);
660667
savePresetButton.setDefaultButton(true);
661668
} else {
662669
savePresetButton.setDefaultButton(false);
663670
goButton.setDefaultButton(true);
664671
goButton.setDisable(false);
665-
backgroundSettingsButton.setDisable(false);
672+
backgroundSettingsButton.setVisible(true);
673+
backgroundSettingsButton.setManaged(true);
666674
presetVBox.setEffect(null);
667675
savePresetButton.setText("Save");
668676
presetButtons.forEach((Button btn) -> btn.setText("Load " + btn.getText().substring("Save in ".length())));
@@ -811,7 +819,7 @@ public void aboutMenuHandler() {
811819
public void backgroundSettingsHandler() {
812820
choosingRunInBackground = !choosingRunInBackground;
813821
if (choosingRunInBackground) {
814-
backgroundSettingsButton.setText("Cancel");
822+
backgroundSettingsButton.setText("Back");
815823
presetVBox.setEffect(borderGlow);
816824
presetButtons.forEach((btn) -> {
817825
ArrayList<String> presetsToSaveFor = new ArrayList<>();
@@ -831,15 +839,24 @@ public void backgroundSettingsHandler() {
831839
goButton.setDefaultButton(false);
832840
goButton.setDisable(true);
833841
savePresetButton.setDisable(true);
842+
savePresetButton.setVisible(false);
843+
savePresetButton.setManaged(false);
834844
backgroundSettingsButton.setDefaultButton(true);
835845
chooseTimeToRunButton.setVisible(true);
846+
forceCheckForBlobs.setVisible(true);
836847
startBackgroundButton.setVisible(true);
848+
if (appPrefs.getBoolean("Background setup", false)) {
849+
startBackgroundButton.setDisable(true);
850+
forceCheckForBlobs.setDisable(true);
851+
}
837852
} else {
838853
backgroundSettingsButton.setDefaultButton(false);
839854
goButton.setDefaultButton(true);
840855
goButton.setDisable(false);
841856
presetVBox.setEffect(null);
842857
savePresetButton.setDisable(false);
858+
savePresetButton.setVisible(true);
859+
savePresetButton.setManaged(true);
843860
backgroundSettingsButton.setText("Background settings");
844861
presetButtons.forEach((btn) -> {
845862
if (btn.getText().startsWith("Cancel ")) {
@@ -849,6 +866,9 @@ public void backgroundSettingsHandler() {
849866
}
850867
});
851868
chooseTimeToRunButton.setVisible(false);
869+
forceCheckForBlobs.setDisable(false);
870+
forceCheckForBlobs.setVisible(false);
871+
startBackgroundButton.setDisable(false);
852872
startBackgroundButton.setVisible(false);
853873
}
854874
}
@@ -921,14 +941,18 @@ public void startBackgroundHandler() {
921941
alert.showAndWait();
922942
appPrefs.putBoolean("Show background startup message", false);
923943
appPrefs.putBoolean("Start background immediately", true);
924-
Background.startBackground();
944+
Background.startBackground(false);
925945
} else {
926-
Background.startBackground();
946+
Background.startBackground(false);
927947
startBackgroundButton.setText("Cancel Background");
928948
}
929949
}
930950

931-
public void resetApp() {
951+
public void forceCheckForBlobsHandler() {
952+
Background.startBackground(true);
953+
}
954+
955+
public void resetAppHandler() {
932956
try {
933957
Alert confirmationAlert = new Alert(Alert.AlertType.CONFIRMATION, "Are you sure you would like to reset this application to defaults?", ButtonType.NO, ButtonType.YES);
934958
confirmationAlert.showAndWait();
@@ -954,7 +978,7 @@ private void log(String msg) {
954978
System.out.println(msg);
955979
}
956980

957-
public void go() {
981+
public void goButtonHandler() {
958982
boolean doReturn = false;
959983
if (ecidField.getText().equals("")) {
960984
ecidField.setEffect(errorBorder);

src/main/java/blobsaver/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void start(Stage primaryStage) throws IOException {
8383
Controller.afterStageShowing();
8484
Platform.setImplicitExit(false);
8585
if (appPrefs.getBoolean("Start background immediately", false)) {
86-
Background.startBackground();
86+
Background.startBackground(false);
8787
}
8888
primaryStage.setOnCloseRequest(event -> {
8989
event.consume();

src/main/resources/blobsaver/blobsaver.fxml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +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"/>
31+
<MenuItem mnemonicParsing="false" onAction="#resetAppHandler" text="Clear all data"/>
3232
</Menu>
3333
<Menu mnemonicParsing="false" text="Help">
3434
<MenuItem mnemonicParsing="false" onAction="#newGithubIssue"
@@ -209,7 +209,8 @@
209209
AnchorPane.rightAnchor="0.0"/>
210210
</AnchorPane>
211211
<Region VBox.vgrow="ALWAYS"/>
212-
<Button fx:id="goButton" maxWidth="Infinity" mnemonicParsing="false" onAction="#go" prefWidth="Infinity"
212+
<Button fx:id="goButton" maxWidth="Infinity" mnemonicParsing="false" onAction="#goButtonHandler"
213+
prefWidth="Infinity"
213214
text="Go">
214215
<VBox.margin>
215216
<Insets bottom="10.0" left="10.0" right="10.0"/>
@@ -282,6 +283,12 @@
282283
</VBox.margin>
283284
</Button>
284285
<Region VBox.vgrow="ALWAYS"/>
286+
<Button fx:id="forceCheckForBlobs" maxWidth="Infinity" mnemonicParsing="false"
287+
onAction="#forceCheckForBlobsHandler" prefWidth="Infinity" text="Force check" visible="false">
288+
<VBox.margin>
289+
<Insets bottom="10.0"/>
290+
</VBox.margin>
291+
</Button>
285292
<Button fx:id="chooseTimeToRunButton" maxWidth="Infinity" mnemonicParsing="false"
286293
onAction="#chooseTimeToRunHandler" prefWidth="Infinity" text="Change frequency" visible="false">
287294
<VBox.margin>

0 commit comments

Comments
 (0)