mlemgroup / mlem

Mlem for Lemmy
https://lemmy.ml/c/mlemapp
GNU General Public License v3.0
180 stars 31 forks source link

Codable Settings #1312

Closed EricBAndrews closed 2 months ago

EricBAndrews commented 2 months ago

Checklist

Pull Request Information

This PR makes Settings codable. This is accomplished through the intermediate CodableSettings struct; Settings should not be made directly codable because doing so results in AppStorage values being updated every time any Settings object is decoded. CodableSettings ultimately should replace Settings entirely, migrating our settings storage from AppStorage to JSON, but that's OOS here; this means that in the interim we do have the slightly awkward situation of duplicating default values between CodableSettings' decoder and Settings itself.

Some logic has been added to PersistenceRepository to save and retrieve settings files. There are two different locations settings files are stored:

The new codable settings enable the following features:

To test migration from v1 settings:

You should see a "Settings Restored" toast and any settings you changed in v1 should be preserved.

EricBAndrews commented 2 months ago

Opened #1323 to handle widget persistence