Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce gui app state persistence #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cleydyr
Copy link
Collaborator

@cleydyr cleydyr commented May 6, 2023

Closes #70

@cleydyr cleydyr requested a review from mbaeuerle May 6, 2023 19:45
Copy link
Owner

@mbaeuerle mbaeuerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cleydyr for this implementation.
I think it's a nice addition and can be extended in the future also for things like default crop rect sizes etc.
As stated in the comments I see a human readable file format more fitting for the state but we are on a good way towards that!

Comment on lines +13 to +14
if (osName.contains("Mac OS")) {
_IS_WINDOWS = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant as it's covered in the else case.
I'm wondering if it makes more sense to have a class which returns the default storage location depending on the OS instead.
In case of unix it would return System.getProperty("user.home" and on Windows System.getenv("LOCALAPPDATA").

return (AppState) readObject;
}

throwUnknownAppState();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be thrown whenever we add/change the attributes on the AppState class. So whenever someone already has a stored state and uses a newer Briss version which has these additional attributes, it will immediately crash on start.
Instead we should be defensive and just return no app state (i.e. null).


try (FileInputStream fileInputStream = new FileInputStream(stateFile);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
final Object readObject = objectInputStream.readObject();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java serialized objects have the benefit of being straight forward and not needing additional dependencies.
However they also lack flexibility and a human readable format.

  • Missing flexibility: Whenever the content of the AppState changes, the previously serialized objects can no longer be deserialized, therefore resetting the state
  • Non human readable format: Serialized files are not plain text and cannot be read or changed by a human by just opening the file

Therefore I suggest we use a more versatile approach which uses a human readable format like Json, Yaml or Property files.

I like Jackson for that, as it's easy to map Json properties to field on a class.

Comment on lines +801 to +806
File appStateDestinationFile = new File(System.getProperty("user.home"), ".briss");

if (OSDetector.isWindows()) {
appStateDestinationFile = new File(System.getenv("LOCALAPPDATA"), ".briss");
}

Copy link
Owner

@mbaeuerle mbaeuerle May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File creation is duplicated (code and execution) here

Suggested change
File appStateDestinationFile = new File(System.getProperty("user.home"), ".briss");
if (OSDetector.isWindows()) {
appStateDestinationFile = new File(System.getenv("LOCALAPPDATA"), ".briss");
}
String userHome;
if (OSDetector.isWindows()) {
userHome = System.getenv("LOCALAPPDATA");
} else {
userHome = System.getProperty("user.home");
}
File appStateDestinationFile = new File(userHome, ".briss");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store application state as user configuration
2 participants