Skip to content

Commit

Permalink
Fix sound settings path on Linux
Browse files Browse the repository at this point in the history
Also let you actually select another path if the current sound directory doesn't exist.
  • Loading branch information
zapek committed Jan 19, 2025
1 parent 4366ec9 commit 6d4a4dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 by David Gerber - https://zapek.com
* Copyright (c) 2024-2025 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
Expand Down Expand Up @@ -91,11 +91,11 @@ public class SettingsSoundController implements SettingsController
private final SoundSettings soundSettings;
private final SoundService soundService;

public SettingsSoundController(ResourceBundle bundle, SoundSettings soundSettings, SoundService soundService, SoundService soundService1)
public SettingsSoundController(ResourceBundle bundle, SoundSettings soundSettings, SoundService soundService)
{
this.bundle = bundle;
this.soundSettings = soundSettings;
this.soundService = soundService1;
this.soundService = soundService;
}

@Override
Expand All @@ -121,7 +121,7 @@ private void initializeSoundPath(CheckBox checkbox, TextField path, Button pathS
if (!path.getText().isEmpty())
{
fileChooser.setInitialFileName(path.getText());
fileChooser.setInitialDirectory(Path.of(path.getText()).getParent().toFile());
setInitialDirectoryIfExists(fileChooser, path.getText());
}
var selectedFile = fileChooser.showOpenDialog(UiUtils.getWindow(event));
if (selectedFile != null && selectedFile.isFile())
Expand All @@ -132,6 +132,19 @@ private void initializeSoundPath(CheckBox checkbox, TextField path, Button pathS
playButton.setOnAction(actionEvent -> soundService.play(path.getText()));
}

private static void setInitialDirectoryIfExists(FileChooser fileChooser, String path)
{
var parent = Path.of(path).getParent();
if (parent != null)
{
var file = parent.toFile();
if (file.exists() && file.isDirectory())
{
fileChooser.setInitialDirectory(file);
}
}
}

@Override
public void onLoad(Settings settings)
{
Expand Down
13 changes: 8 additions & 5 deletions ui/src/main/java/io/xeres/ui/support/sound/SoundSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 by David Gerber - https://zapek.com
* Copyright (c) 2024-2025 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
Expand All @@ -20,6 +20,7 @@
package io.xeres.ui.support.sound;

import io.xeres.ui.support.preference.PreferenceUtils;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.stereotype.Service;

import static io.xeres.ui.support.preference.PreferenceUtils.SOUND;
Expand Down Expand Up @@ -149,10 +150,12 @@ private void loadIfNeeded()
friendEnabled = node.getBoolean(ENABLE_FRIEND, false);
downloadEnabled = node.getBoolean(ENABLE_DOWNLOAD, false);

messageFile = node.get(MESSAGE_FILE, "app/sounds/message-notification-190034.mp3");
highlightFile = node.get(HIGHLIGHT_FILE, "app/sounds/notification-4-126507.mp3");
friendFile = node.get(FRIEND_FILE, "app/sounds/notification-20-270145.mp3");
downloadFile = node.get(DOWNLOAD_FILE, "app/sounds/achive-sound-132273.mp3");
var prefixPath = SystemUtils.IS_OS_LINUX ? "../lib/" : "";

messageFile = node.get(MESSAGE_FILE, prefixPath + "app/sounds/message-notification-190034.mp3");
highlightFile = node.get(HIGHLIGHT_FILE, prefixPath + "app/sounds/notification-4-126507.mp3");
friendFile = node.get(FRIEND_FILE, prefixPath + "app/sounds/notification-20-270145.mp3");
downloadFile = node.get(DOWNLOAD_FILE, prefixPath + "app/sounds/achive-sound-132273.mp3");

loaded = true;
}
Expand Down

0 comments on commit 6d4a4dc

Please sign in to comment.