From 6742eb002467c862635b3ee7b4e9ba79264f7b18 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Tue, 23 Feb 2021 22:48:22 +0100 Subject: [PATCH 1/5] feat: add developer mode execution profile --- owlplug-client/pom.xml | 5 +++++ owlplug-client/src/main/java/com/owlplug/OwlPlug.java | 7 ++++++- .../com/owlplug/core/components/ApplicationDefaults.java | 1 + .../src/main/resources/application-dev-mode.properties | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 owlplug-client/src/main/resources/application-dev-mode.properties diff --git a/owlplug-client/pom.xml b/owlplug-client/pom.xml index 86f2a64e..7a60816c 100644 --- a/owlplug-client/pom.xml +++ b/owlplug-client/pom.xml @@ -72,6 +72,11 @@ spring-boot-starter-cache + + org.springframework.boot + spring-boot-starter-jetty + + org.springframework.boot spring-boot-starter-test diff --git a/owlplug-client/src/main/java/com/owlplug/OwlPlug.java b/owlplug-client/src/main/java/com/owlplug/OwlPlug.java index 015cc891..1b869a27 100644 --- a/owlplug-client/src/main/java/com/owlplug/OwlPlug.java +++ b/owlplug-client/src/main/java/com/owlplug/OwlPlug.java @@ -59,6 +59,7 @@ public class OwlPlug extends Application { @Autowired private Environment environment; + private Preferences preferences = Preferences.userRoot().node("com.owlplug.user"); private ConfigurableApplicationContext context; private Parent rootNode; @@ -73,6 +74,10 @@ public void init() throws Exception { try { SpringApplicationBuilder builder = new SpringApplicationBuilder(OwlPlug.class); builder.headless(false); + + if(preferences.getBoolean(ApplicationDefaults.DEVELOPER_MODE_ENABLED_KEY, false)) { + builder.profiles("dev-mode"); + } context = builder.run(getParameters().getRaw().toArray(new String[0])); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MainView.fxml")); @@ -146,7 +151,7 @@ public DataSource datasource() throws PropertyVetoException { */ @Bean public Preferences getPreference() { - return Preferences.userRoot().node("com.owlplug.user"); + return preferences; } diff --git a/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java b/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java index 155f37d3..b4bd2731 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java +++ b/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java @@ -82,6 +82,7 @@ public class ApplicationDefaults { public static final String STORE_SUBDIRECTORY_ENABLED = "STORE_SUBDIRECTORY_ENABLED"; public static final String FIRST_LAUNCH_KEY = "FIRST_LAUNCH_KEY"; public static final String APPLICATION_STATE_KEY = "APPLICATION_STATE_KEY"; + public static final String DEVELOPER_MODE_ENABLED_KEY = "DEVELOPER_MODE_ENABLED_KEY"; /** * Creates a new ApplicationDefaults. diff --git a/owlplug-client/src/main/resources/application-dev-mode.properties b/owlplug-client/src/main/resources/application-dev-mode.properties new file mode 100644 index 00000000..e537f1e2 --- /dev/null +++ b/owlplug-client/src/main/resources/application-dev-mode.properties @@ -0,0 +1,5 @@ +spring.main.web-application-type=SERVLET +spring.main.web-environment=true + +server.host=127.0.0.1 +server.port=0 From 0a59311a3a0102838b18854cb45c44f62342f220 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Thu, 25 Feb 2021 22:38:42 +0100 Subject: [PATCH 2/5] feat: add developer mode on Options view --- .../core/controllers/OptionsController.java | 24 +++++++++++++++++++ .../src/main/resources/fxml/OptionsView.fxml | 14 ++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java b/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java index d3eae62b..2416e45d 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java +++ b/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java @@ -88,6 +88,14 @@ public class OptionsController extends BaseController { private Label storeDirectorySeperator; @FXML private Hyperlink owlplugWebsiteLink; + + @FXML + private JFXCheckBox devModeCheckBox; + @FXML + private JFXTextField devModeTextField; + @FXML + private JFXButton devModeButton; + /** * FXML initialize method. @@ -211,6 +219,13 @@ public void initialize() { owlplugWebsiteLink.setOnAction(e -> { PlatformUtils.openDefaultBrowser(owlplugWebsiteLink.getText()); }); + + + devModeCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> { + this.getPreferences().putBoolean(ApplicationDefaults.DEVELOPER_MODE_ENABLED_KEY, newValue); + devModeTextField.setVisible(newValue); + devModeButton.setVisible(newValue); + }); refreshView(); } @@ -237,6 +252,15 @@ public void refreshView() { if(!storeByCreatorCheckBox.isSelected()){ storeByCreatorLabel.setVisible(false); } + + devModeCheckBox.setSelected(this.getPreferences().getBoolean(ApplicationDefaults.DEVELOPER_MODE_ENABLED_KEY, false)); + if(devModeCheckBox.isSelected()) { + devModeTextField.setVisible(true); + devModeButton.setVisible(true); + } else { + devModeTextField.setVisible(false); + devModeButton.setVisible(false); + } } } diff --git a/owlplug-client/src/main/resources/fxml/OptionsView.fxml b/owlplug-client/src/main/resources/fxml/OptionsView.fxml index 5f7ee7d7..45d67ab6 100644 --- a/owlplug-client/src/main/resources/fxml/OptionsView.fxml +++ b/owlplug-client/src/main/resources/fxml/OptionsView.fxml @@ -111,7 +111,7 @@ @@ -138,6 +138,18 @@ + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + org.springframework spring-web - + org.springframework.boot spring-boot-starter-data-jpa @@ -73,8 +85,8 @@ - org.springframework.boot - spring-boot-starter-jetty + org.springframework.boot + spring-boot-starter-jetty diff --git a/owlplug-client/src/main/java/com/owlplug/core/controllers/PluginsController.java b/owlplug-client/src/main/java/com/owlplug/core/controllers/PluginsController.java index 7673fce3..83bc93e2 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/controllers/PluginsController.java +++ b/owlplug-client/src/main/java/com/owlplug/core/controllers/PluginsController.java @@ -19,6 +19,18 @@ package com.owlplug.core.controllers; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.prefs.Preferences; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXTabPane; import com.jfoenix.controls.JFXTextField; @@ -26,7 +38,6 @@ import com.owlplug.core.components.ApplicationDefaults; import com.owlplug.core.components.CoreTaskFactory; import com.owlplug.core.controllers.dialogs.NewLinkController; -import com.owlplug.core.dao.PluginDAO; import com.owlplug.core.dao.SymlinkDAO; import com.owlplug.core.model.IDirectory; import com.owlplug.core.model.Plugin; @@ -36,12 +47,7 @@ import com.owlplug.core.ui.CustomTreeCell; import com.owlplug.core.ui.FilterableTreeItem; import com.owlplug.core.utils.FileUtils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.prefs.Preferences; + import javafx.beans.binding.Bindings; import javafx.fxml.FXML; import javafx.scene.control.TreeCell; @@ -49,10 +55,6 @@ import javafx.scene.control.TreeView; import javafx.scene.image.ImageView; import javafx.util.Callback; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; @Controller public class PluginsController extends BaseController { @@ -62,8 +64,6 @@ public class PluginsController extends BaseController { @Autowired private PluginService pluginService; @Autowired - private PluginDAO pluginDAO; - @Autowired private SymlinkDAO symlinkDAO; @Autowired private NodeInfoController nodeInfoController; @@ -159,7 +159,7 @@ public TreeCell call(TreeView p) { public void refreshPlugins() { treePluginNode.getInternalChildren().clear(); - this.pluginList = pluginDAO.findAll(); + this.pluginList = pluginService.findAll(); for (Plugin plugin : pluginList) { diff --git a/owlplug-client/src/main/java/com/owlplug/core/controllers/web/PluginRestController.java b/owlplug-client/src/main/java/com/owlplug/core/controllers/web/PluginRestController.java new file mode 100644 index 00000000..7e27b0ce --- /dev/null +++ b/owlplug-client/src/main/java/com/owlplug/core/controllers/web/PluginRestController.java @@ -0,0 +1,21 @@ +package com.owlplug.core.controllers.web; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.owlplug.core.model.Plugin; +import com.owlplug.core.services.PluginService; + +@RestController +public class PluginRestController { + + @Autowired + private PluginService pluginService; + + @GetMapping("/plugins") + public Iterable plugins() { + return pluginService.findAll(); + } + +} diff --git a/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java b/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java index 8e3be895..0fb56097 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java +++ b/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java @@ -77,6 +77,10 @@ public String resolveImageUrl(Plugin plugin) { } + public Iterable findAll() { + return pluginDAO.findAll(); + } + /** * Removes a plugin reference from database. * @param plugin - plugin to remoeve From d84b1bd10800a33473e2859e7e0dafc44ba26543 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Mon, 1 Mar 2021 22:23:30 +0100 Subject: [PATCH 4/5] feat: register dev server url --- .../core/components/WebServerContext.java | 53 +++++++++++++++++++ .../components/WebServerEventListener.java | 22 ++++++++ .../core/controllers/OptionsController.java | 15 ++++++ 3 files changed, 90 insertions(+) create mode 100644 owlplug-client/src/main/java/com/owlplug/core/components/WebServerContext.java create mode 100644 owlplug-client/src/main/java/com/owlplug/core/components/WebServerEventListener.java diff --git a/owlplug-client/src/main/java/com/owlplug/core/components/WebServerContext.java b/owlplug-client/src/main/java/com/owlplug/core/components/WebServerContext.java new file mode 100644 index 00000000..adddcd8f --- /dev/null +++ b/owlplug-client/src/main/java/com/owlplug/core/components/WebServerContext.java @@ -0,0 +1,53 @@ +package com.owlplug.core.components; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class WebServerContext { + + private int port; + @Value("${server.host:@null}") + private String host; + @Value("${server.contextPath:/}") + private String contextPath; + + private boolean serverStarted; + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getContextPath() { + return contextPath; + } + + public void setContextPath(String contextPath) { + this.contextPath = contextPath; + } + + public boolean isServerStarted() { + return serverStarted; + } + + public void setServerStarted(boolean serverStarted) { + this.serverStarted = serverStarted; + } + + public String getUrl() { + return "http://" + this.host + ":" + this.port + this.contextPath; + } + +} diff --git a/owlplug-client/src/main/java/com/owlplug/core/components/WebServerEventListener.java b/owlplug-client/src/main/java/com/owlplug/core/components/WebServerEventListener.java new file mode 100644 index 00000000..07afc85a --- /dev/null +++ b/owlplug-client/src/main/java/com/owlplug/core/components/WebServerEventListener.java @@ -0,0 +1,22 @@ +package com.owlplug.core.components; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +@Component +public class WebServerEventListener implements ApplicationListener { + + @Autowired + private WebServerContext webServerContext; + + @Override + public void onApplicationEvent(WebServerInitializedEvent event) { + webServerContext.setPort(event.getWebServer().getPort()); + webServerContext.setServerStarted(true); + + + } + +} diff --git a/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java b/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java index 2416e45d..6d16d045 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java +++ b/owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java @@ -26,6 +26,7 @@ import com.jfoenix.controls.JFXTextField; import com.jfoenix.controls.JFXToggleButton; import com.owlplug.core.components.ApplicationDefaults; +import com.owlplug.core.components.WebServerContext; import com.owlplug.core.services.NativeHostService; import com.owlplug.core.services.OptionsService; import com.owlplug.core.utils.PlatformUtils; @@ -46,6 +47,8 @@ public class OptionsController extends BaseController { private OptionsService optionsService; @Autowired private NativeHostService nativeHostService; + @Autowired + private WebServerContext webServerContext; @FXML private JFXToggleButton vst2ToggleButton; @@ -226,6 +229,12 @@ public void initialize() { devModeTextField.setVisible(newValue); devModeButton.setVisible(newValue); }); + + devModeButton.setOnAction(e -> { + if(webServerContext.isServerStarted()) { + PlatformUtils.openDefaultBrowser(webServerContext.getUrl()); + } + }); refreshView(); } @@ -257,10 +266,16 @@ public void refreshView() { if(devModeCheckBox.isSelected()) { devModeTextField.setVisible(true); devModeButton.setVisible(true); + } else { devModeTextField.setVisible(false); devModeButton.setVisible(false); } + + if(webServerContext.isServerStarted()) { + devModeTextField.setText(webServerContext.getUrl()); + } + } } From b0ce3c82c8d9db81c77a4c5ab8be160d8051233f Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Wed, 17 Mar 2021 22:34:07 +0100 Subject: [PATCH 5/5] feat: disable developer mode if startup fails --- owlplug-client/src/main/java/com/owlplug/OwlPlug.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/owlplug-client/src/main/java/com/owlplug/OwlPlug.java b/owlplug-client/src/main/java/com/owlplug/OwlPlug.java index 1b869a27..47e93d4f 100644 --- a/owlplug-client/src/main/java/com/owlplug/OwlPlug.java +++ b/owlplug-client/src/main/java/com/owlplug/OwlPlug.java @@ -98,6 +98,10 @@ public void init() throws Exception { throw e; } catch (Exception e) { log.error("OwlPlug could not be started", e); + if(preferences.getBoolean(ApplicationDefaults.DEVELOPER_MODE_ENABLED_KEY, false)) { + log.info("Disabling developer mode after unexpected error during startup"); + preferences.putBoolean(ApplicationDefaults.DEVELOPER_MODE_ENABLED_KEY, false); + } notifyPreloader(new PreloaderProgressMessage("error", "OwlPlug could not be started")); throw e; }