Browsers
This commit is contained in:
parent
aba063fb49
commit
814b0c0665
@ -4,14 +4,10 @@ import javafx.application.Application;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.web.WebEngine;
|
|
||||||
import javafx.scene.web.WebView;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
|
import java.awt.*;
|
||||||
import java.util.Scanner;
|
import java.net.URI;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
@ -28,17 +24,7 @@ public class Main extends Application {
|
|||||||
primaryStage.setScene(new Scene(root, 900, 500));
|
primaryStage.setScene(new Scene(root, 900, 500));
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
System.out.println(getDefaultBrowser());
|
Desktop.getDesktop().browse(new URI("www.youtube.com"));
|
||||||
|
|
||||||
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());
|
root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close());
|
||||||
@ -56,40 +42,4 @@ public class Main extends Application {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user