Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Update information in detailed status window in a background thread
Browse files Browse the repository at this point in the history
This will make the status window appear and not block the main thread
but information in it will be populated after the response is received
from the daemon after a short delay

This however doesn't make the window dynamically update information
once it appears, just pushes the initial communication with the daemon to a
background thread
  • Loading branch information
anjannath committed Jun 1, 2020
1 parent 63cd1bd commit b959f7f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions CodeReady Containers/DetailedStatusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ class DetailedStatusViewController: NSViewController {
}

func updateViewWithClusterStatus() {
let r = SendCommandToDaemon(command: Request(command: "status", args: nil))
guard let data = r else { return }
do {
let status = try JSONDecoder().decode(ClusterStatus.self, from: data)
if status.Success {
self.vmStatus.stringValue = status.CrcStatus
self.ocpStatus.stringValue = status.OpenshiftStatus
self.diskUsage.stringValue = "\(Units(bytes: status.DiskUse).getReadableUnit()) of \(Units(bytes: status.DiskSize).getReadableUnit()) (Inside the VM)"
self.cacheSize.stringValue = Units(bytes: folderSize(folderPath: cacheDirPath)).getReadableUnit()
self.cacheDirectory.stringValue = cacheDirPath.path
DispatchQueue.global(qos: .background).async {
let r = SendCommandToDaemon(command: Request(command: "status", args: nil))

DispatchQueue.main.async {
guard let data = r else { return }
do {
let status = try JSONDecoder().decode(ClusterStatus.self, from: data)
if status.Success {
self.vmStatus.stringValue = status.CrcStatus
self.ocpStatus.stringValue = status.OpenshiftStatus
self.diskUsage.stringValue = "\(Units(bytes: status.DiskUse).getReadableUnit()) of \(Units(bytes: status.DiskSize).getReadableUnit()) (Inside the VM)"
self.cacheSize.stringValue = Units(bytes: folderSize(folderPath: self.cacheDirPath)).getReadableUnit()
self.cacheDirectory.stringValue = self.cacheDirPath.path
}
} catch let jsonErr {
print(jsonErr.localizedDescription)
}
}
} catch let jsonErr {
print(jsonErr.localizedDescription)
}
}
}
Expand Down

0 comments on commit b959f7f

Please sign in to comment.