Skip to content

Commit

Permalink
Fix for LiveActivity metadata state fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Jul 13, 2024
1 parent 7958d60 commit e7da810
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions ProgressWidget/ProgressWidgetAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ extension ProgressWidgetAttributes.State {
}

struct ProgressWidgetAttributes: ActivityAttributes {
public init(name: String, hash: String) {
self.name = name
public init(hash: String) {
self.hash = hash
}

public struct ContentState: Codable, Hashable {
public init(state: State, progress: Double, downSpeed: UInt64, upSpeed: UInt64, timeRemainig: String, timeStamp: Date, color: Data?) {
public init(name: String, state: State, progress: Double, downSpeed: UInt64, upSpeed: UInt64, timeRemainig: String, timeStamp: Date, color: Data?) {
self.name = name
self.state = state
self.progress = progress
self.downSpeed = downSpeed
Expand All @@ -63,6 +63,7 @@ struct ProgressWidgetAttributes: ActivityAttributes {
}

// Dynamic stateful properties about your activity go here!
public var name: String
public var state: State
public var progress: Double
public var downSpeed: UInt64
Expand All @@ -73,7 +74,6 @@ struct ProgressWidgetAttributes: ActivityAttributes {
}

// Fixed non-changing properties about your activity go here!
public var name: String
public var hash: String
}
#endif
4 changes: 2 additions & 2 deletions ProgressWidget/ProgressWidgetLiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct ProgressWidgetLiveActivity: Widget {
DynamicIslandExpandedRegion(.bottom) {
VStack {
HStack {
Text(context.attributes.name).padding(.top, 2)
Text(context.state.name).padding(.top, 2)
Spacer()
if context.state.state == .downloading {
Text(context.state.timeRemainig)
Expand Down Expand Up @@ -188,7 +188,7 @@ struct ProgressWidgetLiveActivityContent: View {
var body: some View {
VStack(spacing: 8) {
HStack {
Text(context.attributes.name)
Text(context.state.name)
Spacer()

if #available(iOS 17.0, *),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private extension LiveActivityService {
else { return }

for activity in Activity<ProgressWidgetAttributes>.activities {
if activity.attributes.name == snapshot.name {
if activity.attributes.hash == snapshot.infoHashes.best.hex {
if snapshot.friendlyState.shouldShowLiveActivity {
if #available(iOS 16.2, *) {
await activity.update(.init(state: snapshot.toLiveActivityState, staleDate: .now + 10))
Expand All @@ -60,7 +60,7 @@ private extension LiveActivityService {

func showLiveActivity(with snapshot: TorrentHandle.Snapshot) {
if #available(iOS 16.1, *) {
let attributes = ProgressWidgetAttributes(name: snapshot.name, hash: snapshot.infoHashes.best.hex)
let attributes = ProgressWidgetAttributes(hash: snapshot.infoHashes.best.hex)

do {
_ = try Activity<ProgressWidgetAttributes>.request(attributes: attributes, contentState: snapshot.toLiveActivityState, pushType: .none)
Expand All @@ -76,7 +76,8 @@ private extension TorrentHandle.Snapshot {
let color = PreferencesStorage.shared.tintColor
let data = try? NSKeyedArchiver.archivedData(withRootObject: color, requiringSecureCoding: true)

return .init(state: friendlyState.toState,
return .init(name: name,
state: friendlyState.toState,
progress: progress,
downSpeed: downloadRate,
upSpeed: uploadRate,
Expand Down

0 comments on commit e7da810

Please sign in to comment.