From 91c32d8ad24a5918929724354e421014460e60d6 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Thu, 26 Nov 2020 15:35:30 +0100 Subject: [PATCH] - fix GPU popup initialization (GPU not showing in the popup) (#185) --- Modules/Disk/main.swift | 5 +++- Modules/Disk/popup.swift | 56 ++++++++++++++++++---------------------- Modules/GPU/main.swift | 4 ++- Modules/GPU/popup.swift | 41 +++++++++++++++-------------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/Modules/Disk/main.swift b/Modules/Disk/main.swift index 32f27f40..5e72c7b6 100644 --- a/Modules/Disk/main.swift +++ b/Modules/Disk/main.swift @@ -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) diff --git a/Modules/Disk/popup.swift b/Modules/Disk/popup.swift index c284d37b..88a38738 100644 --- a/Modules/Disk/popup.swift +++ b/Modules/Disk/popup.swift @@ -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) + } } } diff --git a/Modules/GPU/main.swift b/Modules/GPU/main.swift index 3f584d11..03eb4518 100644 --- a/Modules/GPU/main.swift +++ b/Modules/GPU/main.swift @@ -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() diff --git a/Modules/GPU/popup.swift b/Modules/GPU/popup.swift index 513704f2..30a36e9a 100644 --- a/Modules/GPU/popup.swift +++ b/Modules/GPU/popup.swift @@ -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) + } } }