Skip to content

Commit

Permalink
Implement homepage setting
Browse files Browse the repository at this point in the history
  • Loading branch information
javierllorente committed Oct 12, 2024
1 parent 9f7f3aa commit 383ed74
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/javierllorente/obsfx/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Javier Llorente <javier@opensuse.org>
* Copyright (C) 2023-2024 Javier Llorente <javier@opensuse.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,7 @@ public class App extends Application {
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String API_URI = "api_uri";
public static final String HOMEPAGE = "homepage";
public static final String AUTOLOGIN = "autologin";

private final String applicationStyle = "style.css";
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/javierllorente/obsfx/BrowserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void initialize(URL url, ResourceBundle rb) {
initPackageListView();
initTabPane();

String username = preferences.get(App.USERNAME, "");
if (!username.isBlank()) {
String homepage = preferences.get(App.HOMEPAGE, "home:" + username);
locationTextField.setText(homepage);
}
Platform.runLater(() -> locationTextField.requestFocus());

bookmarksController.setBrowserController(this);
Expand Down Expand Up @@ -698,6 +703,10 @@ public void startProjectsTask() {
new Thread(projectsTask).start();
projectsTask.setOnSucceeded((t) -> {
projects = projectsTask.getValue();
if (!locationTextField.getText().isBlank()) {
// Load homepage
load(locationTextField.getText());
}
progressIndicator.setVisible(false);
});
projectsTask.setOnFailed((t) -> {
Expand Down Expand Up @@ -773,7 +782,7 @@ private void handleAbout() {

public void autoLogin() {
if (preferences.getBoolean(App.AUTOLOGIN, false)) {
handleLogin();
handleLogin();
}
}

Expand Down Expand Up @@ -993,6 +1002,7 @@ private void updatePreferences(Map<String, String> data) {
preferences.put(App.USERNAME, data.get(App.USERNAME));
preferences.put(App.PASSWORD, data.get(App.PASSWORD));
preferences.put(App.API_URI, data.get(App.API_URI));
preferences.put(App.HOMEPAGE, data.get(App.HOMEPAGE));
preferences.put(App.AUTOLOGIN, data.get(App.AUTOLOGIN));
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/javierllorente/obsfx/dialog/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
public class SettingsDialog extends Dialog<Map<String, String>> {

private TextField apiUriField;
private TextField homepageField;

public SettingsDialog(Window window, Preferences preferences) {
super();
Expand Down Expand Up @@ -82,6 +83,10 @@ public SettingsDialog(Window window, Preferences preferences) {
apiUriField.setPrefWidth(260.0);
apiUriField.setText(preferences.get(App.API_URI, ""));

homepageField = new TextField();
homepageField.setPrefWidth(260.0);
homepageField.setText(preferences.get(App.HOMEPAGE, ""));

CheckBox autoLoginCheckBox = new CheckBox();
autoLoginCheckBox.setSelected(preferences.getBoolean(App.AUTOLOGIN, false));

Expand All @@ -91,8 +96,10 @@ public SettingsDialog(Window window, Preferences preferences) {
gridPane.add(passwordField, 1, 1);
gridPane.add(new Label(App.getBundle().getString("settings.apiuri")), 0, 2);
gridPane.add(apiUriField, 1, 2);
gridPane.add(new Label(App.getBundle().getString("settings.autologin")), 0, 3);
gridPane.add(autoLoginCheckBox, 1, 3);
gridPane.add(new Label(App.getBundle().getString("settings.homepage")), 0, 3);
gridPane.add(homepageField, 1, 3);
gridPane.add(new Label(App.getBundle().getString("settings.autologin")), 0, 4);
gridPane.add(autoLoginCheckBox, 1, 4);

getDialogPane().setContent(gridPane);
setResizable(true); // FIXME: Workaround for JavaFX 11
Expand All @@ -113,6 +120,7 @@ public SettingsDialog(Window window, Preferences preferences) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
}
data.put(App.API_URI, apiUriField.getText());
data.put(App.HOMEPAGE, homepageField.getText());
data.put(App.AUTOLOGIN, String.valueOf(autoLoginCheckBox.isSelected()));
return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ shortcuts.download = Open download page
shortcuts.exit = Exit
settings.autologin = Autologin
settings.apiuri = API URI:
settings.homepage = Homepage:
settings.username = Username:
settings.password = password:
settings.save = Save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ shortcuts.exit = Salir
shortcuts.switch_tabs = Cambiar de pesta\u00f1a
settings.autologin = Inicio autom\u00e1tico de sesi\u00f3n
settings.apiuri = URI de la API:
settings.homepage = P\u00e1gina de inicio:
settings.email = Correo electr\u00f3nico:
settings.username = Nombre de usuario:
settings.password = Contrase\u00f1a:
Expand Down

0 comments on commit 383ed74

Please sign in to comment.