Add 'open recent configuration file on start' option.

Add opened file name to the main pane information label.
Update screenshots
Correct readme
This commit is contained in:
Dmitry Isaenko 2021-10-26 06:51:48 +03:00
parent 9ed015db4d
commit 6e251348f3
13 changed files with 94 additions and 40 deletions

View file

@ -6,9 +6,9 @@
LogiLedus is a Logitech G513 Carbon GUI driver for adjusting backlight and effects.
![Screenshot 1](https://live.staticflickr.com/65535/48932060697_6f60cc4143_o.png)
![Screenshot 2](https://live.staticflickr.com/65535/48931873171_b00c4fd875_o.png)
![Screenshot 3](https://live.staticflickr.com/65535/48931332563_72de8e93ed_o.png)
![Screenshot 1](screenshots/1.png)
![Screenshot 2](screenshots/2.png)
![Screenshot 3](screenshots/3.png)
#### License
@ -52,7 +52,7 @@ Want to support development? Make a donation* (see below):
<a href="https://paypal.me/developersu" title="PayPal"><img src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png" border="0" alt="PayPal Logo" /></a>
[Yandex.Money](https://money.yandex.ru/to/410014301951665)
[ЮMoney](https://yoomoney.ru/to/410014301951665)
*Please note: this is non-commercial application.
@ -61,4 +61,4 @@ Want to support development? Make a donation* (see below):
* [ ] Tray support: tray icon size checks
* [ ] Autoload option in settings
* [ ] Headless mode (CLI)
* [ ] Add opened file name to info pane
* [x] Add opened file name to info pane

View file

@ -6,7 +6,7 @@
<groupId>loper</groupId>
<artifactId>LogiLedus</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.4-SNAPSHOT</version>
<!-- <url></url> -->
<description>

BIN
screenshots/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

BIN
screenshots/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
screenshots/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View file

@ -4,16 +4,17 @@ import java.util.prefs.Preferences;
// Rule application settings
public class AppPreferences {
private Preferences preferences;
public AppPreferences(){
preferences = Preferences.userRoot().node("LogiLedus");
}
private static final Preferences preferences = Preferences.userRoot().node("LogiLedus");
public void setUseTray(boolean value){ preferences.putBoolean("USE_TRAY", value); }
public boolean getUseTray(){ return preferences.getBoolean("USE_TRAY", true); }
public void setTheme(String value){ preferences.put("THEME", value); }
public String getTheme(){ return preferences.get("THEME", "/light.css"); }
public void setRecent(String value){ preferences.put("recent", value); }
public String getRecent(){ return preferences.get("recent", ""); }
public void setOpenRecentPlaylistOnStart(boolean value){ preferences.putBoolean("auto_open_recent", value); }
public boolean getOpenRecentPlaylistOnStart(){ return preferences.getBoolean("auto_open_recent", true); }
}

View file

@ -7,10 +7,9 @@ import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.FileChooser;
import logiledus.*;
import logiledus.About.AboutWindow;
import logiledus.MessagesConsumer;
import logiledus.Config.SettingsFileFormat;
import logiledus.ServiceWindow;
import logiledus.Settings.SettingsWindow;
import logiledus.USB.EffectsThread;
import logiledus.USB.GameModeThread;
@ -25,10 +24,8 @@ import java.util.ResourceBundle;
public class MainController implements Initializable {
@FXML
private KeysLedsController KeysLedsController;
@FXML
private EffectsController EffectsController;
@FXML
private GameModeController GameModeController;
@ -52,13 +49,20 @@ public class MainController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
this.rb = resourceBundle;
AppPreferences preferences = new AppPreferences();
if (preferences.getOpenRecentPlaylistOnStart()){
String recentConfigFileAbsPath = FilesValidator.validate(preferences.getRecent());
if (! recentConfigFileAbsPath.isEmpty())
openConfig(new File(recentConfigFileAbsPath));
}
aboutBtn.setOnAction(actionEvent -> new AboutWindow());
settingsBtn.setOnAction(actionEvent -> new SettingsWindow());
MessagesConsumer.getInstance().setInstance(infoLbl);
MessagesConsumer.getInstance().start();
openBtn.setOnAction(actionEvent -> openConfig());
openBtn.setOnAction(actionEvent -> openConfigButtonAction());
saveBtn.setOnAction(ActionEvent -> saveConfig(false));
saveAsBtn.setOnAction(ActionEvent -> saveConfig(true));
@ -97,12 +101,15 @@ public class MainController implements Initializable {
/**
* For 'Open' button
* */
private void openConfig(){
private void openConfigButtonAction(){
File configFile = getOpenFileChooser();
if (configFile == null)
return;
else
recentPath = configFile.getParentFile().getAbsolutePath();
openConfig(configFile);
}
private void openConfig(File configFile){
ObjectMapper mapper = new ObjectMapper();
SettingsFileFormat setup;
try{
@ -113,6 +120,7 @@ public class MainController implements Initializable {
GameModeController.setConfig(setup.getGameModeKeyCodes());
openedConfigFile = configFile;
infoLbl.setText(configFile.getAbsolutePath());
}
catch (IOException e){
ServiceWindow.getErrorNotification(rb.getString("error_any_title"), rb.getString("error_any_body"));
@ -216,7 +224,7 @@ public class MainController implements Initializable {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(rb.getString("btn_save_as"));
fileChooser.setInitialFileName("keyboard settings.lcfg");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("LogiLed config (*.lcfg)", "*.lcfg"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("LogiLedus config (*.lcfg)", "*.lcfg"));
if (recentPath != null){
File stat = new File(recentPath);
@ -226,4 +234,12 @@ public class MainController implements Initializable {
return fileChooser.showSaveDialog(applyBtn.getScene().getWindow());
}
public void exit(){
AppPreferences preferences = new AppPreferences();
if (openedConfigFile == null)
preferences.setRecent("");
else
preferences.setRecent(openedConfigFile.getAbsolutePath());
}
}

View file

@ -0,0 +1,19 @@
package logiledus;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FilesValidator {
public static String validate(String fileAbsolutePath){
try{
Path locationAsPath = Paths.get(fileAbsolutePath);
if (Files.notExists(locationAsPath) || Files.isDirectory(locationAsPath))
return "";
return fileAbsolutePath;
}
catch (Exception ignored){
return "";
}
}
}

View file

@ -7,6 +7,7 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import logiledus.Controllers.MainController;
import javax.imageio.ImageIO;
import javax.swing.*;
@ -16,7 +17,7 @@ import java.util.Locale;
import java.util.ResourceBundle;
public class MainFx extends Application {
public static final String appVersion = "v1.3";
public static final String appVersion = "v1.4";
private static boolean traySupport = true;
@ -28,6 +29,9 @@ public class MainFx extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
//if (! getParameters().getUnnamed().isEmpty())
// System.out.println(getParameters().getUnnamed().get(0));
AppPreferences appPreferences = new AppPreferences();
if (traySupport) // By default it's enabled, but in case it disabled from CLI, don't touch.
traySupport = appPreferences.getUseTray(); // Otherwise, check against preferences
@ -84,7 +88,11 @@ public class MainFx extends Application {
primaryStage.setScene(mainScene);
primaryStage.show();
primaryStage.setOnHidden(e->MessagesConsumer.getInstance().stop()); // Useless?
MainController controller = loader.getController();
primaryStage.setOnHidden(e->{
MessagesConsumer.getInstance().stop();
controller.exit();
}); // Useless?
}
private void addAppToTray(){
@ -144,19 +152,22 @@ public class MainFx extends Application {
}
public static void main(String[] args) {
if ((args.length > 0)) {
if (args[0].equals("--no-tray")){
traySupport = false;
launch(args);
if ((args.length > 0) && args[0].startsWith("-")){
switch (args[0]){
case "--no-tray":
traySupport = false;
launch(args);
return;
case "-v":
case "--version":
System.out.println("LogiLedus " + appVersion);
return;
}
if (args[0].equals("-v") || args[0].equals("--version"))
System.out.println("LogiLedus " + appVersion);
else
System.out.println("Usage: LogiLedus [KEY]\n" +
" -v, --version\tGet application version\n" +
" --no-tray\tDisable tray support");
System.out.println("Usage: LogiLedus [KEY]\n" +
" -v, --version\tGet application version\n" +
" --no-tray\tDisable tray support");
return;
}
else
launch(args);
launch(args);
}
}

View file

@ -5,6 +5,7 @@ import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.stage.Stage;
import logiledus.AppPreferences;
import logiledus.Mediator;
import java.net.URL;
@ -16,24 +17,27 @@ public class SettingsController implements Initializable {
private Button cancelBtn, okBtn;
@FXML
private CheckBox trayCB, drkThemeCB;
private CheckBox trayCB, drkThemeCB, openRecentCB;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
trayCB.setSelected(Mediator.getInstance().getPreferences().getUseTray());
if (Mediator.getInstance().getPreferences().getTheme().equals("/dark.css"))
drkThemeCB.setSelected(true);
AppPreferences preferences = Mediator.getInstance().getPreferences();
trayCB.setSelected(preferences.getUseTray());
openRecentCB.setSelected(preferences.getOpenRecentPlaylistOnStart());
drkThemeCB.setSelected(preferences.getTheme().equals("/dark.css"));
cancelBtn.setOnAction(actionEvent -> ((Stage) cancelBtn.getScene().getWindow()).close());
okBtn.setOnAction(actionEvent -> {
Mediator.getInstance().getPreferences().setUseTray(trayCB.isSelected());
preferences.setUseTray(trayCB.isSelected());
preferences.setOpenRecentPlaylistOnStart(openRecentCB.isSelected());
if (drkThemeCB.isSelected()) {
Mediator.getInstance().getPreferences().setTheme("/dark.css");
preferences.setTheme("/dark.css");
Mediator.getInstance().setTheme("/dark.css");
}
else {
Mediator.getInstance().getPreferences().setTheme("/light.css");
preferences.setTheme("/light.css");
Mediator.getInstance().setTheme("/light.css");
}
((Stage) cancelBtn.getScene().getWindow()).close();

View file

@ -21,6 +21,7 @@
<children>
<CheckBox fx:id="trayCB" mnemonicParsing="false" text="%setting_tray_support" />
<CheckBox fx:id="drkThemeCB" mnemonicParsing="false" text="%setting_use_dark_theme" />
<CheckBox fx:id="openRecentCB" mnemonicParsing="false" text="%setting_open_recent_on_start" />
</children>
</VBox>
</center>

View file

@ -706,3 +706,4 @@ setting_save_and_close=Save and close
setting_cancel=Cancel
open=Open
setting_use_dark_theme=Use dark theme
setting_open_recent_on_start=Open recent configuration file on application start

View file

@ -32,3 +32,4 @@ setting_cancel=\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C
setting_save_and_close=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u0438 \u0437\u0430\u043A\u0440\u044B\u0442\u044C
open=\u041E\u0442\u043A\u0440\u044B\u0442\u044C
setting_use_dark_theme=\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0442\u0451\u043C\u043D\u0443\u044E \u0442\u0435\u043C\u0443
setting_open_recent_on_start=\u041E\u0442\u043A\u0440\u044B\u0432\u0430\u0442\u044C \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0438\u0439 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043E\u043D\u043D\u044B\u0439 \u0444\u0430\u0439\u043B \u043F\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F