mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-31 10:37:11 -04:00 
			
		
		
		
	* improvements to error handling, ability to select "Favorites" as a virtual album, fix widgets not showing image when tinting homescreen * dont include isFavorite all the time * remove check for if the album exists this will never run because we default to Album.NONE and its impossible to distinguish between no album selected and album DNE (we dont know what the store ID is, only what iOS gives)
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
| import SwiftUI
 | |
| import WidgetKit
 | |
| 
 | |
| extension Image {
 | |
|   @ViewBuilder
 | |
|   func tintedWidgetImageModifier() -> some View {
 | |
|     if #available(iOS 18.0, *) {
 | |
|       self
 | |
|         .widgetAccentedRenderingMode(.accentedDesaturated)
 | |
|     } else {
 | |
|       self
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| struct ImmichWidgetView: View {
 | |
|   var entry: ImageEntry
 | |
| 
 | |
|   var body: some View {
 | |
|     if entry.image == nil {
 | |
|       VStack {
 | |
|         Image("LaunchImage")
 | |
|           .tintedWidgetImageModifier()
 | |
|         Text(entry.metadata.error?.errorDescription ?? "")
 | |
|           .minimumScaleFactor(0.25)
 | |
|           .multilineTextAlignment(.center)
 | |
|           .foregroundStyle(.secondary)
 | |
|       }
 | |
|       .padding(16)
 | |
|     } else {
 | |
|       ZStack(alignment: .leading) {
 | |
|         Color.clear.overlay(
 | |
|           Image(uiImage: entry.image!)
 | |
|             .resizable()
 | |
|             .tintedWidgetImageModifier()
 | |
|             .scaledToFill()
 | |
| 
 | |
|         )
 | |
|         VStack {
 | |
|           Spacer()
 | |
|           if let subtitle = entry.metadata.subtitle {
 | |
|             Text(subtitle)
 | |
|               .foregroundColor(.white)
 | |
|               .padding(8)
 | |
|               .background(Color.black.opacity(0.6))
 | |
|               .cornerRadius(8)
 | |
|               .font(.system(size: 16))
 | |
|           }
 | |
|         }
 | |
|         .padding(16)
 | |
|       }
 | |
|       .widgetURL(entry.metadata.deepLink)
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| #Preview(
 | |
|   as: .systemMedium,
 | |
|   widget: {
 | |
|     ImmichRandomWidget()
 | |
|   },
 | |
|   timeline: {
 | |
|     let date = Date()
 | |
|     ImageEntry(
 | |
|       date: date,
 | |
|       image: UIImage(named: "ImmichLogo"),
 | |
|       metadata: EntryMetadata(
 | |
|         subtitle: "1 year ago"
 | |
|       )
 | |
|     )
 | |
|   }
 | |
| )
 |