Commit Graph

3 Commits

Author SHA1 Message Date
Samuel Holland
5d5cdf54fa ProfileService: Rework profile updating
This should help discourage editing a Profile without making a copy
first, since the caller has to keep track of the old Profile as well.

ProfileAdder has been updated to prevent adding duplicate profiles. It
checks once in the constructor, so the caller can catch the exception
and pass the error back to the UI. It checks again in the worker thread
to prevent any race from happening if a profile is added twice quickly.
Either the file exists, or it doesn't.

Additionally, this change solves the race condition when the old
profile is removed before it is updated; previously this would lead
to the profile being re-added. Now, ProfileRemover will fail and the
profile will stay removed.

Finally, updating a profile's name should now work correctly. There were
previously multiple bugs with that (the old profile wasn't removed, the
new one could duplicate a name, the new one could overwrite some random
other one, etc.).

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2017-08-01 01:38:39 -05:00
Samuel Holland
8623437185 ProfileService: Expand and document service interface
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2017-07-31 19:06:47 -05:00
Samuel Holland
c65ac9fafe ProfileService: Create it and move profile loading
The long-running service is needed for keeping track of which profiles
are enabled, for showing notifications, and for the tile service to use.
Since it has to know which profiles exist anyway, moving the main
ObservableList there avoids some code duplication. It ensures the list
is only loaded once, so it cannot get out of sync. It also makes the
ProfileList activity load faster, because it doesn't have to wait for
file I/O; and it provides a canonical place for storing the Profile
objects so they are accessible everywhere, instead of having to look
them up by name.

This does present some challenges with leaking activities, because all
listeners must be removed from the profiles list (and its contents) when
an activity is stopped.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2017-07-30 01:48:57 -05:00