mirror of
https://github.com/cranci1/Sora.git
synced 2026-01-11 20:10:24 +00:00
fixed crash???? please yes
This commit is contained in:
parent
ce7913c578
commit
d9752a8002
1 changed files with 19 additions and 4 deletions
|
|
@ -14,6 +14,15 @@ class ModuleManager: ObservableObject {
|
|||
private let modulesFileName = "modules.json"
|
||||
|
||||
init() {
|
||||
let url = getModulesFilePath()
|
||||
if (!FileManager.default.fileExists(atPath: url.path)) {
|
||||
do {
|
||||
try "[]".write(to: url, atomically: true, encoding: .utf8)
|
||||
Logger.shared.log("Created empty modules file", type: "Info")
|
||||
} catch {
|
||||
Logger.shared.log("Failed to create modules file: \(error.localizedDescription)", type: "Error")
|
||||
}
|
||||
}
|
||||
loadModules()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleModulesSyncCompleted), name: .modulesSyncDidComplete, object: nil)
|
||||
}
|
||||
|
|
@ -42,11 +51,17 @@ class ModuleManager: ObservableObject {
|
|||
|
||||
func loadModules() {
|
||||
let url = getModulesFilePath()
|
||||
guard let data = try? Data(contentsOf: url) else { return }
|
||||
modules = (try? JSONDecoder().decode([ScrapingModule].self, from: data)) ?? []
|
||||
|
||||
Task {
|
||||
await checkJSModuleFiles()
|
||||
do {
|
||||
let data = try Data(contentsOf: url)
|
||||
modules = (try? JSONDecoder().decode([ScrapingModule].self, from: data)) ?? []
|
||||
|
||||
Task {
|
||||
await checkJSModuleFiles()
|
||||
}
|
||||
} catch {
|
||||
Logger.shared.log("Failed to load modules: \(error.localizedDescription)", type: "Error")
|
||||
modules = []
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue