Skip to content

Commit

Permalink
Code adjustments for running natively on mobile devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Oct 17, 2023
1 parent 4c421f9 commit 153a8e2
Show file tree
Hide file tree
Showing 17 changed files with 441 additions and 489 deletions.
15 changes: 15 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,19 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>ios</id>
<properties>
<gluonfx.target>ios</gluonfx.target>
</properties>
</profile>
<profile>
<id>android</id>
<properties>
<gluonfx.target>android</gluonfx.target>
</properties>
</profile>
</profiles>
</project>
59 changes: 35 additions & 24 deletions app/src/main/java/com/dlsc/jfxcentral2/app/JFXCentral2App.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.dlsc.jfxcentral2.app.utils.PrettyScrollPane;
import com.dlsc.jfxcentral2.model.Size;
import com.dlsc.jfxcentral2.utils.NodeUtil;
import com.dlsc.jfxcentral2.utils.OSUtil;
import com.dlsc.jfxcentral2.utils.SocialUtil;
import com.jpro.webapi.WebAPI;
import javafx.application.Application;
Expand All @@ -82,6 +83,8 @@
import org.apache.logging.log4j.Logger;
import simplefx.experimental.parts.FXFuture;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.PrintStream;
import java.util.Locale;
Expand All @@ -93,7 +96,7 @@ public class JFXCentral2App extends Application {
private static final Logger LOGGER = LogManager.getLogger(JFXCentral2App.class);
private final ObjectProperty<Size> size = new SimpleObjectProperty<>(Size.LARGE);

// private TrayIconManager trayIconManager;
private TrayIconManager trayIconManager;

static {
if (WebAPI.isBrowser() || !RepositoryManager.isCountryEqualToChina()) {
Expand All @@ -104,21 +107,26 @@ public class JFXCentral2App extends Application {
@Override
public void start(Stage stage) {
// This is a workaround to prevent a deadlock between the TrayIcon and the JPro ImageManager
// BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
// bi.createGraphics();
if (!OSUtil.isNative()) {
BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
bi.createGraphics();
}

if (!WebAPI.isBrowser()) {
System.setProperty("prism.lcdtext", "false");
System.setProperty("routing.scrollpane", PrettyScrollPane.class.getName());

// if (Taskbar.isTaskbarSupported()) {
// Taskbar taskbar = Taskbar.getTaskbar();
// if (taskbar.isSupported(Taskbar.Feature.ICON_IMAGE)) {
// Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
// Image dockIcon = defaultToolkit.getImage(JFXCentral2App.class.getResource("app-icon.png"));
// taskbar.setIconImage(dockIcon);
// }
// }
if (!OSUtil.isNative()) {
System.setProperty("prism.lcdtext", "false");

if (Taskbar.isTaskbarSupported()) {
Taskbar taskbar = Taskbar.getTaskbar();
if (taskbar.isSupported(Taskbar.Feature.ICON_IMAGE)) {
Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
Image dockIcon = defaultToolkit.getImage(JFXCentral2App.class.getResource("app-icon.png"));
taskbar.setIconImage(dockIcon);
}
}
}
}

// set jpro.imagemanager.cache to ~/.jfxcentral/imagecache
Expand All @@ -136,22 +144,24 @@ public void start(Stage stage) {
routeNode.start(sessionManager);

// tray icon
// if (!WebAPI.isBrowser() && SystemTray.isSupported()) {
// RepositoryManager.repositoryUpdatedProperty().addListener(it -> {
// if (trayIconManager == null) {
// trayIconManager = new TrayIconManager(stage, sessionManager);
// } else {
// trayIconManager.refresh();
// }
// });
// }
if (!WebAPI.isBrowser() && !OSUtil.isNative() && SystemTray.isSupported()) {
RepositoryManager.repositoryUpdatedProperty().addListener(it -> {
if (trayIconManager == null) {
trayIconManager = new TrayIconManager(stage, sessionManager);
} else {
trayIconManager.refresh();
}
});
}

// customs stage for decorations / the chrome
CustomStage customStage = new CustomStage(stage, routeNode, sessionManager);
customStage.setCloseHandler(() -> {
// if (SystemTray.isSupported()) {
// trayIconManager.hide();
// }
if (!OSUtil.isNative()) {
if (SystemTray.isSupported()) {
trayIconManager.hide();
}
}
stage.close();
});

Expand Down Expand Up @@ -259,6 +269,7 @@ private Response createResponse(Request request, Class<? extends ModelObject> cl

private void updateSizeProperty(Scene scene) {
double sceneWidth = scene.getWidth();
System.out.println("scene width: " + sceneWidth);
if (sceneWidth < 865) {
size.set(Size.SMALL);
} else if (sceneWidth <= 1320) {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/dlsc/jfxcentral2/app/RepositoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import one.jpro.platform.internal.openlink.util.PlatformUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.merge.ContentMergeStrategy;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FS_POSIX;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -81,6 +84,16 @@ private static void initialLoad(ProgressMonitor monitor) throws Exception {
.setBranch("live")
.setDepth(1)
.setDirectory(repoDirectory);

if (PlatformUtils.isAndroid() || PlatformUtils.isIOS()) {
cloneCmd = cloneCmd.setFs(new FS_POSIX() {
@Override
public boolean supportsExecute() {
return false;
}
});
}

try (Git git = cloneCmd.call()) {
// Git object is here only to ensure resources are properly closed; no other actions needed.
}
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/com/dlsc/jfxcentral2/app/stage/CustomStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
Expand Down Expand Up @@ -66,9 +65,12 @@ public CustomStage(Stage stage, Node node, SessionManager sessionManager) {

if (!WebAPI.isBrowser()) {
VBox vBox = new VBox(titleBar);
vBox.setPadding(new Insets(0, 0, 2, 0));
vBox.setAlignment(Pos.CENTER_RIGHT);
setTop(vBox);
if (OSUtil.isNative()) {
setBottom(vBox);
} else {
setTop(vBox);
}
}

centerProperty().bind(contentProperty());
Expand Down Expand Up @@ -320,6 +322,8 @@ class TitleBar extends StackPane {

label = new Label();
label.getStyleClass().add("title");
label.setVisible(!OSUtil.isNative());
label.setManaged(!OSUtil.isNative());

FontIcon maxIcon = new FontIcon(MaterialDesign.MDI_WINDOW_MAXIMIZE);
FontIcon restoreIcon = new FontIcon(MaterialDesign.MDI_WINDOW_RESTORE);
Expand Down Expand Up @@ -386,7 +390,10 @@ class TitleBar extends StackPane {

NavigationView navigationView = new NavigationView(sessionManager);

if (OSUtil.isMac()) {
if (OSUtil.isNative()) {
getStyleClass().add("native");
getChildren().addAll(navigationView);
} else if (OSUtil.isMac()) {
getStyleClass().add("mac");
HBox controlBox = new HBox(closeButton, minButton, maxButton);
controlBox.getStyleClass().add("control-box");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dlsc.jfxcentral2.app.stage;

import com.dlsc.jfxcentral2.utils.OSUtil;
import com.jpro.webapi.WebAPI;
import javafx.beans.binding.Bindings;
import javafx.collections.ObservableList;
Expand All @@ -10,7 +11,6 @@
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import one.jpro.platform.routing.HistoryEntry;
import one.jpro.platform.routing.sessionmanager.SessionManager;
import org.kordamp.ikonli.javafx.FontIcon;
Expand Down Expand Up @@ -45,14 +45,12 @@ public NavigationView(SessionManager sessionManager) {
back.setGraphic(new FontIcon(Material.ARROW_BACK));
back.setOnAction(evt -> sessionManager.goBack());
back.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(back, Priority.ALWAYS);

Button forward = new Button();
forward.setFocusTraversable(false);
forward.setGraphic(new FontIcon(Material.ARROW_FORWARD));
forward.setOnAction(evt -> sessionManager.goForward());
forward.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(forward, Priority.ALWAYS);

sceneProperty().addListener(it -> {
if (getScene() != null) {
Expand All @@ -64,7 +62,11 @@ public NavigationView(SessionManager sessionManager) {
back.setOnContextMenuRequested(evt -> showMenu(back, sessionManager.getHistoryBackward()));
forward.setOnContextMenuRequested(evt -> showMenu(forward, sessionManager.getHistoryForwards()));

getChildren().setAll(refreshButton, back, forward);
if (OSUtil.isNative()) {
getChildren().setAll(back, refreshButton, forward);
} else {
getChildren().setAll(refreshButton, back, forward);
}
}

private void showMenu(Button back, ObservableList<HistoryEntry> historyBackward) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dlsc.jfxcentral2.app.utils;

import com.dlsc.jfxcentral2.utils.OSUtil;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
Expand Down Expand Up @@ -118,12 +119,20 @@ private void init() {
vBar.setManaged(false);
vBar.setOrientation(Orientation.VERTICAL);
vBar.getStyleClass().addAll("my-scroll-bar", "vertical-scroll-bar");
vBar.visibleProperty().bind(hoverProperty());
if (OSUtil.isNative()) {
vBar.setVisible(false);
} else {
vBar.visibleProperty().bind(hoverProperty());
}

hBar.setManaged(false);
hBar.setOrientation(Orientation.HORIZONTAL);
hBar.getStyleClass().addAll("my-scroll-bar", "horizontal-scroll-bar");
hBar.visibleProperty().bind(hBar.visibleAmountProperty().lessThan(1).or(alwaysShowHorizontalScrollBar));
if (OSUtil.isNative()) {
hBar.setVisible(false);
} else {
hBar.visibleProperty().bind(hBar.visibleAmountProperty().lessThan(1).or(alwaysShowHorizontalScrollBar));
}

shadow.setManaged(false);
shadow.getStyleClass().add("shadow");
Expand Down
Loading

0 comments on commit 153a8e2

Please sign in to comment.