@@ -10,6 +10,8 @@ struct DetailView: View {
1010 @ ObservedObject var suggestionStore = SuggestionStore . shared
1111 @ ObservedObject var detailsStore = AppDetailsStore . shared
1212 @ ObservedObject var categoryStore = CustomCategoryStore . shared
13+ @ ObservedObject var imports = ManualImportStore . shared
14+ @ ObservedObject var library = AppLibrary . shared
1315 var onCreateCategory : ( ) -> Void = { }
1416 @ State private var tab = " overview "
1517 @ State private var local = LocalAppDetails ( )
@@ -84,15 +86,13 @@ struct DetailView: View {
8486 }
8587 ViewThatFits ( in : . horizontal ) {
8688 HStack ( spacing : 8 ) {
87- openButton
88- if let details { Link ( preferences . text ( " info.appStore " ) , destination : details . storeURL ) }
89- Button ( preferences . text ( " detail.reveal " ) , action : app . reveal )
89+ if app . origin != . manual { openButton }
90+ headerActions
9091 }
9192 HStack ( spacing : 8 ) {
92- openButton
93+ if app . origin != . manual { openButton }
9394 Menu {
94- if let details { Link ( preferences . text ( " info.appStore " ) , destination : details . storeURL ) }
95- Button ( preferences . text ( " detail.reveal " ) , action : app . reveal )
95+ headerActions
9696 } label : {
9797 Label ( preferences . text ( " info.more " ) , systemImage : " ellipsis " )
9898 }
@@ -111,6 +111,29 @@ struct DetailView: View {
111111 . padding ( 24 )
112112 }
113113
114+ @ ViewBuilder private var headerActions : some View {
115+ if let destination = storeDestination {
116+ Link ( preferences . text ( app . origin == . manual ? " info.viewStore " : " info.appStore " ) , destination : destination )
117+ }
118+ if app . origin == . manual {
119+ Button ( preferences . text ( " import.remove " ) , action : removeImport )
120+ } else {
121+ Button ( preferences . text ( " detail.reveal " ) , action : app . reveal )
122+ }
123+ }
124+
125+ private var storeDestination : URL ? {
126+ if let details { return details . storeURL }
127+ guard app . origin == . manual , let id = app . appStoreID else { return nil }
128+ return URL ( string : " https://apps.apple.com/ \( app . storeCountryCode ) /app/id \( id ) " )
129+ }
130+
131+ private func removeImport ( ) {
132+ guard let id = app . appStoreID else { return }
133+ imports . remove ( id )
134+ library . reloadImports ( )
135+ }
136+
114137 private var openButton : some View {
115138 Button ( action : app . open ) {
116139 Label ( preferences . text ( " detail.open " ) , systemImage : " arrow.up.forward " )
@@ -180,6 +203,10 @@ struct DetailView: View {
180203 . help ( preferences . text ( " info.fetchedAt " ) )
181204 }
182205 . transition ( . opacity )
206+ } else if app . origin == . manual && ! loading {
207+ Label ( preferences . text ( " category.manual " ) , systemImage : " square.and.arrow.down " )
208+ . font ( . caption ) . foregroundStyle ( . secondary )
209+ . transition ( . opacity )
183210 } else {
184211 Label ( preferences . text ( loading ? " info.loading " : " info.localSource " ) ,
185212 systemImage : loading ? " arrow.triangle.2.circlepath " : " desktopcomputer " )
@@ -404,7 +431,11 @@ struct AppInformationCard: View {
404431 }
405432 add ( " info.appID " , ( listing ? . trackId ?? app . appStoreID ) . map ( String . init ) )
406433 add ( " detail.bundle " , app . bundleID ?? listing ? . bundleId )
407- add ( " info.installedVersion " , app . version )
434+ if app . origin == . manual {
435+ if listing ? . version == nil { add ( " info.storeVersion " , app . version ) }
436+ } else {
437+ add ( " info.installedVersion " , app . version )
438+ }
408439 add ( " info.storeVersion " , listing ? . version )
409440 add ( " info.price " , price )
410441 if let size = listing ? . fileSizeBytes . flatMap ( Int64 . init ) , size >= 0 {
@@ -450,9 +481,12 @@ struct AppInformationCard: View {
450481 }
451482
452483 private var copyText : String {
453- ( values . map { preferences . text ( $0 . key ) + " : " + $0 . value }
454- + requirements . map { $0 . platform + " : " + $0 . text }
455- + [ preferences . text ( " detail.location " ) + " : " + app . path ] ) . joined ( separator : " \n " )
484+ var lines = values . map { preferences . text ( $0 . key ) + " : " + $0 . value }
485+ + requirements . map { $0 . platform + " : " + $0 . text }
486+ if app . origin != . manual {
487+ lines . append ( preferences . text ( " detail.location " ) + " : " + app . path )
488+ }
489+ return lines . joined ( separator : " \n " )
456490 }
457491
458492 var body : some View {
@@ -462,7 +496,9 @@ struct AppInformationCard: View {
462496 VStack ( spacing : 0 ) {
463497 ForEach ( values ) { item in
464498 infoRow ( preferences . text ( item . key ) , value : item . value )
465- Divider ( ) . opacity ( 0.65 )
499+ if item . id != values . last ? . id || hasInformationFooter {
500+ Divider ( ) . opacity ( 0.65 )
501+ }
466502 }
467503 if ! requirements . isEmpty {
468504 VStack ( alignment : . leading , spacing : 12 ) {
@@ -476,17 +512,25 @@ struct AppInformationCard: View {
476512 }
477513 }
478514 . frame ( maxWidth : . infinity , alignment : . leading ) . padding ( . vertical , 13 )
479- Divider ( ) . opacity ( 0.65 )
515+ if app . origin != . manual || ( local . copyright ? . isEmpty == false ) {
516+ Divider ( ) . opacity ( 0.65 )
517+ }
518+ }
519+ if app . origin != . manual {
520+ infoRow ( preferences . text ( " detail.location " ) , value : app . path )
480521 }
481- infoRow ( preferences . text ( " detail.location " ) , value : app . path )
482522 if let copyright = local . copyright , ! copyright . isEmpty {
483- Divider ( ) . opacity ( 0.65 )
523+ if app . origin != . manual { Divider ( ) . opacity ( 0.65 ) }
484524 infoRow ( preferences . text ( " info.copyright " ) , value : copyright )
485525 }
486526 }
487527 }
488528 }
489529
530+ private var hasInformationFooter : Bool {
531+ ! requirements . isEmpty || app . origin != . manual || local . copyright ? . isEmpty == false
532+ }
533+
490534 private func infoRow ( _ title : String , value : String ) -> some View {
491535 HStack ( alignment : . firstTextBaseline , spacing : 16 ) {
492536 Text ( title ) . foregroundStyle ( . secondary ) . frame ( width : 108 , alignment : . leading )
0 commit comments