From: rnayabed Date: Sat, 06 Mar 2021 12:22:00 +0530 Subject: Added support for iOS, changed storage to use Gluon Attach Storage --- Added support for iOS, changed storage to use Gluon Attach Storage --- --- 'a/pom.xml' +++ b/pom.xml @@ -77,6 +77,11 @@ storage 4.0.10 + + com.gluonhq.attach + browser + 4.0.10 + @@ -113,10 +118,10 @@ client-maven-plugin ${client.plugin.version} - android + ${clientTarget} --initialize-at-build-time=com.sun.org.apache.xml.internal.serializer.ToXMLStream - -Dsvm.targetName=android + {additionalArgs} com.sun.org.apache.xerces.internal.impl.msg.XMLMessages @@ -124,6 +129,7 @@ lifecycle storage + browser java.util.logging.FileHandler @@ -142,23 +148,6 @@ - - gluon-releases @@ -172,6 +161,21 @@ + android + + android + -Dsvm.targetName=android + + + + ios + + ios + -Dsvm.targetName=ios + + + + release --- 'a/src/main/java/com/stream_pi/client/connection/Client.java' +++ b/src/main/java/com/stream_pi/client/connection/Client.java @@ -361,7 +361,7 @@ public class Client extends Thread{ String clientNickname = Config.getInstance().getClientNickName(); String screenWidth = clientListener.getStageWidth()+""; String screenHeight = clientListener.getStageHeight()+""; - String OS = clientInfo.getPlatformType()+""; + String OS = clientInfo.getPlatform()+""; String defaultProfileID = Config.getInstance().getStartupProfileID(); --- 'a/src/main/java/com/stream_pi/client/controller/Controller.java' +++ b/src/main/java/com/stream_pi/client/controller/Controller.java @@ -25,6 +25,7 @@ import javafx.scene.Node; import javafx.util.Duration; import java.io.*; +import java.util.logging.Level; public class Controller extends Base @@ -47,7 +48,7 @@ public class Controller extends Base if(firstRun) initBase(); - if(getClientInfo().getPlatformType()!= com.stream_pi.util.platform.Platform.ANDROID) + if(getClientInfo().getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID) { getStage().setWidth(getConfig().getStartupWindowWidth()); getStage().setHeight(getConfig().getStartupWindowHeight()); @@ -108,15 +109,11 @@ public class Controller extends Base catch (SevereException e) { handleSevereException(e); - return; } catch (MinorException e) { handleMinorException(e); - return; } - - } @@ -156,7 +153,7 @@ public class Controller extends Base getLogger().info("Shut down"); closeLogger(); - if (ClientInfo.getInstance().getPlatformType() == com.stream_pi.util.platform.Platform.ANDROID) + if (ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.ANDROID) Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown); } @@ -242,12 +239,20 @@ public class Controller extends Base @Override public void handleMinorException(MinorException e) { + getLogger().log(Level.SEVERE, e.getMessage(), e); + e.printStackTrace(); + + Platform.runLater(()-> genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show()); } @Override public void handleSevereException(SevereException e) { + getLogger().log(Level.SEVERE, e.getMessage(), e); + e.printStackTrace(); + + Platform.runLater(()-> { StreamPiAlert alert = genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR); --- 'a/src/main/java/com/stream_pi/client/info/ClientInfo.java' +++ b/src/main/java/com/stream_pi/client/info/ClientInfo.java @@ -22,7 +22,7 @@ import java.util.function.Function; public class ClientInfo { private Version version; private final ReleaseStatus releaseStatus; - private Platform platformType; + private Platform platform; private String prePath; @@ -36,7 +36,7 @@ public class ClientInfo { private ClientInfo() { - version = new Version(1,0,0); + version = new Version(0,0,0); minThemeSupportVersion = new Version(1,0,0); minPluginSupportVersion = new Version(1,0,0); commStandardVersion = new Version(1,0,0); @@ -49,11 +49,11 @@ public class ClientInfo { if(osName.contains("windows")) { - platformType = Platform.WINDOWS; + platform = Platform.WINDOWS; } else if (osName.contains("linux")) { - platformType = Platform.LINUX; + platform = Platform.LINUX; } else if(osName.contains("android")) // SPECIFY -Dsvm.targetName=android WHILE BUILDING ANDROID NATIVE IMAGE { @@ -66,7 +66,7 @@ public class ClientInfo { }); }); - platformType = Platform.ANDROID; + platform = Platform.ANDROID; } else if(osName.contains("ios")) // SPECIFY -Dsvm.targetName=ios WHILE BUILDING ANDROID NATIVE IMAGE { @@ -79,15 +79,15 @@ public class ClientInfo { }); }); - platformType = Platform.IOS; + platform = Platform.IOS; } else if (osName.contains("mac")) { - platformType = Platform.MAC; + platform = Platform.MAC; } else { - platformType = Platform.UNKNOWN; + platform = Platform.UNKNOWN; } } @@ -136,9 +136,9 @@ public class ClientInfo { return prePath; } - public Platform getPlatformType() + public Platform getPlatform() { - return platformType; + return platform; } public Version getVersion() { --- 'a/src/main/java/com/stream_pi/client/io/Config.java' +++ b/src/main/java/com/stream_pi/client/io/Config.java @@ -141,7 +141,9 @@ public class Config { public String getThemesPath() { - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform != Platform.ANDROID && + platform != Platform.IOS) return ClientInfo.getInstance().getPrePath() + "Themes/"; return XMLConfigHelper.getStringProperty(getClientElement(), "themes-path", getDefaultThemesPath(), false, true, document, configFile); @@ -149,8 +151,9 @@ public class Config { public String getProfilesPath() { - - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform != Platform.ANDROID && + platform != Platform.IOS) return ClientInfo.getInstance().getPrePath() + "Profiles/"; return XMLConfigHelper.getStringProperty(getClientElement(), "profiles-path", getDefaultProfilesPath(), false, true, document, configFile); @@ -158,7 +161,9 @@ public class Config { public String getIconsPath() { - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform != Platform.ANDROID && + platform != Platform.IOS) return ClientInfo.getInstance().getPrePath() + "Icons/"; return XMLConfigHelper.getStringProperty(getClientElement(), "icons-path", getDefaultIconsPath(), false, true, document, configFile); --- 'a/src/main/java/com/stream_pi/client/window/Base.java' +++ b/src/main/java/com/stream_pi/client/window/Base.java @@ -94,7 +94,9 @@ public abstract class Base extends Stack { String path = ClientInfo.getInstance().getPrePath()+"../stream-pi-client.log"; - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + Platform platform = getClientInfo().getPlatform(); + if(platform == Platform.ANDROID || + platform == Platform.IOS) path = ClientInfo.getInstance().getPrePath()+"stream-pi-client.log"; logFileHandler = new StreamPiLogFileHandler(path); @@ -198,7 +200,7 @@ public abstract class Base extends Stack private void resizeAccordingToResolution() { - if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID) + if(ClientInfo.getInstance().getPlatform() != Platform.ANDROID) { double height = getScreenHeight(); double width = getScreenWidth(); @@ -216,7 +218,7 @@ public abstract class Base extends Stack @Override public double getStageWidth() { - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID) { return getScreenWidth(); } @@ -234,7 +236,7 @@ public abstract class Base extends Stack @Override public double getStageHeight() { - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID) { return getScreenHeight(); } @@ -251,13 +253,28 @@ public abstract class Base extends Stack private void checkPrePathDirectory() throws SevereException { - try + try { - File filex = new File(getClientInfo().getPrePath()); + String path = getClientInfo().getPrePath(); - if(!filex.exists()) + System.out.println("PAAAAAAAAAAAATH : '"+path+"'"); + if(path == null) { - boolean result = filex.mkdirs(); + throwStoragePermErrorAlert("Unable to access file system!"); + return; + } + + File file = new File(path); + + if(!file.canWrite() || !file.canRead()) + { + throwStoragePermErrorAlert("No read/write storage permission. Give it!"); + return; + } + + if(!file.exists()) + { + boolean result = file.mkdirs(); if(result) { IOHelper.unzip(Main.class.getResourceAsStream("Default.zip"), ClientInfo.getInstance().getPrePath()); @@ -271,13 +288,7 @@ public abstract class Base extends Stack } else { - resizeAccordingToResolution(); - - clearStylesheets(); - applyDefaultStylesheet(); - applyDefaultIconsStylesheet(); - getStage().show(); - throw new SevereException("No storage permission. Give it!"); + throwStoragePermErrorAlert("No storage permission. Give it!"); } } } @@ -288,6 +299,17 @@ public abstract class Base extends Stack } } + private void throwStoragePermErrorAlert(String msg) throws SevereException + { + resizeAccordingToResolution(); + + clearStylesheets(); + applyDefaultStylesheet(); + applyDefaultIconsStylesheet(); + getStage().show(); + throw new SevereException(msg); + } + public void setupFlags() { //Full Screen --- 'a/src/main/java/com/stream_pi/client/window/firsttimeuse/FinalConfigPane.java' +++ b/src/main/java/com/stream_pi/client/window/firsttimeuse/FinalConfigPane.java @@ -59,7 +59,9 @@ public class FinalConfigPane extends VBo HBoxInputBox displayWidthInputBox = new HBoxInputBox("Display Width", displayWidthTextField); HBoxInputBox displayHeightInputBox = new HBoxInputBox("Display Height", displayHeightTextField); - if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID) + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform == Platform.ANDROID || + platform == Platform.IOS) { displayWidthInputBox.setVisible(false); displayHeightInputBox.setVisible(false); @@ -115,7 +117,7 @@ public class FinalConfigPane extends VBo double width=-1,height=-1; - if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID) + if(ClientInfo.getInstance().getPlatform() != Platform.ANDROID) { try { @@ -151,7 +153,9 @@ public class FinalConfigPane extends VBo Config.getInstance().setServerPort(port); Config.getInstance().setFirstTimeUse(false); - if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID) + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform != Platform.ANDROID && + platform != Platform.IOS) { Config.getInstance().setStartupWindowSize( width, height --- 'a/src/main/java/com/stream_pi/client/window/settings/SettingsBase.java' +++ b/src/main/java/com/stream_pi/client/window/settings/SettingsBase.java @@ -1,7 +1,10 @@ package com.stream_pi.client.window.settings; import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import com.gluonhq.attach.browser.BrowserService; import com.stream_pi.client.connection.ClientListener; import com.stream_pi.client.io.Config; import com.stream_pi.client.info.ClientInfo; @@ -11,18 +14,21 @@ import com.stream_pi.theme_api.Theme; import com.stream_pi.util.alert.StreamPiAlert; import com.stream_pi.util.alert.StreamPiAlertType; import com.stream_pi.util.checkforupdates.CheckForUpdates; +import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick; import com.stream_pi.util.combobox.StreamPiComboBox; import com.stream_pi.util.combobox.StreamPiComboBoxFactory; import com.stream_pi.util.combobox.StreamPiComboBoxListener; import com.stream_pi.util.exception.MinorException; import com.stream_pi.util.exception.SevereException; +import com.stream_pi.util.platform.Platform; import com.stream_pi.util.platform.PlatformType; import com.stream_pi.util.uihelper.HBoxInputBox; import com.stream_pi.util.uihelper.SpaceFiller; import com.stream_pi.util.startatboot.StartAtBoot; import javafx.application.HostServices; -import javafx.application.Platform; +import javafx.concurrent.Task; +import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.CacheHint; @@ -81,7 +87,7 @@ public class SettingsBase extends VBox { clientProfileComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory() { @Override - public String getOptionDisplayText(ClientProfile object) + public String getOptionDisplayText(ClientProfile object) { return object.getName(); } @@ -89,7 +95,7 @@ public class SettingsBase extends VBox { clientProfileComboBox.setStreamPiComboBoxListener(new StreamPiComboBoxListener(){ @Override - public void onNewItemSelected(ClientProfile selectedItem) + public void onNewItemSelected(ClientProfile selectedItem) { clientListener.renderProfile(selectedItem, true); } @@ -100,7 +106,7 @@ public class SettingsBase extends VBox { themeComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory() { @Override - public String getOptionDisplayText(Theme object) + public String getOptionDisplayText(Theme object) { return object.getShortName(); } @@ -149,7 +155,9 @@ public class SettingsBase extends VBox { HBoxInputBox screenWidthInputBox = new HBoxInputBox("Screen Width", displayWidthTextField, prefWidth); screenWidthInputBox.managedProperty().bind(screenWidthInputBox.visibleProperty()); - if(ClientInfo.getInstance().getPlatformType() == com.stream_pi.util.platform.Platform.ANDROID) + com.stream_pi.util.platform.Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform == Platform.ANDROID || + platform == Platform.IOS) { themesPathInputBox.setVisible(false); iconsPathInputBox.setVisible(false); @@ -187,7 +195,7 @@ public class SettingsBase extends VBox { profilesPathInputBox ); - if(ClientInfo.getInstance().getPlatformType() == com.stream_pi.util.platform.Platform.LINUX && + if(ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.LINUX && ClientInfo.getInstance().isShowShutDownButton()) { @@ -259,14 +267,41 @@ public class SettingsBase extends VBox { private void checkForUpdates() { - new CheckForUpdates(checkForUpdatesButton, hostServices, - PlatformType.CLIENT, ClientInfo.getInstance().getVersion()); + new CheckForUpdates(checkForUpdatesButton, + PlatformType.CLIENT, ClientInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() { + @Override + public void handle(ActionEvent actionEvent) { + Platform platform = ClientInfo.getInstance().getPlatform(); + if(platform == Platform.ANDROID || platform == Platform.IOS) + { + BrowserService.create().ifPresentOrElse(s-> + { + try + { + s.launchExternalBrowser(getURL()); + } + catch (Exception e ) + { + exceptionAndAlertHandler.handleMinorException( + new MinorException("Cant start browser!") + ); + } + },()-> exceptionAndAlertHandler.handleMinorException( + new MinorException("Sorry!","No browser detected.") + )); + } + else + { + hostServices.showDocument(getURL()); + } + } + }); } public void onExitButtonClicked() { clientListener.onCloseRequest(); - Platform.exit(); + javafx.application.Platform.exit(); } public void setDisableStatus(boolean status) @@ -305,7 +340,7 @@ public class SettingsBase extends VBox { public void setConnectDisconnectButtonStatus() { - Platform.runLater(()->{ + javafx.application.Platform.runLater(()->{ setDisableStatus(false); if(clientListener.isConnected()) @@ -464,7 +499,7 @@ public class SettingsBase extends VBox { Config.getInstance().setServerHostNameOrIP(serverHostNameOrIPTextField.getText()); boolean startOnBoot = startOnBootToggleButton.isSelected(); - + if(Config.getInstance().isStartOnBoot() != startOnBoot) { if(ClientInfo.getInstance().getRunnerFileName() == null) @@ -474,7 +509,7 @@ public class SettingsBase extends VBox { } else { - StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatformType()); + StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform()); if(startOnBoot) { startAtBoot.create(new File(ClientInfo.getInstance().getRunnerFileName()), --- 'a/src/main/java/module-info.java' +++ b/src/main/java/module-info.java @@ -8,6 +8,7 @@ module com.stream_pi.client { requires com.gluonhq.attach.lifecycle; requires com.gluonhq.attach.util; requires com.gluonhq.attach.storage; + requires com.gluonhq.attach.browser; requires java.xml;