better cache cleaning (Library/Caches/), updated dumped configuration, updates some localizations, fixed downloading server-sided alert

This commit is contained in:
eevee
2024-09-29 17:13:40 +03:00
parent 7cc86d3d37
commit 07d505fe80
8 changed files with 58 additions and 56 deletions
@@ -1,12 +1,12 @@
import Foundation
enum LyricsSource : Int, CustomStringConvertible {
enum LyricsSource: Int, CaseIterable, CustomStringConvertible {
case genius
case lrclib
case musixmatch
case petit
var description : String {
var description: String {
switch self {
case .genius: "Genius"
case .lrclib: "LRCLIB"
@@ -1,17 +1,21 @@
import Foundation
class OfflineHelper {
static private let applicationSupportPath = FileManager.default.urls(
static private let applicationSupportDirectory = FileManager.default.urls(
for: .applicationSupportDirectory, in: .userDomainMask
)
.first!
static private let cachesDirectory = FileManager.default.urls(
for: .cachesDirectory, in: .userDomainMask
).first!
//
static private let persistentCachePath = applicationSupportPath
static private let persistentCachePath = applicationSupportDirectory
.appendingPathComponent("PersistentCache")
static private let remoteConfigPath = applicationSupportPath
static private let remoteConfigPath = applicationSupportDirectory
.appendingPathComponent("remote-config")
//
@@ -24,10 +28,18 @@ class OfflineHelper {
try FileManager.default.removeItem(at: self.remoteConfigPath)
}
static private func resetCaches() throws {
try FileManager.default.removeItem(at: self.cachesDirectory)
}
//
static func resetData() {
static func resetData(clearCaches: Bool = false) {
try? resetPersistentCache()
try? resetRemoteConfig()
if clearCaches {
try? resetCaches()
}
}
}
@@ -24,35 +24,18 @@ private func showOfflineModePopUp() {
)
}
class FTPDownloadActionHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
static let targetName = "ListUXPlatform_FreeTierPlaylistImpl.FTPDownloadAction"
func execute(_ idk: Any) {
showOfflineModePopUp()
}
}
class UIButtonHook: ClassHook<UIButton> {
class ContentOffliningUIHelperImplementationHook: ClassHook<NSObject> {
typealias Group = PremiumPatching
static let targetName = "Offline_ContentOffliningUIImpl.ContentOffliningUIHelperImplementation"
func setHighlighted(_ highlighted: Bool) {
if highlighted {
if let identifier = target.accessibilityIdentifier, identifier.contains("DownloadButton"),
let viewController = WindowHelper.shared.viewController(for: target) {
if !(NSStringFromClass(type(of: viewController)) ~= "Podcast|CreativeWorkPlatform") {
target.removeTarget(nil, action: nil, for: .allEvents)
showOfflineModePopUp()
return
}
}
}
orig.setHighlighted(highlighted)
func downloadToggledWithCurrentAvailability(
_ availability: Int,
addAction: NSObject,
removeAction: NSObject,
pageIdentifier: String,
pageURI: URL
) -> String {
showOfflineModePopUp()
return pageIdentifier
}
}
@@ -5,7 +5,9 @@ struct EeveeSettingsView: View {
let navigationController: UINavigationController
@State var latestVersion = ""
@State var hasShownCommonIssuesTip = UserDefaults.hasShownCommonIssuesTip
@State private var hasShownCommonIssuesTip = UserDefaults.hasShownCommonIssuesTip
@State private var isClearingData = false
private func pushSettingsController(with view: any View, title: String) {
let viewController = EeveeSettingsViewController(
@@ -74,16 +76,29 @@ struct EeveeSettingsView: View {
Section(footer: Text("reset_data_description".localized)) {
Button {
OfflineHelper.resetData()
exitApplication()
isClearingData = true
DispatchQueue.global(qos: .userInitiated).async {
OfflineHelper.resetData(clearCaches: true)
DispatchQueue.main.async {
exitApplication()
}
}
} label: {
Text("reset_data".localized)
if isClearingData {
ProgressView()
}
else {
Text("reset_data".localized)
}
}
}
}
.listStyle(GroupedListStyle())
.animation(.default, value: isClearingData)
.animation(.default, value: latestVersion)
.animation(.default, value: hasShownCommonIssuesTip)
@@ -1,14 +1,11 @@
import SwiftUI
extension EeveeLyricsSettingsView {
func lyricsSourceFooter() -> some View {
var text = "lyrics_source_description".localized
if Locale.isInRegion("JP", orHasLanguage: "ja") {
text.append("\n\n")
text.append("petitlyrics_description".localized)
}
text.append("\n\n")
text.append("petitlyrics_description".localized)
text.append("\n\n")
text.append("lyrics_additional_info".localized)
@@ -22,18 +19,13 @@ extension EeveeLyricsSettingsView {
"lyrics_source".localized,
selection: $lyricsSource
) {
Text("Genius").tag(LyricsSource.genius)
Text("LRCLIB").tag(LyricsSource.lrclib)
Text("Musixmatch").tag(LyricsSource.musixmatch)
if Locale.isInRegion("JP", orHasLanguage: "ja") {
Text("PetitLyrics").tag(LyricsSource.petit)
ForEach(LyricsSource.allCases, id: \.self) { lyricsSource in
Text(lyricsSource.description).tag(lyricsSource)
}
}
if lyricsSource == .musixmatch {
VStack(alignment: .leading, spacing: 5) {
Text("musixmatch_user_token".localized)
TextField("user_token_placeholder".localized, text: $musixmatchToken)