Reply-ограничения: Desktop-parity аудит и фикс .call / system accounts

This commit is contained in:
2026-03-29 18:02:01 +05:00
parent 5e89e97301
commit 469f182155
8 changed files with 254 additions and 56 deletions

View File

@@ -4,7 +4,6 @@ import Foundation
struct CallActivityAttributes: ActivityAttributes {
let peerName: String
let peerPublicKey: String
let avatarData: Data?
let colorIndex: Int
struct ContentState: Codable, Hashable {

View File

@@ -2,26 +2,28 @@ import ActivityKit
import SwiftUI
import WidgetKit
// Mantine v8 avatar palette (11 colors) desktop parity
private let mantineAvatarTints: [Color] = [
Color(red: 0.133, green: 0.545, blue: 0.902), // blue #228be6
Color(red: 0.082, green: 0.667, blue: 0.749), // cyan #15aabf
Color(red: 0.745, green: 0.294, blue: 0.859), // grape #be4bdb
Color(red: 0.251, green: 0.753, blue: 0.341), // green #40c057
Color(red: 0.298, green: 0.431, blue: 0.961), // indigo #4c6ef5
Color(red: 0.510, green: 0.788, blue: 0.118), // lime #82c91e
Color(red: 0.992, green: 0.494, blue: 0.078), // orange #fd7e14
Color(red: 0.902, green: 0.286, blue: 0.502), // pink #e64980
Color(red: 0.980, green: 0.322, blue: 0.322), // red #fa5252
Color(red: 0.071, green: 0.722, blue: 0.525), // teal #12b886
Color(red: 0.475, green: 0.314, blue: 0.949), // violet #7950f2
// Mantine v8 avatar tint colors (shade-6) exact hex values, desktop parity
private let mantineTints: [Color] = [
Color(red: 34/255, green: 139/255, blue: 230/255), // #228be6 blue
Color(red: 21/255, green: 170/255, blue: 191/255), // #15aabf cyan
Color(red: 190/255, green: 75/255, blue: 219/255), // #be4bdb grape
Color(red: 64/255, green: 192/255, blue: 87/255), // #40c057 green
Color(red: 76/255, green: 110/255, blue: 245/255), // #4c6ef5 indigo
Color(red: 130/255, green: 201/255, blue: 30/255), // #82c91e lime
Color(red: 253/255, green: 126/255, blue: 20/255), // #fd7e14 orange
Color(red: 230/255, green: 73/255, blue: 128/255), // #e64980 pink
Color(red: 250/255, green: 82/255, blue: 82/255), // #fa5252 red
Color(red: 18/255, green: 184/255, blue: 134/255), // #12b886 teal
Color(red: 121/255, green: 80/255, blue: 242/255), // #7950f2 violet
]
private let appGroupID = "group.com.rosetta.dev"
@main
struct CallLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: CallActivityAttributes.self) { context in
// MARK: - Lock Screen Banner
// MARK: - Lock Screen
HStack(spacing: 14) {
avatarView(context: context, size: 48, fontSize: 18)
@@ -37,7 +39,7 @@ struct CallLiveActivity: Widget {
.foregroundColor(Color(white: 0.45))
if context.state.isActive {
Text(duration(context.state.durationSec))
Text(fmt(context.state.durationSec))
.font(.system(size: 14, weight: .medium).monospacedDigit())
.foregroundColor(Color(white: 0.55))
} else {
@@ -53,9 +55,7 @@ struct CallLiveActivity: Widget {
}
}
}
Spacer()
ZStack {
Circle().fill(Color.red)
Image(systemName: "phone.down.fill")
@@ -76,11 +76,10 @@ struct CallLiveActivity: Widget {
.padding(.leading, 6)
.padding(.top, 4)
}
DynamicIslandExpandedRegion(.trailing) {
VStack(spacing: 2) {
if context.state.isActive {
Text(duration(context.state.durationSec))
Text(fmt(context.state.durationSec))
.font(.system(size: 16, weight: .bold).monospacedDigit())
.foregroundColor(.green)
} else {
@@ -88,7 +87,6 @@ struct CallLiveActivity: Widget {
.font(.system(size: 16, weight: .bold))
.foregroundColor(.orange)
}
if context.state.isMuted {
Image(systemName: "mic.slash.fill")
.font(.system(size: 11))
@@ -98,7 +96,6 @@ struct CallLiveActivity: Widget {
.padding(.trailing, 6)
.padding(.top, 4)
}
DynamicIslandExpandedRegion(.center) {
Text(context.attributes.peerName)
.font(.system(size: 16, weight: .semibold))
@@ -106,7 +103,6 @@ struct CallLiveActivity: Widget {
.lineLimit(1)
.padding(.top, 4)
}
DynamicIslandExpandedRegion(.bottom) {
HStack(spacing: 5) {
Circle()
@@ -121,13 +117,11 @@ struct CallLiveActivity: Widget {
}
.padding(.top, 4)
}
} compactLeading: {
avatarView(context: context, size: 26, fontSize: 10)
} compactTrailing: {
if context.state.isActive {
Text(duration(context.state.durationSec))
Text(fmt(context.state.durationSec))
.font(.system(size: 13, weight: .semibold).monospacedDigit())
.foregroundColor(.green)
} else {
@@ -135,7 +129,6 @@ struct CallLiveActivity: Widget {
.font(.system(size: 12))
.foregroundColor(.green)
}
} minimal: {
Image(systemName: "phone.fill")
.font(.system(size: 11))
@@ -148,19 +141,17 @@ struct CallLiveActivity: Widget {
@ViewBuilder
private func avatarView(context: ActivityViewContext<CallActivityAttributes>, size: CGFloat, fontSize: CGFloat) -> some View {
if let data = context.attributes.avatarData,
let uiImage = UIImage(data: data) {
Image(uiImage: uiImage)
if let img = loadSharedAvatar() {
Image(uiImage: img)
.resizable()
.scaledToFill()
.frame(width: size, height: size)
.clipShape(Circle())
} else {
let idx = context.attributes.colorIndex
let color = mantineAvatarTints[idx < mantineAvatarTints.count ? idx : 0]
let idx = min(context.attributes.colorIndex, mantineTints.count - 1)
ZStack {
Circle().fill(color)
Text(initials(from: context.attributes.peerName, publicKey: context.attributes.peerPublicKey))
Circle().fill(mantineTints[max(0, idx)])
Text(makeInitials(context.attributes.peerName, context.attributes.peerPublicKey))
.font(.system(size: fontSize, weight: .bold))
.foregroundColor(.white)
}
@@ -168,25 +159,31 @@ struct CallLiveActivity: Widget {
}
}
private func loadSharedAvatar() -> UIImage? {
guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)?
.appendingPathComponent("call_avatar.jpg"),
let data = try? Data(contentsOf: url),
let img = UIImage(data: data) else { return nil }
return img
}
// MARK: - Helpers
private func duration(_ sec: Int) -> String {
private func fmt(_ sec: Int) -> String {
String(format: "%d:%02d", sec / 60, sec % 60)
}
private func initials(from name: String, publicKey: String) -> String {
private func makeInitials(_ name: String, _ pubKey: String) -> String {
let words = name.trimmingCharacters(in: .whitespaces)
.split(whereSeparator: { $0.isWhitespace })
.filter { !$0.isEmpty }
switch words.count {
case 0:
return publicKey.isEmpty ? "?" : String(publicKey.prefix(2)).uppercased()
return pubKey.isEmpty ? "?" : String(pubKey.prefix(2)).uppercased()
case 1:
return String(words[0].prefix(2)).uppercased()
default:
let first = words[0].first.map(String.init) ?? ""
let second = words[1].first.map(String.init) ?? ""
return (first + second).uppercased()
return "\(words[0].prefix(1))\(words[1].prefix(1))".uppercased()
}
}
}