-
Notifications
You must be signed in to change notification settings - Fork 48
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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!
if (osName.contains("Mac OS")) { | ||
_IS_WINDOWS = false; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
File appStateDestinationFile = new File(System.getProperty("user.home"), ".briss"); | ||
|
||
if (OSDetector.isWindows()) { | ||
appStateDestinationFile = new File(System.getenv("LOCALAPPDATA"), ".briss"); | ||
} | ||
|
There was a problem hiding this comment.
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
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"); |
Closes #70