Refresh core data size on foreground
This commit is contained in:
@@ -10,6 +10,7 @@ import SwiftUI
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public struct CoreView: View {
|
public struct CoreView: View {
|
||||||
|
@Environment(\.scenePhase) private var scenePhase
|
||||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||||
@State private var isLoading = true
|
@State private var isLoading = true
|
||||||
@State private var alert: AlertState?
|
@State private var alert: AlertState?
|
||||||
@@ -92,6 +93,22 @@ public struct CoreView: View {
|
|||||||
}
|
}
|
||||||
.navigationTitle("Core")
|
.navigationTitle("Core")
|
||||||
.alert($alert)
|
.alert($alert)
|
||||||
|
.onAppear {
|
||||||
|
guard !isLoading else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Task {
|
||||||
|
await refreshWorkingDirectorySize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChangeCompat(of: scenePhase) { newValue in
|
||||||
|
guard newValue == .active, !isLoading else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Task {
|
||||||
|
await refreshWorkingDirectorySize()
|
||||||
|
}
|
||||||
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
#endif
|
#endif
|
||||||
@@ -120,10 +137,25 @@ public struct CoreView: View {
|
|||||||
|
|
||||||
private nonisolated func loadSettingsBackground() async {
|
private nonisolated func loadSettingsBackground() async {
|
||||||
let disableDeprecatedWarnings = await SharedPreferences.disableDeprecatedWarnings.get()
|
let disableDeprecatedWarnings = await SharedPreferences.disableDeprecatedWarnings.get()
|
||||||
|
await MainActor.run {
|
||||||
|
self.disableDeprecatedWarnings = disableDeprecatedWarnings
|
||||||
|
}
|
||||||
|
await refreshWorkingDirectorySize()
|
||||||
|
}
|
||||||
|
|
||||||
|
private nonisolated func refreshWorkingDirectorySize() async {
|
||||||
|
guard !Variant.screenshotMode else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#if os(macOS)
|
||||||
|
let helperUnavailable = Variant.useSystemExtension && HelperServiceManager.rootHelperStatus != .enabled
|
||||||
|
#endif
|
||||||
let dataSize: String?
|
let dataSize: String?
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
if Variant.useSystemExtension {
|
if Variant.useSystemExtension {
|
||||||
if let size = try? RootHelperClient.shared.getWorkingDirectorySize() {
|
if helperUnavailable {
|
||||||
|
dataSize = nil
|
||||||
|
} else if let size = try? RootHelperClient.shared.getWorkingDirectorySize() {
|
||||||
dataSize = LibboxFormatBytes(size)
|
dataSize = LibboxFormatBytes(size)
|
||||||
} else {
|
} else {
|
||||||
dataSize = nil
|
dataSize = nil
|
||||||
@@ -135,7 +167,9 @@ public struct CoreView: View {
|
|||||||
dataSize = (try? FilePath.workingDirectory.formattedSize()) ?? "Unknown"
|
dataSize = (try? FilePath.workingDirectory.formattedSize()) ?? "Unknown"
|
||||||
#endif
|
#endif
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
self.disableDeprecatedWarnings = disableDeprecatedWarnings
|
#if os(macOS)
|
||||||
|
self.helperUnavailable = helperUnavailable
|
||||||
|
#endif
|
||||||
self.dataSize = dataSize
|
self.dataSize = dataSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user