mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-06 13:50:58 +08:00
- iPhone「订阅余量」编辑页新增「排在前面的账号」(小/中/大最多 4/6/7 个,可拖动、删除)与「隐藏的账号」; 其余账号(含以后新加的)按电脑顺序跟在后面,全部隐藏时显示全部,与 Mac 菜单栏设置同一思路。 - 所选账号存为 id + 图标 + 名字:各电脑给同一订阅的 id 不同时按图标与名字找回;重复选择只显示一次。 - 小号版式只对其余账号做「订阅优先」,排在前面的照原样显示。 - iPhone 小组件与 Mac 菜单栏面板的液面顶角改为 4pt 圆角(液面很低时按高度缩小),Mac 液面晃动时圆角跟着波形。 - 编辑页文案补齐 10 种语言;DESIGN.md 与 mobile-development.md 登记规则。 Assisted-by: Cindy (https://cindy.app) Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
123 lines
4.4 KiB
Swift
123 lines
4.4 KiB
Swift
import AppIntents
|
|
import WidgetKit
|
|
|
|
/// A computer a widget can show, or "automatic": the one that answered the app last.
|
|
struct ComputerEntity: AppEntity {
|
|
static let autoID = "auto"
|
|
static let automatic = ComputerEntity(id: autoID, name: "")
|
|
|
|
let id: String
|
|
let name: String
|
|
|
|
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Computer"
|
|
static var defaultQuery = ComputerQuery()
|
|
|
|
var displayRepresentation: DisplayRepresentation {
|
|
id == Self.autoID
|
|
? DisplayRepresentation(title: "Automatic", subtitle: "The computer that answered last")
|
|
: DisplayRepresentation(title: "\(name)")
|
|
}
|
|
}
|
|
|
|
/// The computers the app last listed (other computers that allow remote control).
|
|
struct ComputerQuery: EntityQuery {
|
|
func entities(for identifiers: [String]) async throws -> [ComputerEntity] {
|
|
all().filter { identifiers.contains($0.id) }
|
|
}
|
|
|
|
func suggestedEntities() async throws -> [ComputerEntity] {
|
|
all()
|
|
}
|
|
|
|
func defaultResult() async -> ComputerEntity? {
|
|
.automatic
|
|
}
|
|
|
|
private func all() -> [ComputerEntity] {
|
|
[.automatic] + (WidgetStore.load()?.computers.map { ComputerEntity(id: $0.id, name: $0.name) } ?? [])
|
|
}
|
|
}
|
|
|
|
/// An account the quota widget can list: one of the sources a computer sent. The id carries the
|
|
/// logo and name too (`AccountKey`), so a choice still finds the account on another computer.
|
|
struct AccountEntity: AppEntity {
|
|
let key: AccountKey
|
|
|
|
var id: String { key.encoded }
|
|
|
|
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Account"
|
|
static var defaultQuery = AccountQuery()
|
|
|
|
var displayRepresentation: DisplayRepresentation {
|
|
let image = key.logo.map { DisplayRepresentation.Image(named: "logo-\($0)") }
|
|
return DisplayRepresentation(title: "\(key.name)", image: image)
|
|
}
|
|
}
|
|
|
|
/// The accounts of the widget's chosen computer, in that computer's order. Hidden ones on the
|
|
/// computer are not sent, so they are not offered either.
|
|
struct AccountQuery: EntityQuery {
|
|
@IntentParameterDependency<QuotaWidgetIntent>(\.$computer)
|
|
var config
|
|
|
|
func entities(for identifiers: [String]) async throws -> [AccountEntity] {
|
|
identifiers.map { AccountEntity(key: AccountKey(encoded: $0)) }
|
|
}
|
|
|
|
func suggestedEntities() async throws -> [AccountEntity] {
|
|
let sources = WidgetState.load(computer: config?.computer.id).snapshot?.sources ?? []
|
|
return sources.map { AccountEntity(key: AccountKey(source: $0)) }
|
|
}
|
|
}
|
|
|
|
/// What a widget's edit sheet chose; nil or empty means the defaults.
|
|
protocol UsageWidgetConfiguration: WidgetConfigurationIntent {
|
|
var computerID: String? { get }
|
|
/// Accounts placed first, in this order (`AccountKey` strings).
|
|
var pinnedAccounts: [String]? { get }
|
|
/// Accounts left out (`AccountKey` strings).
|
|
var hiddenAccounts: [String]? { get }
|
|
}
|
|
|
|
/// "Data source" in the daily usage widget's edit sheet.
|
|
struct SelectComputerIntent: UsageWidgetConfiguration {
|
|
static var title: LocalizedStringResource = "Data source"
|
|
static var description = IntentDescription("Choose which computer this widget shows.")
|
|
|
|
@Parameter(title: "Computer")
|
|
var computer: ComputerEntity?
|
|
|
|
var computerID: String? { computer?.id }
|
|
var pinnedAccounts: [String]? { nil }
|
|
var hiddenAccounts: [String]? { nil }
|
|
}
|
|
|
|
/// The quota widget's edit sheet, like the Mac menu bar's settings: accounts placed first and
|
|
/// accounts hidden; every other account, including ones added later, follows in the computer's
|
|
/// order.
|
|
struct QuotaWidgetIntent: UsageWidgetConfiguration {
|
|
static var title: LocalizedStringResource = "Data source"
|
|
static var description = IntentDescription(
|
|
"Choose which computer this widget shows, which accounts come first and which to hide. Other accounts, including ones added later, follow in that computer's order."
|
|
)
|
|
|
|
@Parameter(title: "Computer")
|
|
var computer: ComputerEntity?
|
|
|
|
/// Up to what each size shows; a plain number would mean exactly that many, with no way to
|
|
/// remove one or clear the choice.
|
|
@Parameter(title: "Accounts first", size: [
|
|
.systemSmall: IntentCollectionSize(min: 0, max: 4),
|
|
.systemMedium: IntentCollectionSize(min: 0, max: 6),
|
|
.systemLarge: IntentCollectionSize(min: 0, max: 7),
|
|
])
|
|
var pinned: [AccountEntity]?
|
|
|
|
@Parameter(title: "Hidden accounts")
|
|
var hidden: [AccountEntity]?
|
|
|
|
var computerID: String? { computer?.id }
|
|
var pinnedAccounts: [String]? { pinned?.map(\.id) }
|
|
var hiddenAccounts: [String]? { hidden?.map(\.id) }
|
|
}
|