Skip to content

Commit

Permalink
Windows size is now saved | fix where volume level was not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
DBChoco committed May 22, 2022
1 parent c6e929a commit 7f93960
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ On Salawat you can choose to play an Adhan or not, you can import your own audio
- [x] Snapstore
- [x] Add auto start to Windows (only if installed on default path)
- [ ] Fix bugs
- [ ] Fix bug that causes crash after Adhan is played (need more information about the cause)
- [ ] Add loader

#### Probably future updates, inshaAllah:
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/io/github/dbchoco/Salawat/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.dbchoco.Salawat.helpers.*;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
Expand Down Expand Up @@ -64,8 +65,15 @@ public void run(){

launchTrayIcon();


if (UserSettings.windowWidth != 0){
stage.setWidth(UserSettings.windowWidth);
stage.setHeight(UserSettings.windowHeight);
}
else stage.setMaximized(true);
addStageSizeListener(stage);

if(!UserSettings.launchMinimized) {
stage.setMaximized(true);
stage.show();
}

Expand All @@ -76,6 +84,15 @@ private void loadLocale() {
I18N.setLocale(Locale.forLanguageTag(UserSettings.language));
}

private void addStageSizeListener(Stage stage){
ChangeListener<Number> stageSizeListener = (observable, oldValue, newValue) -> {
UserSettings.windowWidth = stage.getWidth();
UserSettings.windowHeight = stage.getHeight();
};
stage.widthProperty().addListener(stageSizeListener);
stage.heightProperty().addListener(stageSizeListener);
}

private void checkForUpdates() {
UpdateChecker updateChecker = new UpdateChecker();
}
Expand Down Expand Up @@ -123,6 +140,15 @@ private void checkFirstTime(){
apiRequester.requestLocation();
}
}

@Override
/**
* When closing the app, settings are saved (especially for window size)
*/
public void stop(){
UserSettings.saveWhenClosing();
}

public static void main(String[] args) {
launch();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/dbchoco/Salawat/app/TrayMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TrayMenu {

private static final Boolean isSupported = FXTrayIcon.isSupported();

public static void launch() {
public static void launch() {
if (isSupported) {
icon = new FXTrayIcon(StageController.getStage(), Main.class.getResource("images/icon.png"));

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/io/github/dbchoco/Salawat/app/UserSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public class UserSettings {
public static Integer asrAdjustments = prefs.getInt("asrAdjustments", 0);
public static Integer maghribAdjustments = prefs.getInt("maghribAdjustments", 0);
public static Integer ishaAdjustments = prefs.getInt("ishaAdjustments", 0);
public static Boolean firstTime = prefs.getBoolean("firstTime", true);

public static Double volume = prefs.getDouble("volume", 0.5);
public static Boolean firstTime = prefs.getBoolean("firstTime", true);
public static Double windowWidth = prefs.getDouble("width", 0);
public static Double windowHeight = prefs.getDouble("height", 0);

public static void saveSetting(String key, Object value) throws ClassNotFoundException {
if (value instanceof String) prefs.put(key, (String) value);
Expand Down Expand Up @@ -112,7 +113,12 @@ public static void saveAllSettings() {
prefs.putInt("asrAdjustments", asrAdjustments);
prefs.putInt("maghribAdjustments", maghribAdjustments);
prefs.putInt("ishaAdjustments", ishaAdjustments);
prefs.putDouble("volume", volume);
prefs.putBoolean("firstTime", firstTime);
}

public static void saveWhenClosing() {
prefs.putDouble("volume", volume);
prefs.putDouble("width", windowWidth);
prefs.putDouble("height", windowHeight);
}
}

0 comments on commit 7f93960

Please sign in to comment.