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

[Fix] NextUp Updates Require Restart #1280

Merged
merged 3 commits into from
Oct 17, 2024
Merged

Conversation

JPKribs
Copy link
Contributor

@JPKribs JPKribs commented Oct 17, 2024

Issue

Fixes #1279.

When I made this change: #1258 (comment), I updated the maxNextUp and resumeNextUp settings to use let constants. However, this introduced an issue where you cannot update the values for maxNextUp or resumeNextUp without restarting Swiftfin. Changing them to var doesn’t fully resolve the problem either, as the values still don’t update dynamically.

PR Fix

If I revert the change from #1258 (comment), the issue is resolved.

Alternative Fix

I also explored another approach that allows these values to update dynamically without requiring a restart. The fix uses Published properties in combination with Defaults.publisher to observe changes and update the values in real-time.

@Published 
private(set) var maxNextUp: TimeInterval = Defaults[.Customization.Home.maxNextUp]
@Published 
private(set) var resumeNextUp: Bool = Defaults[.Customization.Home.resumeNextUp]

init() {
    Defaults.publisher(.Customization.Home.maxNextUp)
        .map { $0.newValue }
        .assign(to: &$maxNextUp)

    Defaults.publisher(.Customization.Home.resumeNextUp)
        .map { $0.newValue }
        .assign(to: &$resumeNextUp)

    // Other init code...
}

Let me know if we want to go the alternative route or if there is a better solution I haven't explored yet! For this PR, I chose to start with the 4 line change vs the 20 line change.

Copy link
Member

@LePips LePips left a comment

Choose a reason for hiding this comment

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

Per my comment, the wrappers shouldn't be used in non-View contexts.

use the subscript instead at the usage sites

I must have missed making sure these were used correctly, but instead of making properties of the class use the Defaults[.Customization.Home.maxNextUp] in the function.

@JPKribs
Copy link
Contributor Author

JPKribs commented Oct 17, 2024

Apologies on this! I was copying a usage I saw elsewhere but using them in-function resolves this issue too.

While I'm looking at this, is this the best way to do this? Using nextUpDateCutoff = 0 creates different results than not including the parameter.

This is what I currently have, which starts feeling a little worse now we have to call Defaults[.Customization.Home.maxNextUp] twice. I could create a Defaults[.Customization.Home.limitMaxNextUp] toggle if we think that is better. I was just trying to mirror other clients with the single input field but while I'm changing this, I thought I would check this:

if Defaults[.Customization.Home.maxNextUp] > 0 {
    parameters.nextUpDateCutoff = Date.now.addingTimeInterval(-Defaults[.Customization.Home.maxNextUp])
}

@LePips
Copy link
Member

LePips commented Oct 17, 2024

You can just have a local variable:

let maxNextUp = Defaults[.Customization.Home.maxNextUp]
if maxNextUp > 0 {
    parameters.nextUpDateCutoff = Date.now.addingTimeInterval(-maxNextUp)
}

Yes, we need to account for 0 because iirc the server doesn't.

@JPKribs
Copy link
Contributor Author

JPKribs commented Oct 17, 2024

let maxNextUp = Defaults[.Customization.Home.maxNextUp]
if maxNextUp > 0 {
    parameters.nextUpDateCutoff = Date.now.addingTimeInterval(-maxNextUp)
}

Sounds good. Committed this change. I did a quick test with 0, 7, 31, & 1000. All look good and refreshing correctly.

@LePips LePips merged commit edf56e7 into jellyfin:main Oct 17, 2024
4 checks passed
@JPKribs JPKribs deleted the nextUpUpdateFix branch October 17, 2024 20:57
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.

NextUpViewModel Not Updating After Changing ‘Days in Next Up’
2 participants