From: Debayan Sutradhar Date: Thu, 29 Apr 2021 15:10:43 +0530 Subject: Optimised startup file handling --- Optimised startup file handling --- --- 'a/src/main/java/com/stream_pi/client/controller/Controller.java' +++ b/src/main/java/com/stream_pi/client/controller/Controller.java @@ -18,6 +18,8 @@ import com.stream_pi.util.exception.Seve import com.gluonhq.attach.lifecycle.LifecycleService; import com.gluonhq.attach.util.Services; +import com.stream_pi.util.platform.PlatformType; +import com.stream_pi.util.startatboot.StartAtBoot; import javafx.animation.Interpolator; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; @@ -55,6 +57,26 @@ public class Controller extends Base if(getClientInfo().getPlatform() != com.stream_pi.util.platform.Platform.ANDROID) { + if(getConfig().isStartOnBoot()) + { + if(getClientInfo().isXMode() != getConfig().isStartupXMode()) + { + StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform()); + + boolean result = startAtBoot.delete(); + if(!result) + new StreamPiAlert("Uh Oh!", "Unable to delete the previous starter file.\n" + + "This was probably because you ran Stream-Pi as root before. Restart stream pi as root, " + + "delete the old starter file, then exit and restart Stream-Pi as normal user.", StreamPiAlertType.ERROR).show(); + else + { + startAtBoot.create(new File(ClientInfo.getInstance().getRunnerFileName()), + ClientInfo.getInstance().isXMode()); + getConfig().setStartupIsXMode(ClientInfo.getInstance().isXMode()); + } + } + } + setupFlags(); if(!getConfig().getIsFullScreenMode()) --- 'a/src/main/java/com/stream_pi/client/io/Config.java' +++ b/src/main/java/com/stream_pi/client/io/Config.java @@ -411,4 +411,19 @@ public class Config { getStartupWindowSizeElement().getElementsByTagName("height").item(0).setTextContent(height+""); } + + public void setStartupIsXMode(boolean isXMode) + { + getOthersElement().getElementsByTagName("start-on-boot-x-mode").item(0).setTextContent(isXMode+""); + } + + public boolean getDefaultIsStartupXMode() + { + return false; + } + + public boolean isStartupXMode() + { + return XMLConfigHelper.getBooleanProperty(getOthersElement(), "start-on-boot-x-mode", getDefaultIsStartupXMode(), false, false, document, configFile); + } } --- 'a/src/main/java/com/stream_pi/client/window/settings/SettingsBase.java' +++ b/src/main/java/com/stream_pi/client/window/settings/SettingsBase.java @@ -529,6 +529,8 @@ public class SettingsBase extends VBox { { startAtBoot.create(new File(ClientInfo.getInstance().getRunnerFileName()), ClientInfo.getInstance().isXMode()); + + config.setStartupIsXMode(ClientInfo.getInstance().isXMode()); } else {