Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

[DO NOT MERGE] Application settings #164

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -137,6 +153,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
Expand Down Expand Up @@ -164,6 +185,16 @@
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.192</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/ninja/eivind/hotsreplayuploader/Client.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -35,14 +39,17 @@
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;

/**
* Application entry point. Sets up the actions that connect to the underlying platform.
*/
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@SpringBootApplication
public class Client extends Application implements ApplicationContextAware {

Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -70,4 +74,10 @@ public StormParser stormParser() {
public StatusBinder statusBinder() {
return new StatusBinder();
}

@Bean
@ApplicationHome
public File applicationHomeDirectory(PlatformService platformService) {
return platformService.getApplicationHome();
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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<ConfigurableApplicationContext> {
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.");
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,9 @@ public class HomeController implements JavaFXController, InitializingBean {
@FXML
private Pane nodeHolder;

@FXML
private ImageView settingsIcon;

@Autowired
private PlatformService platformService;
@Autowired
Expand All @@ -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");
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading