Skip to content

Commit 6b4111b

Browse files
dynamic storage monitoring for custom model directories (#781)
* update storage monitoring to respect custom model directory * reverted .pbxproj --------- Co-authored-by: tpae <terencepae@gmail.com>
1 parent 0affb66 commit 6b4111b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Packages/OsaurusCore/Services/DirectoryPickerService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ final class DirectoryPickerService: ObservableObject {
8686

8787
private init() {
8888
loadSavedDirectory()
89+
SystemMonitorService.shared.updateStoragePath(Self.effectiveModelsDirectory().path)
8990
}
9091

9192
/// Load previously saved directory from security-scoped bookmark
@@ -273,6 +274,7 @@ final class DirectoryPickerService: ObservableObject {
273274
/// Notify the rest of the app that the models directory changed so local models are rescanned.
274275
private func notifyModelsDirectoryChanged() {
275276
ModelManager.invalidateLocalModelsCache()
277+
SystemMonitorService.shared.updateStoragePath(Self.effectiveModelsDirectory().path)
276278
NotificationCenter.default.post(name: .localModelsChanged, object: nil)
277279
}
278280

Packages/OsaurusCore/Services/SystemMonitorService.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SystemMonitorService: ObservableObject {
2525
@Published var availableStorageGB: Double = 0.0
2626
@Published var totalStorageGB: Double = 0.0
2727

28+
private var storagePath: String = NSHomeDirectory()
2829
private var timer: Timer?
2930
private var previousCPUInfo: host_cpu_load_info?
3031

@@ -66,6 +67,12 @@ class SystemMonitorService: ObservableObject {
6667
totalStorageGB = storageInfo.totalGB
6768
}
6869

70+
/// Update the path used for storage monitoring (when user selects a custom models directory)
71+
func updateStoragePath(_ path: String) {
72+
storagePath = path
73+
updateResourceUsage()
74+
}
75+
6976
private func getCPUUsage() -> Double {
7077
var _ = mach_msg_type_number_t()
7178
var cpuInfo: host_cpu_load_info = host_cpu_load_info()
@@ -179,7 +186,7 @@ class SystemMonitorService: ObservableObject {
179186
private func getStorageUsage() -> (availableGB: Double, totalGB: Double) {
180187
let gb = 1024.0 * 1024.0 * 1024.0
181188
do {
182-
let attrs = try FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory())
189+
let attrs = try FileManager.default.attributesOfFileSystem(forPath: storagePath)
183190
let total = (attrs[.systemSize] as? NSNumber)?.doubleValue ?? 0
184191
let free = (attrs[.systemFreeSize] as? NSNumber)?.doubleValue ?? 0
185192
return (free / gb, total / gb)

Packages/OsaurusCore/Views/Model/ModelDownloadView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ private struct SystemStatusBar: View {
707707

708708
ResourceGauge(
709709
label: "Storage",
710-
icon: "internaldrive",
710+
icon: DirectoryPickerService.shared.hasValidDirectory ? "externaldrive" : "internaldrive",
711711
usedFraction: totalStorageGB > 0
712712
? (totalStorageGB - availableStorageGB) / totalStorageGB : 0,
713713
detail: String(

0 commit comments

Comments
 (0)