diff --git a/pom.xml b/pom.xml index ac68bbbf..41fd10d8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,20 @@ + + @@ -137,6 +153,11 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-configuration-processor + true + org.springframework.boot spring-boot-starter-jdbc @@ -164,6 +185,16 @@ aws-java-sdk-s3 1.11.192 + + org.yaml + snakeyaml + + + org.projectlombok + lombok + 1.16.18 + provided + junit junit diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/Client.java b/src/main/java/ninja/eivind/hotsreplayuploader/Client.java index a27dcd25..b3364fe0 100644 --- a/src/main/java/ninja/eivind/hotsreplayuploader/Client.java +++ b/src/main/java/ninja/eivind/hotsreplayuploader/Client.java @@ -1,16 +1,18 @@ -// Copyright 2015-2016 Eivind Vegsundvåg -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * Copyright 2015-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package ninja.eivind.hotsreplayuploader; @@ -26,6 +28,8 @@ import ninja.eivind.hotsreplayuploader.services.platform.PlatformNotSupportedException; import ninja.eivind.hotsreplayuploader.services.platform.PlatformService; import ninja.eivind.hotsreplayuploader.services.platform.PlatformServiceFactoryBean; +import ninja.eivind.hotsreplayuploader.settings.ApplicationSettings; +import ninja.eivind.hotsreplayuploader.settings.SettingsFileInitializer; import ninja.eivind.hotsreplayuploader.utils.Constants; import ninja.eivind.hotsreplayuploader.versions.ReleaseManager; import ninja.eivind.hotsreplayuploader.window.builder.SceneBuilderFactory; @@ -35,7 +39,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.*; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; import java.awt.*; import java.net.URL; @@ -43,6 +49,7 @@ /** * Application entry point. Sets up the actions that connect to the underlying platform. */ +@SuppressWarnings("SpringAutowiredFieldsWarningInspection") @SpringBootApplication public class Client extends Application implements ApplicationContextAware { @@ -60,12 +67,16 @@ public class Client extends Application implements ApplicationContextAware { @Autowired private SceneBuilderFactory sceneBuilderFactory; + @Autowired + private ApplicationSettings settings; + private static boolean preloaderSupported; private ConfigurableApplicationContext context; public static void main(String... args) throws Exception { launchArgs = args; + Application.launch(); PlatformService platformService = new PlatformServiceFactoryBean().getObject(); preloaderSupported = platformService.isPreloaderSupported(); if (preloaderSupported) { @@ -92,7 +103,9 @@ public void init() { if(preloaderSupported) { builder.initializers(new ProgressMonitor(this::notifyPreloader)); } - context = builder.headless(false).run(launchArgs); + context = builder.headless(false) + .initializers(new SettingsFileInitializer()) + .run(launchArgs); context.getAutowireCapableBeanFactory().autowireBean(this); //add a shutdown hook to be really sure, resources are closed properly @@ -119,7 +132,9 @@ public void start(final Stage primaryStage) throws Exception { primaryStage.setScene(scene); - primaryStage.show(); + if(!settings.getWindow().isStartMinimized()) { + primaryStage.show(); + } } catch (Exception e) { LOG.error("Failed to start", e); throw e; diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/di/HotSReplayUploaderConfiguration.java b/src/main/java/ninja/eivind/hotsreplayuploader/di/HotSReplayUploaderConfiguration.java index 7fee0cc7..a96861aa 100644 --- a/src/main/java/ninja/eivind/hotsreplayuploader/di/HotSReplayUploaderConfiguration.java +++ b/src/main/java/ninja/eivind/hotsreplayuploader/di/HotSReplayUploaderConfiguration.java @@ -19,7 +19,9 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import javafx.fxml.FXMLLoader; import javafx.util.BuilderFactory; +import ninja.eivind.hotsreplayuploader.di.locations.ApplicationHome; import ninja.eivind.hotsreplayuploader.models.stringconverters.StatusBinder; +import ninja.eivind.hotsreplayuploader.services.platform.PlatformService; import ninja.eivind.hotsreplayuploader.utils.SimpleHttpClient; import ninja.eivind.stormparser.StandaloneBattleLobbyParser; import ninja.eivind.stormparser.StormParser; @@ -29,6 +31,8 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import java.io.File; + @Configuration @ComponentScan() public class HotSReplayUploaderConfiguration { @@ -70,4 +74,10 @@ public StormParser stormParser() { public StatusBinder statusBinder() { return new StatusBinder(); } + + @Bean + @ApplicationHome + public File applicationHomeDirectory(PlatformService platformService) { + return platformService.getApplicationHome(); + } } diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/di/locations/ApplicationHome.java b/src/main/java/ninja/eivind/hotsreplayuploader/di/locations/ApplicationHome.java new file mode 100644 index 00000000..be104fb3 --- /dev/null +++ b/src/main/java/ninja/eivind/hotsreplayuploader/di/locations/ApplicationHome.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ninja.eivind.hotsreplayuploader.di.locations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ + ElementType.METHOD, + ElementType.FIELD, + ElementType.PARAMETER +}) +public @interface ApplicationHome { +} diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/settings/ApplicationSettings.java b/src/main/java/ninja/eivind/hotsreplayuploader/settings/ApplicationSettings.java new file mode 100644 index 00000000..e8efff21 --- /dev/null +++ b/src/main/java/ninja/eivind/hotsreplayuploader/settings/ApplicationSettings.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ninja.eivind.hotsreplayuploader.settings; + +import ninja.eivind.hotsreplayuploader.settings.window.WindowSettings; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +/** + * JavaFX property object for propagating events on changes to settings + */ +@ConfigurationProperties("settings") +public class ApplicationSettings { + + @NestedConfigurationProperty + private final WindowSettings window = new WindowSettings(); + + public WindowSettings getWindow() { + return window; + } + +} diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsConfiguration.java b/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsConfiguration.java new file mode 100644 index 00000000..0e0e59d9 --- /dev/null +++ b/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsConfiguration.java @@ -0,0 +1,26 @@ +/* + * Copyright 2015-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ninja.eivind.hotsreplayuploader.settings; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@SuppressWarnings("EmptyClass") +@Configuration +@EnableConfigurationProperties(ApplicationSettings.class) +public class SettingsConfiguration { +} diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsFileInitializer.java b/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsFileInitializer.java new file mode 100644 index 00000000..bcc24145 --- /dev/null +++ b/src/main/java/ninja/eivind/hotsreplayuploader/settings/SettingsFileInitializer.java @@ -0,0 +1,46 @@ +/* + * Copyright 2015-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ninja.eivind.hotsreplayuploader.settings; + +import ninja.eivind.hotsreplayuploader.services.platform.PlatformService; +import ninja.eivind.hotsreplayuploader.services.platform.PlatformServiceFactoryBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.env.YamlPropertySourceLoader; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.Resource; + +import java.io.File; + +public class SettingsFileInitializer implements ApplicationContextInitializer { + private static final Logger logger = LoggerFactory.getLogger(SettingsFileInitializer.class); + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + try { + PlatformService platformService = new PlatformServiceFactoryBean().getObject(); + Resource resource = applicationContext.getResource(new File(platformService.getApplicationHome(), "settings.yml").toURI().toString()); + YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader(); + PropertySource yamlTestProperties = sourceLoader.load("application-settings", resource, null); + applicationContext.getEnvironment().getPropertySources().addFirst(yamlTestProperties); + } catch (Exception ignored) { + logger.warn("Unable to load settings file. It might not exist yet."); + } + } +} diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/settings/window/WindowSettings.java b/src/main/java/ninja/eivind/hotsreplayuploader/settings/window/WindowSettings.java new file mode 100644 index 00000000..91761ff2 --- /dev/null +++ b/src/main/java/ninja/eivind/hotsreplayuploader/settings/window/WindowSettings.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015-2017 Eivind Vegsundvåg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ninja.eivind.hotsreplayuploader.settings.window; + +import javafx.beans.property.SimpleBooleanProperty; + +public class WindowSettings { + + private final SimpleBooleanProperty startMinimized = new SimpleBooleanProperty(false); + + public boolean isStartMinimized() { + return startMinimized.get(); + } + + public void setStartMinimized(boolean startMinimized) { + this.startMinimized.set(startMinimized); + } + + public SimpleBooleanProperty startMinimizedProperty() { + return startMinimized; + } + +} diff --git a/src/main/java/ninja/eivind/hotsreplayuploader/window/HomeController.java b/src/main/java/ninja/eivind/hotsreplayuploader/window/HomeController.java index 52c04300..ac72bf69 100644 --- a/src/main/java/ninja/eivind/hotsreplayuploader/window/HomeController.java +++ b/src/main/java/ninja/eivind/hotsreplayuploader/window/HomeController.java @@ -20,6 +20,7 @@ import javafx.scene.Node; import javafx.scene.control.Hyperlink; import javafx.scene.control.Label; +import javafx.scene.image.ImageView; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.util.BuilderFactory; @@ -58,6 +59,9 @@ public class HomeController implements JavaFXController, InitializingBean { @FXML private Pane nodeHolder; + @FXML + private ImageView settingsIcon; + @Autowired private PlatformService platformService; @Autowired @@ -82,6 +86,9 @@ public void initialize() { currentContext = loadInitialContext(); uploaderNode = (UploaderNode) currentContext; + settingsIcon.setOnMouseClicked(event -> { + LOG.error("NYI -> Settings icon clicked"); + }); LOG.info("Initialized HomeController"); } diff --git a/src/main/resources/ninja/eivind/hotsreplayuploader/settings/settings-icon.png b/src/main/resources/ninja/eivind/hotsreplayuploader/settings/settings-icon.png new file mode 100644 index 00000000..97ded33b Binary files /dev/null and b/src/main/resources/ninja/eivind/hotsreplayuploader/settings/settings-icon.png differ diff --git a/src/main/resources/ninja/eivind/hotsreplayuploader/window/Home.fxml b/src/main/resources/ninja/eivind/hotsreplayuploader/window/Home.fxml index 0d216cdd..e684e60f 100644 --- a/src/main/resources/ninja/eivind/hotsreplayuploader/window/Home.fxml +++ b/src/main/resources/ninja/eivind/hotsreplayuploader/window/Home.fxml @@ -15,15 +15,24 @@ - + - - - - + + + + + + + + + + + + +