File tree Expand file tree Collapse file tree 4 files changed +181
-4
lines changed Expand file tree Collapse file tree 4 files changed +181
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ struct MewSettingsView: View {
17
17
case About
18
18
}
19
19
20
+ @StateObject var settingsViewModel : SettingsViewModel = . init( )
21
+
20
22
@StateObject var defaultsManager = MewDefaultsManager . shared
21
23
22
24
@State var selectedPage : SettingsPages = . General
@@ -34,7 +36,9 @@ struct MewSettingsView: View {
34
36
case . General:
35
37
NavigationLink (
36
38
destination: {
37
- GeneraSettingsView ( )
39
+ GeneraSettingsView (
40
+ settingsViewModel: settingsViewModel
41
+ )
38
42
}
39
43
) {
40
44
Label (
@@ -43,10 +47,13 @@ struct MewSettingsView: View {
43
47
)
44
48
}
45
49
. id ( SettingsPages . General)
50
+
46
51
case . About:
47
52
NavigationLink (
48
53
destination: {
49
- AboutAppView ( )
54
+ AboutAppView (
55
+ settingsViewModel: settingsViewModel
56
+ )
50
57
}
51
58
) {
52
59
Label (
@@ -60,7 +67,9 @@ struct MewSettingsView: View {
60
67
}
61
68
} ,
62
69
detail: {
63
- GeneraSettingsView ( )
70
+ GeneraSettingsView (
71
+ settingsViewModel: settingsViewModel
72
+ )
64
73
}
65
74
)
66
75
. task {
Original file line number Diff line number Diff line change 8
8
import SwiftUI
9
9
10
10
struct AboutAppView : View {
11
+
12
+ @Environment ( \. openURL) private var openURL
13
+
14
+ @ObservedObject var settingsViewModel : SettingsViewModel = . init( )
15
+
11
16
var body : some View {
12
- Text ( " About " )
17
+ Form {
18
+ Section (
19
+ content: {
20
+ HStack {
21
+ Text ( " Version " )
22
+
23
+ Spacer ( )
24
+
25
+ Text ( settingsViewModel. currentAppVersion)
26
+ }
27
+ } ,
28
+ header: {
29
+ Text ( " App " )
30
+ }
31
+ )
32
+
33
+ Section (
34
+ content: {
35
+ if let latestRelease = settingsViewModel. latestRelease {
36
+ HStack {
37
+ Text ( " Version " )
38
+
39
+ Spacer ( )
40
+
41
+ Text ( latestRelease. tagName)
42
+ . bold ( )
43
+ }
44
+
45
+ if let publishedAt = latestRelease. publishedAt {
46
+ HStack {
47
+ Text ( " Released At " )
48
+
49
+ Spacer ( )
50
+
51
+ Text (
52
+ publishedAt. formatted (
53
+ format: " dd MMM yyyy, hh:mm a "
54
+ )
55
+ )
56
+ . bold ( )
57
+ }
58
+ }
59
+
60
+ HStack {
61
+ Text ( " Download " )
62
+
63
+ Spacer ( )
64
+
65
+ ForEach (
66
+ latestRelease. assets,
67
+ id: \. name
68
+ ) { asset in
69
+ if let url = URL (
70
+ string: asset. browserDownloadUrl
71
+ ) {
72
+ Button (
73
+ asset. name,
74
+ action: {
75
+ openURL ( url)
76
+ }
77
+ )
78
+ }
79
+ }
80
+ }
81
+
82
+ if let url = URL (
83
+ string: " https://github.com/monuk7735/mew-notch "
84
+ ) {
85
+ HStack {
86
+ Text ( " Source Code " )
87
+
88
+ Spacer ( )
89
+
90
+ Button (
91
+ " View on Github " ,
92
+ action: {
93
+ openURL ( url)
94
+ }
95
+ )
96
+ }
97
+ }
98
+ } else if settingsViewModel. didFailToLoadLatestRelease {
99
+ Text ( " Failed to Load " )
100
+ . multilineTextAlignment ( . center)
101
+ . frame ( maxWidth: . infinity)
102
+ . foregroundStyle ( . red)
103
+ }
104
+ } ,
105
+ header: {
106
+ HStack {
107
+ Text ( " Latest Release " )
108
+
109
+ Spacer ( )
110
+
111
+ if settingsViewModel. isLoadingLatestRelease {
112
+ Text ( " 000 " )
113
+ . opacity ( 0 )
114
+ . overlay {
115
+ ProgressView ( )
116
+ . scaleEffect ( 0.5 )
117
+ . frame (
118
+ maxWidth: . infinity,
119
+ alignment: . leading
120
+ )
121
+ }
122
+ }
123
+
124
+ Button (
125
+ " Check for Updates " ,
126
+ action: settingsViewModel. refreshLatestRelease
127
+ )
128
+ . disabled ( settingsViewModel. isLoadingLatestRelease)
129
+ }
130
+ }
131
+ )
132
+ }
133
+ . formStyle (
134
+ . grouped
135
+ )
136
+ . navigationTitle ( " About " )
137
+ . toolbarTitleDisplayMode ( . inline)
13
138
}
14
139
}
15
140
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ struct GeneraSettingsView: View {
11
11
12
12
@StateObject var defaultsManager = MewDefaultsManager . shared
13
13
14
+ @ObservedObject var settingsViewModel : SettingsViewModel = . init( )
15
+
14
16
var body : some View {
15
17
Form {
16
18
Section (
Original file line number Diff line number Diff line change
1
+ //
2
+ // SettingsViewModel.swift
3
+ // MewNotch
4
+ //
5
+ // Created by Monu Kumar on 05/03/2025.
6
+ //
7
+
8
+ import SwiftUI
9
+
10
+ class SettingsViewModel : ObservableObject {
11
+
12
+ @Published var isLoadingLatestRelease : Bool = false
13
+
14
+ @Published var didFailToLoadLatestRelease : Bool = false
15
+
16
+ @Published var currentAppVersion : String
17
+ @Published var latestRelease : MewReleaseAPIResponseModel ?
18
+
19
+ init ( ) {
20
+ self . currentAppVersion = Bundle . main. infoDictionary ? [
21
+ " CFBundleShortVersionString "
22
+ ] as? String ?? " "
23
+
24
+ self . refreshLatestRelease ( )
25
+ }
26
+
27
+ func refreshLatestRelease( ) {
28
+ withAnimation {
29
+ isLoadingLatestRelease = true
30
+ }
31
+
32
+ MewAPI . shared. getLatestRelease { latestRelease in
33
+ withAnimation {
34
+ self . didFailToLoadLatestRelease = latestRelease == nil
35
+
36
+ self . latestRelease = latestRelease
37
+ self . isLoadingLatestRelease = false
38
+ }
39
+ }
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments