diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 3aab502a..ff2d313b 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -55,6 +55,7 @@ import net.filebot.cli.CmdlineOperations; import net.filebot.format.ExpressionFormat; import net.filebot.mac.MacAppUtilities; import net.filebot.ui.FileBotMenuBar; +import net.filebot.ui.GettingStartedStage; import net.filebot.ui.MainFrame; import net.filebot.ui.PanelBuilder; import net.filebot.ui.SinglePanelFrame; @@ -201,6 +202,15 @@ public class Main { Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to check for updates", e); } } + + // check if application help should be shown + if (!"skip".equals(System.getProperty("application.help"))) { + try { + checkGettingStarted(); + } catch (Exception e) { + Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to show Getting Started help", e); + } + } } catch (Exception e) { // illegal arguments => just print CLI error message and stop System.err.println(e.getMessage()); @@ -355,6 +365,19 @@ public class Main { } } + /** + * Show Getting Started to new users + */ + private static void checkGettingStarted() throws Exception { + PreferencesEntry started = Settings.forPackage(Main.class).entry("getting.started").defaultValue("0"); + if ("0".equals(started.getValue())) { + SwingUtilities.invokeLater(() -> { + GettingStartedStage.start(); + }); + started.setValue("1"); + } + } + private static void showDonationReminder() { PreferencesEntry donation = Settings.forPackage(Main.class).entry("donation").defaultValue("0"); int donationRev = Integer.parseInt(donation.getValue()); diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index f9c0d850..fd29a3ec 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -206,6 +206,10 @@ public final class Settings { return null; } + public static URI getEmbeddedHelpURI() { + return URI.create("http://www.filebot.net/getting-started/embed.html#" + getApplicationDeployment()); + } + public static Map getHelpURIs() { Map links = new LinkedHashMap(); links.put("Getting Started", URI.create("http://www.filebot.net/getting-started/")); diff --git a/source/net/filebot/UserFiles.java b/source/net/filebot/UserFiles.java index ab3a75ac..48e613e1 100644 --- a/source/net/filebot/UserFiles.java +++ b/source/net/filebot/UserFiles.java @@ -299,6 +299,7 @@ public class UserFiles { try { // initialize JavaFX new javafx.embed.swing.JFXPanel(); + javafx.application.Platform.setImplicitExit(false); // run on FX Thread FutureTask task = new FutureTask(c); diff --git a/source/net/filebot/ui/GettingStartedStage.java b/source/net/filebot/ui/GettingStartedStage.java new file mode 100644 index 00000000..0446c51f --- /dev/null +++ b/source/net/filebot/ui/GettingStartedStage.java @@ -0,0 +1,85 @@ +package net.filebot.ui; + +import java.awt.Desktop; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javafx.application.Platform; +import javafx.concurrent.Worker.State; +import javafx.scene.Scene; +import javafx.scene.paint.Color; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; +import javafx.stage.Stage; +import net.filebot.Main; +import net.filebot.Settings; + +public class GettingStartedStage { + + public static void start() { + // initialize JavaFX + new javafx.embed.swing.JFXPanel(); + javafx.application.Platform.setImplicitExit(false); + + Platform.runLater(() -> { + Stage stage = new Stage(); + stage.setResizable(false); + + GettingStartedStage view = new GettingStartedStage(stage); + view.show(); + }); + } + + private Stage stage; + + public GettingStartedStage(Stage stage) { + this.stage = stage; + + WebView webview = new WebView(); + webview.getEngine().load(Settings.getEmbeddedHelpURI().toString()); + webview.setPrefSize(750, 480); + + // intercept target _blank click events and open links in a new browser window + webview.getEngine().setCreatePopupHandler((config) -> onPopup(webview)); + + webview.getEngine().getLoadWorker().stateProperty().addListener((value, oldState, newState) -> { + if (newState == State.SUCCEEDED) { + Platform.runLater(() -> { + stage.setOpacity(1); + stage.show(); + stage.toFront(); + stage.requestFocus(); + }); + } else { + Platform.runLater(() -> { + stage.hide(); + }); + } + }); + + stage.setTitle("Getting Started"); + stage.setScene(new Scene(webview, webview.getPrefWidth(), webview.getPrefHeight(), Color.BLACK)); + } + + public void show() { + stage.setOpacity(0); + stage.show(); + stage.toBack(); + } + + protected WebEngine onPopup(WebView webview) { + // get currently select image via Galleria API + Object link = webview.getEngine().executeScript("$('.galleria').data('galleria').getData().link"); + + try { + Desktop.getDesktop().browse(new URI(link.toString())); + } catch (Exception e) { + Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to browse URI", e); + } + + // prevent current web view from opening the link + return null; + } + +} diff --git a/website/getting-started/embed.html b/website/getting-started/embed.html new file mode 100644 index 00000000..59ca1320 --- /dev/null +++ b/website/getting-started/embed.html @@ -0,0 +1,38 @@ + + + + + + + + + Getting Started + + +
+ +
+ + + diff --git a/website/getting-started/index.html b/website/getting-started/index.html index 10f8f825..bce55936 100644 --- a/website/getting-started/index.html +++ b/website/getting-started/index.html @@ -18,12 +18,11 @@