From aba063fb499443edfe490e41d5aac735ca9eab68 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sun, 30 Oct 2016 14:52:01 +0100 Subject: [PATCH] Merges 'n stuff' --- src/Launcher/Main.java | 62 ++++++++++++++++++++++++++++++++++++---- src/Launcher/sample.fxml | 23 +++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/Launcher/sample.fxml diff --git a/src/Launcher/Main.java b/src/Launcher/Main.java index 3562acf..784e1e2 100644 --- a/src/Launcher/Main.java +++ b/src/Launcher/Main.java @@ -4,9 +4,15 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; import javafx.stage.Stage; import javafx.stage.StageStyle; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class Main extends Application { private double xOffset = 0; @@ -17,16 +23,24 @@ public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ primaryStage.initStyle(StageStyle.UNDECORATED); - Parent root = FXMLLoader.load(getClass().getResource("Main_Launcher.fxml")); + Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); primaryStage.setTitle("Team-Avion Launcher [WIP]"); primaryStage.setScene(new Scene(root, 900, 500)); primaryStage.show(); - primaryStage.maximizedProperty().addListener((observable, oldValue, newValue) -> { - if (newValue) { - primaryStage.setMaximized(false); - } - }); + System.out.println(getDefaultBrowser()); + + final WebView browser = new WebView(); + final WebEngine webEngine = browser.getEngine(); + webEngine.setJavaScriptEnabled(true); + webEngine.load("google.com"); + System.out.println(webEngine.getDocument()); + + Runtime.getRuntime().exec(getDefaultBrowser()+" youtube.com"); + + + + root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close()); // Drag @@ -42,4 +56,40 @@ public class Main extends Application { public static void main(String[] args) { launch(args); } + + public static String getDefaultBrowser() + { + try + { + // Get registry where we find the default browser + Process process = Runtime.getRuntime().exec("REG QUERY HKEY_CLASSES_ROOT\\http\\shell\\open\\command"); + Scanner kb = new Scanner(process.getInputStream()); + while (kb.hasNextLine()) + { + + // Get output from the terminal, and replace all '\' with '/' (makes regex a bit more manageable) + String registry = (kb.nextLine()).replaceAll("\\\\", "/").trim(); + + // Extract the default browser + Matcher matcher = Pattern.compile("\"(.*)\"").matcher(registry); + if (matcher.find()) + { + // Scanner is no longer needed if match is found, so close it + kb.close(); + String defaultBrowser = matcher.group(1); + + // Capitalize first letter and return String + defaultBrowser = defaultBrowser.substring(0, 1).toUpperCase() + defaultBrowser.substring(1, defaultBrowser.length()); + return defaultBrowser; + } + } + // Match wasn't found, still need to close Scanner + kb.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + // Have to return something if everything fails + return "Error: Unable to get default browser"; + } } diff --git a/src/Launcher/sample.fxml b/src/Launcher/sample.fxml new file mode 100644 index 0000000..7144e85 --- /dev/null +++ b/src/Launcher/sample.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + +