diff --git a/Sora.xcodeproj/project.pbxproj b/Sora.xcodeproj/project.pbxproj index f62aa22..0c2b96a 100644 --- a/Sora.xcodeproj/project.pbxproj +++ b/Sora.xcodeproj/project.pbxproj @@ -39,6 +39,8 @@ 132417D72D13242400B4F2D2 /* CircularProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132417D62D13242400B4F2D2 /* CircularProgressBar.swift */; }; 132417D92D1328B900B4F2D2 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132417D82D1328B900B4F2D2 /* VideoPlayerView.swift */; }; 1352BA712D1ABC30000A9AF9 /* URLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1352BA702D1ABC30000A9AF9 /* URLSession.swift */; }; + 13AEE7BA2D2451F200CA634A /* GitHubAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13AEE7B92D2451F200CA634A /* GitHubAPI.swift */; }; + 13AEE7BC2D24521200CA634A /* SettingsReleasesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13AEE7BB2D24521200CA634A /* SettingsReleasesView.swift */; }; 13B3A4B22D1477F100BCC0D5 /* SettingsStorageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13B3A4B12D1477F100BCC0D5 /* SettingsStorageView.swift */; }; 13C9821F2D2152B1007A0132 /* GitHubRelease.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13C9821E2D2152B1007A0132 /* GitHubRelease.swift */; }; /* End PBXBuildFile section */ @@ -77,6 +79,8 @@ 132417D82D1328B900B4F2D2 /* VideoPlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoPlayerView.swift; sourceTree = ""; }; 1352BA6F2D1AB113000A9AF9 /* Sora.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Sora.entitlements; sourceTree = ""; }; 1352BA702D1ABC30000A9AF9 /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = ""; }; + 13AEE7B92D2451F200CA634A /* GitHubAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubAPI.swift; sourceTree = ""; }; + 13AEE7BB2D24521200CA634A /* SettingsReleasesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsReleasesView.swift; sourceTree = ""; }; 13B3A4B12D1477F100BCC0D5 /* SettingsStorageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsStorageView.swift; sourceTree = ""; }; 13C9821E2D2152B1007A0132 /* GitHubRelease.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubRelease.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -247,6 +251,7 @@ 132417AE2D131A0600B4F2D2 /* SettingsModuleView.swift */, 132417AF2D131A0600B4F2D2 /* SettingsPlayerView.swift */, 13B3A4B12D1477F100BCC0D5 /* SettingsStorageView.swift */, + 13AEE7BB2D24521200CA634A /* SettingsReleasesView.swift */, ); path = SubPages; sourceTree = ""; @@ -283,6 +288,7 @@ isa = PBXGroup; children = ( 13C9821E2D2152B1007A0132 /* GitHubRelease.swift */, + 13AEE7B92D2451F200CA634A /* GitHubAPI.swift */, ); path = GitHub; sourceTree = ""; @@ -377,6 +383,7 @@ 1308CFC12D198466004CD38C /* CustomPlayer.swift in Sources */, 132417A22D1319E800B4F2D2 /* ModulesManager.swift in Sources */, 132417862D13198000B4F2D2 /* ContentView.swift in Sources */, + 13AEE7BA2D2451F200CA634A /* GitHubAPI.swift in Sources */, 132417C22D131A0600B4F2D2 /* LibraryView.swift in Sources */, 132417A32D1319E800B4F2D2 /* NormalPlayer.swift in Sources */, 132417D72D13242400B4F2D2 /* CircularProgressBar.swift in Sources */, @@ -385,6 +392,7 @@ 132417C32D131A0600B4F2D2 /* MediaView.swift in Sources */, 132417A12D1319E800B4F2D2 /* ModuleStruct.swift in Sources */, 132417B92D131A0600B4F2D2 /* SearchResultsView.swift in Sources */, + 13AEE7BC2D24521200CA634A /* SettingsReleasesView.swift in Sources */, 132417842D13198000B4F2D2 /* SoraApp.swift in Sources */, 132417BE2D131A0600B4F2D2 /* SettingsPlayerView.swift in Sources */, 132417C12D131A0600B4F2D2 /* LibraryManager.swift in Sources */, diff --git a/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate b/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate index 92245d2..fa99873 100644 Binary files a/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate and b/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Sora/Utils/GitHub/GitHubAPI.swift b/Sora/Utils/GitHub/GitHubAPI.swift new file mode 100644 index 0000000..990cc5c --- /dev/null +++ b/Sora/Utils/GitHub/GitHubAPI.swift @@ -0,0 +1,38 @@ +// +// GitHubAPI.swift +// Sora +// +// Created by Francesco on 31/12/24. +// + +import Foundation + +struct GitHubReleases: Codable { + let tagName: String + let body: String + let htmlUrl: String + + enum CodingKeys: String, CodingKey { + case tagName = "tag_name" + case body + case htmlUrl = "html_url" + } +} + +class GitHubAPI { + static let shared = GitHubAPI() + + func fetchReleases(completion: @escaping ([GitHubReleases]?) -> Void) { + let url = URL(string: "https://api.github.com/repos/cranci1/Sora/releases")! + + URLSession.custom.dataTask(with: url) { data, response, error in + guard let data = data, error == nil else { + completion(nil) + return + } + + let releases = try? JSONDecoder().decode([GitHubReleases].self, from: data) + completion(releases) + }.resume() + } +} diff --git a/Sora/Views/SettingsViews/SettingView.swift b/Sora/Views/SettingsViews/SettingView.swift index 32de685..c1d8a41 100644 --- a/Sora/Views/SettingsViews/SettingView.swift +++ b/Sora/Views/SettingsViews/SettingView.swift @@ -79,9 +79,10 @@ struct SettingsView: View { Section(header: Text("Info")) { NavigationLink(destination: AboutView()) { - HStack { - Text("About") - } + Text("About") + } + NavigationLink(destination: SettingsReleasesView()) { + Text("Releases") } Button(action: { if let url = URL(string: "https://github.com/cranci1/Sora") { diff --git a/Sora/Views/SettingsViews/SubPages/SettingsReleasesView.swift b/Sora/Views/SettingsViews/SubPages/SettingsReleasesView.swift new file mode 100644 index 0000000..bcc6c79 --- /dev/null +++ b/Sora/Views/SettingsViews/SubPages/SettingsReleasesView.swift @@ -0,0 +1,42 @@ +// +// SettingsReleasesView.swift +// Sora +// +// Created by Francesco on 31/12/24. +// + +import SwiftUI + +struct SettingsReleasesView: View { + @State private var releases: [GitHubReleases] = [] + + var body: some View { + List(releases, id: \.tagName) { release in + VStack(alignment: .leading) { + Text(release.tagName) + .font(.system(size: 17)) + .bold() + Text(release.body) + .font(.system(size: 14)) + } + .contextMenu { + Button(action: { + if let url = URL(string: release.htmlUrl) { + UIApplication.shared.open(url) + } + }) { + Text("View on GitHub") + Image(systemName: "safari") + } + } + } + .navigationTitle("Releases") + .onAppear { + GitHubAPI.shared.fetchReleases { fetchedReleases in + if let fetchedReleases = fetchedReleases { + self.releases = fetchedReleases + } + } + } + } +}