Skip to content

Commit

Permalink
Skins via Plugins (#49)
Browse files Browse the repository at this point in the history
* skin refactoring to plugins
  • Loading branch information
farion authored May 20, 2020
1 parent 95ea923 commit 6c8dea0
Show file tree
Hide file tree
Showing 59 changed files with 526 additions and 323 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.correomqtt</groupId>
<artifactId>correomqtt-client</artifactId>
<version>0.11.1</version>
<version>0.12.0</version>

<name>CorreoMQTT</name>
<description>A modern graphical MQTT client using the HiveMQ client library.</description>
Expand Down
36 changes: 29 additions & 7 deletions src/main/java/org/correomqtt/CorreoMqtt.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.correomqtt;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
Expand All @@ -13,7 +17,7 @@
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.correomqtt.business.dispatcher.*;
import org.correomqtt.business.model.SettingsDTO;
import org.correomqtt.business.services.ConfigService;
import org.correomqtt.business.services.SettingsService;
import org.correomqtt.business.utils.VersionUtils;
import org.correomqtt.gui.controller.AlertController;
import org.correomqtt.gui.controller.MainViewController;
Expand Down Expand Up @@ -49,7 +53,7 @@ public void init() throws IOException {

StartupDispatcher.getInstance().addObserver(this);

final SettingsDTO settings = ConfigService.getInstance().getSettings();
final SettingsDTO settings = SettingsService.getInstance().getSettings();

handleVersionMismatch(settings);
setLocale(settings);
Expand All @@ -68,7 +72,8 @@ public void init() throws IOException {
}

PreloadingDispatcher.getInstance().onProgress(resources.getString("preloaderReady"));
ConfigService.getInstance().saveSettings();
SettingsService.getInstance().saveSettings();

}

private void handleVersionMismatch(SettingsDTO settings) {
Expand Down Expand Up @@ -106,7 +111,7 @@ private void setLocale(SettingsDTO settings) {
}
settings.setCurrentLocale(settings.getSavedLocale());
LOGGER.info("Locale is: {}", settings.getSavedLocale());
resources = ResourceBundle.getBundle("org.correomqtt.i18n", ConfigService.getInstance().getSettings().getCurrentLocale());
resources = ResourceBundle.getBundle("org.correomqtt.i18n", SettingsService.getInstance().getSettings().getCurrentLocale());
}

private void checkForUpdates() {
Expand All @@ -127,11 +132,10 @@ public void start(Stage primaryStage) throws Exception {
}

private void loadPrimaryStage(Stage primaryStage) throws IOException {
ConfigService.getInstance().setCssFileName();
String cssPath = ConfigService.getInstance().getCssPath();
String cssPath = SettingsService.getInstance().getCssPath();

FXMLLoader loader = new FXMLLoader(MainViewController.class.getResource("mainView.fxml"),
ResourceBundle.getBundle("org.correomqtt.i18n", ConfigService.getInstance().getSettings().getCurrentLocale()));
ResourceBundle.getBundle("org.correomqtt.i18n", SettingsService.getInstance().getSettings().getCurrentLocale()));
Parent root = loader.load();

mainViewController = loader.getController();
Expand Down Expand Up @@ -184,6 +188,24 @@ private void setupShortcut() {
);
}

private void setLoggerFilePath() {

// Set the path for file logging to user directory.
System.setProperty("correomqtt-logfile", SettingsService.getInstance().getLogPath());

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(lc);
lc.reset();
try {
//I prefer autoConfig() over JoranConfigurator.doConfigure() so I wouldn't need to find the file myself.
ci.autoConfig();
} catch (JoranException e) {
// StatusPrinter will try to log this
e.printStackTrace(); //TODO
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}

@Override
public void onPluginUpdateFailed(String disabledPath) {
AlertHelper.warn(
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/correomqtt/CorreoPreloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javafx.util.Duration;
import org.correomqtt.business.dispatcher.PreloadingDispatcher;
import org.correomqtt.business.dispatcher.PreloadingObserver;
import org.correomqtt.business.services.ConfigService;
import org.correomqtt.business.services.SettingsService;
import org.correomqtt.business.utils.VersionUtils;
import org.correomqtt.gui.controller.PreloaderViewController;
import org.slf4j.LoggerFactory;
Expand All @@ -39,8 +39,7 @@ public CorreoPreloader() {
public void init() throws IOException {
setLoggerFilePath();

ConfigService.getInstance().setCssFileName();
String cssPath = ConfigService.getInstance().getCssPath();
String cssPath = SettingsService.getInstance().getCssPath();

FXMLLoader loader = new FXMLLoader(PreloaderViewController.class.getResource("preloaderView.fxml"));
Parent root = loader.load();
Expand All @@ -56,7 +55,7 @@ public void init() throws IOException {

private void setLoggerFilePath() {
// Set the path for file logging to user directory.
System.setProperty("correomqtt-logfile", ConfigService.getInstance().getLogPath());
System.setProperty("correomqtt-logfile", SettingsService.getInstance().getLogPath());
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, CorreoMqtt.class.getResource("logger-config.xml").getPath());

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.correomqtt.business.exception;

import org.correomqtt.business.services.ConfigService;
import org.correomqtt.business.services.SettingsService;

import java.util.ResourceBundle;

public abstract class CorreoMqttException extends RuntimeException {
static ResourceBundle resources;

CorreoMqttException(){
resources = ResourceBundle.getBundle("org.correomqtt.i18n", ConfigService.getInstance().getSettings().getCurrentLocale());
resources = ResourceBundle.getBundle("org.correomqtt.i18n", SettingsService.getInstance().getSettings().getCurrentLocale());
}

CorreoMqttException(String message){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SettingsDTO {
private Locale currentLocale = null;
private boolean searchUpdates;
private boolean firstStart = true;

@Builder.Default
private String configCreatedWithCorreoVersion = null;

Expand Down
16 changes: 4 additions & 12 deletions src/main/java/org/correomqtt/business/model/ThemeDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.correomqtt.gui.theme.IconMode;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ThemeDTO {

private String name;
private String file;
private String iconMode;

public ThemeDTO(String name, String file, String iconMode) {
this.name = name;
this.file = file;
this.iconMode = iconMode;
}
private IconMode iconMode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class ThemeSettingsDTO {
private ThemeDTO activeTheme;
private List<ThemeDTO> themes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getConnectionId() {
protected abstract void readingError(Exception e);

protected void removeFileIfConnectionDeleted() {
ConfigService.getInstance().getConnectionConfigs().stream()
SettingsService.getInstance().getConnectionConfigs().stream()
.filter(c -> c.getId().equals(getConnectionId()))
.findFirst()
.ifPresentOrElse(c -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;

public class BaseUserFileService {

Expand Down Expand Up @@ -47,7 +43,7 @@ void prepareFile(String id, String filename) throws IOException {
}

if (!targetFile.exists()) {
try (InputStream inputStream = ConfigService.class.getResourceAsStream(filename)) {
try (InputStream inputStream = SettingsService.class.getResourceAsStream(filename)) {
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);

Expand All @@ -64,6 +60,20 @@ void prepareFile(String configFileName) throws IOException {
prepareFile(null, configFileName);
}

void saveToUserDirectory(String filename, String content) {

String targetDirectoryPath = getTargetDirectoryPath();
if (!new File(targetDirectoryPath).exists() && !new File(targetDirectoryPath).mkdir()) {
ConfigDispatcher.getInstance().onConfigDirectoryEmpty();
}

try (BufferedWriter writer = new BufferedWriter(new FileWriter(targetDirectoryPath + File.separator + filename))) {
writer.write(content);
} catch (IOException e) {
e.printStackTrace();//TODO
}
}

public boolean isMacOS() {
return OPERATING_SYSTEM.contains("mac os");
}
Expand Down
Loading

0 comments on commit 6c8dea0

Please sign in to comment.