add config icon feature

This commit is contained in:
2026-10-09 22:41:45 +08:00
parent 493c70ce81
commit aa028266ee
1621 changed files with 5130 additions and 77 deletions
+18 -1
View File
@@ -46,6 +46,7 @@ struct Provider: TimelineProvider {
playText: playText,
isShutdown: isShutdown,
bgColor: bgColor,
appIconCharacterId: data?.string(forKey: "appIconCharacterId") ?? "default",
isPreview: isPreview
)
}
@@ -62,6 +63,7 @@ private func sampleEntry(family: WidgetFamily, isPreview: Bool) -> ExampleEntry
playText: "",
isShutdown: true,
bgColor: "255,255,255",
appIconCharacterId: "default",
isPreview: isPreview
)
}
@@ -76,6 +78,7 @@ struct ExampleEntry: TimelineEntry {
let playText: String
let isShutdown: Bool
let bgColor: String
let appIconCharacterId: String
let isPreview: Bool
}
@@ -90,6 +93,19 @@ struct HomeWidgetExampleEntryView: View {
self.isWhiteBackground = isWhiteBackground
}
private var selectedAppIcon: UIImage? {
let id = entry.appIconCharacterId
guard id != "default", !id.contains("/"),
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: widgetGroupId)?
.appendingPathComponent("app-icon-\(id)-\(isWhiteBackground ? "light" : "dark").png") else { return nil }
return UIImage(contentsOfFile: url.path)
}
private var appLogo: Image {
if let selected = selectedAppIcon { return Image(uiImage: selected) }
return Image("logo")
}
var body: some View {
let canvas = familyCanvasSize
let cdSize: CGFloat = 140
@@ -157,7 +173,7 @@ struct HomeWidgetExampleEntryView: View {
// 绘制左侧一列歌曲信息
VStack(alignment: .leading) {
Image("logo")
appLogo
.resizable()
.scaledToFit()
.frame(width: 30, height: 30)
@@ -491,6 +507,7 @@ private enum WidgetI18n {
playText: "playing,paused",
isShutdown: true,
bgColor: "255,255,255",
appIconCharacterId: "default",
isPreview: true
)
}