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

Saving State between launches #29

Open
4 tasks
Amzd opened this issue May 15, 2023 · 5 comments
Open
4 tasks

Saving State between launches #29

Amzd opened this issue May 15, 2023 · 5 comments
Labels
feature A feature request

Comments

@Amzd
Copy link
Contributor

Amzd commented May 15, 2023

It would be nice to be able to save state between launches.

  • SavableAppState that conforms to Codable or
  • a Property wrapper for which parts of state should be saved?
  • Save location?
  • ?
@stackotter
Copy link
Owner

I love that idea! That would be really useful. I’ll think about how that would best be done.

@stackotter
Copy link
Owner

Do reckon we could possibly use GSettings? The persistent app state properties can just be converted to json and stored as a string in the settings.

My main reason for suggesting that is that it would solve the issue of having to figure out a good storage location for every different OS that SwiftCrossUI supports.

Alternatively we could probably just find where GSettings stores state on each OS and copy it (so that we're not forced to use their API).

@stackotter
Copy link
Owner

And in terms of how to mark which properties are persistent, we could simplify that with something like this:

protocol AppState: ViewState {
    associatedtype PersistedState: Codable, ViewState

    @Observed
    var persisted: PersistedState
}

struct EmptyPersistedState: Codable {}

extension AppState where PersistedState == EmptyPersistedState {
    @Observed
    var persisted: EmptyPersistedState { EmptyPersistedState() }
}

That means that if someone wants to persist part of their app state they can implement the persisted property, and put all persisted state inside that.

I'm not sure if that code is actually valid, but it's at least close to what I have in mind, it may need some modification.

@Amzd
Copy link
Contributor Author

Amzd commented May 17, 2023

GSettings sounds good!

associatedtype PersistedState: Codable, ViewState

I think currently @observed only works with value types and not reference types, which shouldn't be too hard to fix.

@stackotter
Copy link
Owner

I think currently @observed only works with value types and not reference types, which shouldn't be too hard to fix.

Oh yeah, good catch. I can fix that pretty easily

@stackotter stackotter added the feature A feature request label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request
Projects
None yet
Development

No branches or pull requests

2 participants