- fix GPU popup initialization (GPU not showing in the popup) (#185)

This commit is contained in:
Serhiy Mytrovtsiy
2020-11-26 15:35:30 +01:00
parent 75151e40f7
commit 91c32d8ad2
4 changed files with 53 additions and 53 deletions

View File

@@ -132,7 +132,10 @@ public class Disk: Module {
if value == nil {
return
}
self.popupView.usageCallback(value!)
DispatchQueue.main.async(execute: {
self.popupView.usageCallback(value!)
})
self.settingsView.setList(value!)
var d = value!.getDiskByName(self.selectedDisk)

View File

@@ -29,42 +29,36 @@ internal class Popup: NSView, Popup_p {
internal func usageCallback(_ value: DiskList) {
if self.list.count != value.list.count && self.list.count != 0 {
DispatchQueue.main.async(execute: {
self.subviews.forEach{ $0.removeFromSuperview() }
})
self.subviews.forEach{ $0.removeFromSuperview() }
self.list = [:]
}
DispatchQueue.main.async(execute: {
value.list.reversed().forEach { (drive: drive) in
if let disk = self.list[drive.mediaName] {
disk.update(free: drive.free, read: drive.stats?.read, write: drive.stats?.write)
} else {
let disk = DiskView(
NSRect(
x: 0,
y: (self.diskFullHeight + Constants.Popup.margins) * CGFloat(self.list.count),
width: self.frame.width,
height: self.diskFullHeight
),
name: drive.mediaName,
size: drive.size,
free: drive.free,
path: drive.path
)
self.list[drive.mediaName] = disk
self.addSubview(disk)
}
value.list.reversed().forEach { (drive: drive) in
if let disk = self.list[drive.mediaName] {
disk.update(free: drive.free, read: drive.stats?.read, write: drive.stats?.write)
} else {
let disk = DiskView(
NSRect(
x: 0,
y: (self.diskFullHeight + Constants.Popup.margins) * CGFloat(self.list.count),
width: self.frame.width,
height: self.diskFullHeight
),
name: drive.mediaName,
size: drive.size,
free: drive.free,
path: drive.path
)
self.list[drive.mediaName] = disk
self.addSubview(disk)
}
})
}
DispatchQueue.main.async(execute: {
let h: CGFloat = ((self.diskFullHeight + Constants.Popup.margins) * CGFloat(self.list.count)) - Constants.Popup.margins
if self.frame.size.height != h {
self.setFrameSize(NSSize(width: self.frame.width, height: h))
self.sizeCallback?(self.frame.size)
}
})
let h: CGFloat = ((self.diskFullHeight + Constants.Popup.margins) * CGFloat(self.list.count)) - Constants.Popup.margins
if self.frame.size.height != h {
self.setFrameSize(NSSize(width: self.frame.width, height: h))
self.sizeCallback?(self.frame.size)
}
}
}

View File

@@ -91,7 +91,9 @@ public class GPU: Module {
return
}
self.popupView.infoCallback(value!)
DispatchQueue.main.async(execute: {
self.popupView.infoCallback(value!)
})
self.settingsView.setList(value!)
let activeGPU = value!.active()

View File

@@ -29,33 +29,34 @@ internal class Popup: NSView, Popup_p {
internal func infoCallback(_ value: GPUs) {
if self.list.count != value.list.count {
DispatchQueue.main.async(execute: {
self.subviews.forEach{ $0.removeFromSuperview() }
})
self.subviews.forEach{ $0.removeFromSuperview() }
self.list = [:]
}
value.list.forEach { (gpu: GPU_Info) in
if self.list[gpu.model] == nil {
DispatchQueue.main.async(execute: {
self.list[gpu.model] = GPUView(
NSRect(x: 0, y: (self.gpuViewHeight + Constants.Popup.margins) * CGFloat(self.list.count), width: self.frame.width, height: self.gpuViewHeight),
gpu: gpu
)
self.addSubview(self.list[gpu.model]!)
})
value.list.forEach { (graphics: GPU_Info) in
if let gpu = self.list[graphics.model] {
gpu.update(graphics)
} else {
self.list[gpu.model]?.update(gpu)
let gpu = GPUView(
NSRect(
x: 0,
y: (self.gpuViewHeight + Constants.Popup.margins) * CGFloat(self.list.count),
width: self.frame.width,
height: self.gpuViewHeight
),
gpu: graphics
)
self.list[graphics.model] = gpu
self.addSubview(gpu)
}
}
DispatchQueue.main.async(execute: {
let h: CGFloat = ((self.gpuViewHeight + Constants.Popup.margins) * CGFloat(self.list.count)) - Constants.Popup.margins
if self.frame.size.height != h {
self.setFrameSize(NSSize(width: self.frame.width, height: h))
self.sizeCallback?(self.frame.size)
}
})
let h: CGFloat = ((self.gpuViewHeight + Constants.Popup.margins) * CGFloat(self.list.count)) - Constants.Popup.margins
if self.frame.size.height != h {
self.setFrameSize(NSSize(width: self.frame.width, height: h))
self.sizeCallback?(self.frame.size)
}
}
}