From 814b0c06658fce64a3b9a9d6f538a78de673d389 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sun, 30 Oct 2016 14:54:46 +0100 Subject: [PATCH] Browsers --- src/Launcher/Main.java | 56 +++--------------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/src/Launcher/Main.java b/src/Launcher/Main.java index 784e1e2..f95fa0a 100644 --- a/src/Launcher/Main.java +++ b/src/Launcher/Main.java @@ -4,14 +4,10 @@ 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; +import java.awt.*; +import java.net.URI; public class Main extends Application { @@ -28,17 +24,7 @@ public class Main extends Application { primaryStage.setScene(new Scene(root, 900, 500)); primaryStage.show(); - 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"); - - + Desktop.getDesktop().browse(new URI("www.youtube.com")); root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close()); @@ -56,40 +42,4 @@ 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"; - } }