client

Clone or download

Added fully working Reset To Factory

Modified Files

--- 'a/src/main/java/com/stream_pi/client/controller/ClientListener.java'
+++ b/src/main/java/com/stream_pi/client/controller/ClientListener.java
@@ -66,4 +66,7 @@ public interface ClientListener
ActionBox getActionBoxByProfileAndID(String profileID, String actionID);
void openURL(String URL);
+
+ void factoryReset();
+ void exitApp();
}
--- 'a/src/main/java/com/stream_pi/client/controller/Controller.java'
+++ b/src/main/java/com/stream_pi/client/controller/Controller.java
@@ -21,6 +21,7 @@ import com.stream_pi.util.exception.Seve
import com.gluonhq.attach.lifecycle.LifecycleService;
import com.gluonhq.attach.util.Services;
+import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.startatboot.StartAtBoot;
import javafx.animation.Interpolator;
@@ -228,7 +229,10 @@ public class Controller extends Base
public void setupDashWindow()
{
getStage().setTitle("Stream-Pi Client");
- getStage().setOnCloseRequest(e->onCloseRequest());
+ getStage().setOnCloseRequest(e->{
+ onCloseRequest();
+ exitApp();
+ });
}
@@ -257,9 +261,20 @@ public class Controller extends Base
getLogger().info("Shut down");
closeLogger();
+ Config.nullify();
+ }
+ }
- if (ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
- Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
+ @Override
+ public void exitApp()
+ {
+ if (ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
+ {
+ Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
+ }
+ else
+ {
+ Platform.exit();
}
}
@@ -383,7 +398,7 @@ public class Controller extends Base
public void onClick(String txt)
{
onCloseRequest();
- Platform.exit();
+ exitApp();
}
});
alert.show();
@@ -555,4 +570,29 @@ public class Controller extends Base
}
}
}
+
+ @Override
+ public void factoryReset()
+ {
+ getLogger().info("Reset to factory ...");
+
+ onCloseRequest();
+
+ boolean result = IOHelper.deleteFile(getClientInfo().getPrePath());
+
+ if(result)
+ {
+ setFirstRun(true);
+ init();
+ }
+ else
+ {
+ handleSevereException(new SevereException("Unable to delete all files successfully. Installation corrupt. Re-install."));
+ }
+ }
+
+ public void setFirstRun(boolean firstRun)
+ {
+ this.firstRun = firstRun;
+ }
}
--- 'a/src/main/java/com/stream_pi/client/io/Config.java'
+++ b/src/main/java/com/stream_pi/client/io/Config.java
@@ -63,6 +63,11 @@ public class Config
return instance;
}
+ public static void nullify()
+ {
+ instance = null;
+ }
+
public static void unzipToDefaultPrePath() throws Exception
{
IOHelper.unzip(Objects.requireNonNull(Main.class.getResourceAsStream("Default.zip")), ClientInfo.getInstance().getPrePath());
--- 'a/src/main/java/com/stream_pi/client/profile/ClientProfiles.java'
+++ b/src/main/java/com/stream_pi/client/profile/ClientProfiles.java
@@ -55,7 +55,7 @@ public class ClientProfiles {
if(!profilesFolder.isDirectory())
{
- throw new SevereException("Profiles","profile folder doesn't exist! Cant continue.");
+ throw new SevereException("Profiles","Profile folder doesn't exist! Cant continue.");
}
--- 'a/src/main/java/com/stream_pi/client/window/Base.java'
+++ b/src/main/java/com/stream_pi/client/window/Base.java
@@ -6,6 +6,7 @@ import com.stream_pi.client.io.Config;
import com.stream_pi.client.info.ClientInfo;
import java.io.File;
+import java.util.Objects;
import java.util.logging.Logger;
import com.stream_pi.client.Main;
@@ -141,7 +142,7 @@ public abstract class Base extends Stack
{
stage = (Stage) getScene().getWindow();
- getStage().getIcons().add(new Image(Main.class.getResourceAsStream("app_icon.png")));
+ getStage().getIcons().add(new Image(Objects.requireNonNull(Main.class.getResourceAsStream("app_icon.png"))));
clientInfo = ClientInfo.getInstance();
dashboardBase = new DashboardBase(this, this);
--- 'a/src/main/java/com/stream_pi/client/window/settings/GeneralTab.java'
+++ b/src/main/java/com/stream_pi/client/window/settings/GeneralTab.java
@@ -1,6 +1,5 @@
package com.stream_pi.client.window.settings;
-import com.gluonhq.attach.browser.BrowserService;
import com.gluonhq.attach.vibration.VibrationService;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.info.ClientInfo;
@@ -10,6 +9,7 @@ import com.stream_pi.client.profile.Clie
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.util.alert.StreamPiAlert;
+import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
@@ -34,9 +34,9 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import org.controlsfx.control.ToggleSwitch;
-import org.w3c.dom.Text;
import java.io.File;
+import java.util.logging.Logger;
public class GeneralTab extends VBox
{
@@ -83,6 +83,10 @@ public class GeneralTab extends VBox
private TextField iconsPathTextField;
private TextField profilesPathTextField;
+ private final Button factoryResetButton;
+
+ private Logger logger;
+
private final Button checkForUpdatesButton;
@@ -95,6 +99,8 @@ public class GeneralTab extends VBox
this.clientListener = clientListener;
this.hostServices = hostServices;
+ logger = Logger.getLogger("");
+
serverPortTextField = new TextField();
screenTimeoutTextField = new TextField();
@@ -180,6 +186,9 @@ public class GeneralTab extends VBox
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
+ factoryResetButton = new Button("Factory Reset");
+ factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
+
screenTimeoutSecondsHBoxInputBox = new HBoxInputBox("Screen Timeout (seconds)", screenTimeoutTextField, prefWidth);
screenTimeoutSecondsHBoxInputBox.managedProperty().bind(screenTimeoutSecondsHBoxInputBox.visibleProperty());
@@ -251,7 +260,8 @@ public class GeneralTab extends VBox
startOnBootHBox,
showCursorHBox,
checkForUpdatesButton,
- shutdownButton
+ shutdownButton,
+ factoryResetButton
);
@@ -311,6 +321,11 @@ public class GeneralTab extends VBox
}
+ private Logger getLogger()
+ {
+ return logger;
+ }
+
private void checkForUpdates()
{
new CheckForUpdates(checkForUpdatesButton,
@@ -329,11 +344,34 @@ public class GeneralTab extends VBox
});
}
+ private void onFactoryResetButtonClicked()
+ {
+ StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
+ "This will erase everything.",StreamPiAlertType.WARNING);
+
+ String yesButton = "Yes";
+ String noButton = "No";
+
+ confirmation.setButtons(yesButton, noButton);
+
+ confirmation.setOnClicked(new StreamPiAlertListener() {
+ @Override
+ public void onClick(String s) {
+ if(s.equals(yesButton))
+ {
+ clientListener.factoryReset();
+ }
+ }
+ });
+
+ confirmation.show();
+ }
+
public void onExitButtonClicked()
{
clientListener.onCloseRequest();
- javafx.application.Platform.exit();
+ clientListener.exitApp();
}
public void setDisableStatus(boolean status)
@@ -350,7 +388,9 @@ public class GeneralTab extends VBox
public void onShutdownButtonClicked()
{
clientListener.onCloseRequest();
- try {
+
+ try
+ {
Runtime.getRuntime().exec("sudo halt");
}
catch (Exception e)
@@ -500,7 +540,8 @@ public class GeneralTab extends VBox
- try {
+ try
+ {
boolean toBeReloaded = false;
boolean syncWithServer = false;