mirror of
https://github.com/XITRIX/iTorrent.git
synced 2026-05-30 11:46:50 +00:00
Fix for LiveActivity color
This commit is contained in:
@@ -52,13 +52,14 @@ struct ProgressWidgetAttributes: ActivityAttributes {
|
||||
}
|
||||
|
||||
public struct ContentState: Codable, Hashable {
|
||||
public init(state: State, progress: Double, downSpeed: UInt64, upSpeed: UInt64, timeRemainig: String, timeStamp: Date) {
|
||||
public init(state: State, progress: Double, downSpeed: UInt64, upSpeed: UInt64, timeRemainig: String, timeStamp: Date, color: Data?) {
|
||||
self.state = state
|
||||
self.progress = progress
|
||||
self.downSpeed = downSpeed
|
||||
self.upSpeed = upSpeed
|
||||
self.timeRemainig = timeRemainig
|
||||
self.timeStamp = timeStamp
|
||||
self.color = color
|
||||
}
|
||||
|
||||
// Dynamic stateful properties about your activity go here!
|
||||
@@ -68,6 +69,7 @@ struct ProgressWidgetAttributes: ActivityAttributes {
|
||||
public var upSpeed: UInt64
|
||||
public var timeRemainig: String
|
||||
public var timeStamp: Date
|
||||
public var color: Data?
|
||||
}
|
||||
|
||||
// Fixed non-changing properties about your activity go here!
|
||||
|
||||
@@ -21,6 +21,16 @@ struct ProgressWidgetLiveActivity: Widget {
|
||||
return (try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIColor.self, from: data)) ?? .tintColor
|
||||
}
|
||||
|
||||
func tintColor(from context: ActivityViewContext<ProgressWidgetAttributes>) -> UIColor {
|
||||
if let colorData = context.state.color,
|
||||
let keyColor = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIColor.self, from: colorData)
|
||||
{
|
||||
return keyColor
|
||||
} else {
|
||||
return Self.tintColor
|
||||
}
|
||||
}
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
let config = ActivityConfiguration(for: ProgressWidgetAttributes.self) { context in
|
||||
// Lock screen/banner UI goes here
|
||||
@@ -28,17 +38,17 @@ struct ProgressWidgetLiveActivity: Widget {
|
||||
if #available(iOS 18, *) {
|
||||
#if XCODE16
|
||||
ProgressWidgetLiveActivityWatchSupportContent(context: context)
|
||||
.tint(Color(uiColor: ProgressWidgetLiveActivity.tintColor))
|
||||
.tint(Color(uiColor: tintColor(from: context)))
|
||||
.padding()
|
||||
#else
|
||||
ProgressWidgetLiveActivityContent(context: context)
|
||||
.tint(Color(uiColor: Self.tintColor))
|
||||
.tint(Color(uiColor: tintColor(from: context)))
|
||||
.padding()
|
||||
#endif
|
||||
|
||||
} else {
|
||||
ProgressWidgetLiveActivityContent(context: context)
|
||||
.tint(Color(uiColor: Self.tintColor))
|
||||
.tint(Color(uiColor: tintColor(from: context)))
|
||||
.padding()
|
||||
}
|
||||
} dynamicIsland: { context in
|
||||
|
||||
@@ -73,12 +73,16 @@ private extension LiveActivityService {
|
||||
|
||||
private extension TorrentHandle.Snapshot {
|
||||
var toLiveActivityState: ProgressWidgetAttributes.ContentState {
|
||||
.init(state: friendlyState.toState,
|
||||
let color = PreferencesStorage.shared.tintColor
|
||||
let data = try? NSKeyedArchiver.archivedData(withRootObject: color, requiringSecureCoding: true)
|
||||
|
||||
return .init(state: friendlyState.toState,
|
||||
progress: progress,
|
||||
downSpeed: downloadRate,
|
||||
upSpeed: uploadRate,
|
||||
timeRemainig: timeRemains,
|
||||
timeStamp: Date())
|
||||
timeStamp: Date(),
|
||||
color: data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user