mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-13 04:50:41 +00:00
added module refresh.
It does only check the version string
This commit is contained in:
parent
71f5f9fe25
commit
af71cb6a2f
6 changed files with 66 additions and 11 deletions
|
|
@ -7,7 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
131845F92D47C62D00CA7A54 /* SettingsViewUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 131845F82D47C62D00CA7A54 /* SettingsViewUI.swift */; };
|
||||
131845F92D47C62D00CA7A54 /* SettingsViewGeneral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 131845F82D47C62D00CA7A54 /* SettingsViewGeneral.swift */; };
|
||||
133D7C6E2D2BE2500075467E /* SoraApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C6D2D2BE2500075467E /* SoraApp.swift */; };
|
||||
133D7C702D2BE2500075467E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C6F2D2BE2500075467E /* ContentView.swift */; };
|
||||
133D7C722D2BE2520075467E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 133D7C712D2BE2520075467E /* Assets.xcassets */; };
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
131845F82D47C62D00CA7A54 /* SettingsViewUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewUI.swift; sourceTree = "<group>"; };
|
||||
131845F82D47C62D00CA7A54 /* SettingsViewGeneral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewGeneral.swift; sourceTree = "<group>"; };
|
||||
133D7C6A2D2BE2500075467E /* Sora.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sora.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
133D7C6D2D2BE2500075467E /* SoraApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoraApp.swift; sourceTree = "<group>"; };
|
||||
133D7C6F2D2BE2500075467E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -154,7 +154,7 @@
|
|||
1E9FF1D22D403E42008AC100 /* SettingsViewLoggerFilter.swift */,
|
||||
1399FAD32D3AB38C00E97C31 /* SettingsViewLogger.swift */,
|
||||
133D7C842D2BE2630075467E /* SettingsViewModule.swift */,
|
||||
131845F82D47C62D00CA7A54 /* SettingsViewUI.swift */,
|
||||
131845F82D47C62D00CA7A54 /* SettingsViewGeneral.swift */,
|
||||
);
|
||||
path = SettingsSubViews;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -371,7 +371,7 @@
|
|||
133D7C702D2BE2500075467E /* ContentView.swift in Sources */,
|
||||
13EA2BD62D32D97400C1EBD7 /* Double+Extension.swift in Sources */,
|
||||
133D7C8F2D2BE2640075467E /* MediaInfoView.swift in Sources */,
|
||||
131845F92D47C62D00CA7A54 /* SettingsViewUI.swift in Sources */,
|
||||
131845F92D47C62D00CA7A54 /* SettingsViewGeneral.swift in Sources */,
|
||||
133D7C8D2D2BE2640075467E /* HomeView.swift in Sources */,
|
||||
13EA2BDC2D32D9FF00C1EBD7 /* MiruDataStruct.swift in Sources */,
|
||||
13D842552D45267500EBBFA6 /* DropManager.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ struct SoraApp: App {
|
|||
.accentColor(settings.accentColor)
|
||||
.onAppear {
|
||||
settings.updateAppearance()
|
||||
if UserDefaults.standard.bool(forKey: "refreshModulesOnLaunch") {
|
||||
Task {
|
||||
await moduleManager.refreshModules()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onOpenURL { url in
|
||||
handleURL(url)
|
||||
|
|
|
|||
|
|
@ -90,4 +90,43 @@ class ModuleManager: ObservableObject {
|
|||
let localUrl = getDocumentsDirectory().appendingPathComponent(module.localPath)
|
||||
return try String(contentsOf: localUrl, encoding: .utf8)
|
||||
}
|
||||
|
||||
func refreshModules() async {
|
||||
for (index, module) in modules.enumerated() {
|
||||
do {
|
||||
let (metadataData, _) = try await URLSession.custom.data(from: URL(string: module.metadataUrl)!)
|
||||
let newMetadata = try JSONDecoder().decode(ModuleMetadata.self, from: metadataData)
|
||||
|
||||
if newMetadata.version != module.metadata.version {
|
||||
guard let scriptUrl = URL(string: newMetadata.scriptUrl) else {
|
||||
throw NSError(domain: "Invalid script URL", code: -1)
|
||||
}
|
||||
|
||||
let (scriptData, _) = try await URLSession.custom.data(from: scriptUrl)
|
||||
guard let jsContent = String(data: scriptData, encoding: .utf8) else {
|
||||
throw NSError(domain: "Invalid script encoding", code: -1)
|
||||
}
|
||||
|
||||
let localUrl = getDocumentsDirectory().appendingPathComponent(module.localPath)
|
||||
try jsContent.write(to: localUrl, atomically: true, encoding: .utf8)
|
||||
|
||||
modules[index] = ScrapingModule(
|
||||
id: module.id,
|
||||
metadata: newMetadata,
|
||||
localPath: module.localPath,
|
||||
metadataUrl: module.metadataUrl,
|
||||
isActive: module.isActive
|
||||
)
|
||||
|
||||
Logger.shared.log("Updated module: \(module.metadata.sourceName) to version \(newMetadata.version)")
|
||||
}
|
||||
} catch {
|
||||
Logger.shared.log("Failed to refresh module: \(module.metadata.sourceName) - \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.saveModules()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// SettingsViewUI.swift
|
||||
// SettingsViewGeneral.swift
|
||||
// Sora
|
||||
//
|
||||
// Created by Francesco on 27/01/25.
|
||||
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsViewUI: View {
|
||||
struct SettingsViewGeneral: View {
|
||||
@AppStorage("episodeChunkSize") private var episodeChunkSize: Int = 100
|
||||
@AppStorage("refreshModulesOnLaunch") private var refreshModulesOnLaunch: Bool = false
|
||||
@EnvironmentObject var settings: Settings
|
||||
|
||||
var body: some View {
|
||||
|
|
@ -48,7 +49,11 @@ struct SettingsViewUI: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: Text("Modules")) {
|
||||
Toggle("Refresh Modules on Launch", isOn: $refreshModulesOnLaunch)
|
||||
}
|
||||
}
|
||||
.navigationTitle("UI Settings")
|
||||
.navigationTitle("General")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ struct SettingsViewModule: View {
|
|||
|
||||
@State private var errorMessage: String?
|
||||
@State private var isLoading = false
|
||||
@State private var isRefreshing = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
|
|
@ -109,6 +110,11 @@ struct SettingsViewModule: View {
|
|||
.resizable()
|
||||
.padding(5)
|
||||
})
|
||||
.refreshable {
|
||||
isRefreshing = true
|
||||
await moduleManager.refreshModules()
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
.alert(isPresented: .constant(errorMessage != nil)) {
|
||||
Alert(
|
||||
|
|
@ -163,4 +169,4 @@ struct SettingsViewModule: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,8 @@ struct SettingsView: View {
|
|||
NavigationView {
|
||||
Form {
|
||||
Section(header: Text("Main Settings")) {
|
||||
NavigationLink(destination: SettingsViewUI()) {
|
||||
Text("UI Settings")
|
||||
NavigationLink(destination: SettingsViewGeneral()) {
|
||||
Text("General Settings")
|
||||
}
|
||||
NavigationLink(destination: SettingsViewModule()) {
|
||||
Text("Media Player")
|
||||
|
|
|
|||
Loading…
Reference in a new issue