mirror of
https://github.com/ninxsoft/Mist.git
synced 2025-05-23 11:37:07 -04:00
Empty Cache even if Cache is not enabled
This commit is contained in:
parent
524cf3d105
commit
33a866ef0f
1 changed files with 9 additions and 10 deletions
|
@ -10,7 +10,7 @@ import SwiftUI
|
||||||
struct SettingsInstallersCacheView: View {
|
struct SettingsInstallersCacheView: View {
|
||||||
@Binding var cacheDownloads: Bool
|
@Binding var cacheDownloads: Bool
|
||||||
@Binding var cacheDirectory: String
|
@Binding var cacheDirectory: String
|
||||||
@State private var cacheSize: String = ""
|
@State private var cacheSize: UInt64 = 0
|
||||||
@State private var buttonClicked: Bool = false
|
@State private var buttonClicked: Bool = false
|
||||||
@State private var openPanel: NSOpenPanel = NSOpenPanel()
|
@State private var openPanel: NSOpenPanel = NSOpenPanel()
|
||||||
|
|
||||||
|
@ -32,26 +32,26 @@ struct SettingsInstallersCacheView: View {
|
||||||
PathControl(path: $cacheDirectory)
|
PathControl(path: $cacheDirectory)
|
||||||
.disabled(true)
|
.disabled(true)
|
||||||
HStack(alignment: .firstTextBaseline) {
|
HStack(alignment: .firstTextBaseline) {
|
||||||
FooterText("Cache directory currently contains \(cacheSize) of data.")
|
FooterText("Cache directory currently contains \(cacheSize.bytesString()) of data.")
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Empty Cache...") {
|
Button("Empty Cache...") {
|
||||||
buttonClicked.toggle()
|
buttonClicked.toggle()
|
||||||
}
|
}
|
||||||
|
.disabled(cacheSize == 0)
|
||||||
}
|
}
|
||||||
.disabled(!cacheDownloads)
|
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
getCacheSize()
|
retrieveCacheSize()
|
||||||
}
|
}
|
||||||
.onChange(of: cacheDirectory) { _ in
|
.onChange(of: cacheDirectory) { _ in
|
||||||
getCacheSize()
|
retrieveCacheSize()
|
||||||
}
|
}
|
||||||
.alert(isPresented: $buttonClicked) {
|
.alert(isPresented: $buttonClicked) {
|
||||||
Alert(
|
Alert(
|
||||||
title: Text("Empty Cache Directory?"),
|
title: Text("Empty Cache Directory?"),
|
||||||
message: Text("Emptying the cache directory will free up \(cacheSize)."),
|
message: Text("Emptying the cache directory will free up \(cacheSize.bytesString())."),
|
||||||
primaryButton: .cancel(),
|
primaryButton: .cancel(),
|
||||||
secondaryButton: .destructive(Text("Empty")) { emptyCache() ; getCacheSize() }
|
secondaryButton: .destructive(Text("Empty")) { emptyCache() ; retrieveCacheSize() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ struct SettingsInstallersCacheView: View {
|
||||||
cacheDirectory = url.path
|
cacheDirectory = url.path
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getCacheSize() {
|
private func retrieveCacheSize() {
|
||||||
|
|
||||||
let url: URL = URL(fileURLWithPath: cacheDirectory)
|
let url: URL = URL(fileURLWithPath: cacheDirectory)
|
||||||
var isDirectory: ObjCBool = false
|
var isDirectory: ObjCBool = false
|
||||||
|
@ -85,8 +85,7 @@ struct SettingsInstallersCacheView: View {
|
||||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
let size: UInt64 = try FileManager.default.sizeOfDirectory(at: url)
|
cacheSize = try FileManager.default.sizeOfDirectory(at: url)
|
||||||
cacheSize = size.bytesString()
|
|
||||||
} catch {
|
} catch {
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue