mirror of
https://github.com/cranci1/Sora.git
synced 2026-05-09 11:30:44 +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"
|
private let modulesFileName = "modules.json"
|
||||||
|
|
||||||
init() {
|
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()
|
loadModules()
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(handleModulesSyncCompleted), name: .modulesSyncDidComplete, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(handleModulesSyncCompleted), name: .modulesSyncDidComplete, object: nil)
|
||||||
}
|
}
|
||||||
|
|
@ -42,11 +51,17 @@ class ModuleManager: ObservableObject {
|
||||||
|
|
||||||
func loadModules() {
|
func loadModules() {
|
||||||
let url = getModulesFilePath()
|
let url = getModulesFilePath()
|
||||||
guard let data = try? Data(contentsOf: url) else { return }
|
|
||||||
modules = (try? JSONDecoder().decode([ScrapingModule].self, from: data)) ?? []
|
|
||||||
|
|
||||||
Task {
|
do {
|
||||||
await checkJSModuleFiles()
|
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