Skip to content

Commit c6bfdf9

Browse files
committed
add: settings: about: release details
1 parent 3223ffa commit c6bfdf9

File tree

4 files changed

+181
-4
lines changed

4 files changed

+181
-4
lines changed

MewNotch/View/Settings/MewSettingsView.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct MewSettingsView: View {
1717
case About
1818
}
1919

20+
@StateObject var settingsViewModel: SettingsViewModel = .init()
21+
2022
@StateObject var defaultsManager = MewDefaultsManager.shared
2123

2224
@State var selectedPage: SettingsPages = .General
@@ -34,7 +36,9 @@ struct MewSettingsView: View {
3436
case .General:
3537
NavigationLink(
3638
destination: {
37-
GeneraSettingsView()
39+
GeneraSettingsView(
40+
settingsViewModel: settingsViewModel
41+
)
3842
}
3943
) {
4044
Label(
@@ -43,10 +47,13 @@ struct MewSettingsView: View {
4347
)
4448
}
4549
.id(SettingsPages.General)
50+
4651
case .About:
4752
NavigationLink(
4853
destination: {
49-
AboutAppView()
54+
AboutAppView(
55+
settingsViewModel: settingsViewModel
56+
)
5057
}
5158
) {
5259
Label(
@@ -60,7 +67,9 @@ struct MewSettingsView: View {
6067
}
6168
},
6269
detail: {
63-
GeneraSettingsView()
70+
GeneraSettingsView(
71+
settingsViewModel: settingsViewModel
72+
)
6473
}
6574
)
6675
.task {

MewNotch/View/Settings/Pages/AboutAppView.swift

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,133 @@
88
import SwiftUI
99

1010
struct AboutAppView: View {
11+
12+
@Environment(\.openURL) private var openURL
13+
14+
@ObservedObject var settingsViewModel: SettingsViewModel = .init()
15+
1116
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)
13138
}
14139
}
15140

MewNotch/View/Settings/Pages/GeneraSettingsView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct GeneraSettingsView: View {
1111

1212
@StateObject var defaultsManager = MewDefaultsManager.shared
1313

14+
@ObservedObject var settingsViewModel: SettingsViewModel = .init()
15+
1416
var body: some View {
1517
Form {
1618
Section(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)