From d6362c5fb35cc42e6fb677f7968191237e0e76cb Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Thu, 19 Aug 2021 19:30:57 +0200 Subject: [PATCH] feat: added option to kill the process in the Top Process (CPU/RAM/Battery) (#569) --- .../close_12pt.imageset/Contents.json | 26 ++++++++++++++++++ .../baseline_cancel_white_12pt_1x.png | Bin 0 -> 150 bytes .../baseline_cancel_white_12pt_2x.png | Bin 0 -> 222 bytes .../baseline_cancel_white_12pt_3x.png | Bin 0 -> 301 bytes Kit/helpers.swift | 25 +++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/Contents.json create mode 100644 Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/baseline_cancel_white_12pt_1x.png create mode 100644 Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/baseline_cancel_white_12pt_2x.png create mode 100644 Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/baseline_cancel_white_12pt_3x.png diff --git a/Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/Contents.json b/Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/Contents.json new file mode 100644 index 00000000..dda0d1d8 --- /dev/null +++ b/Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "baseline_cancel_white_12pt_1x.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "baseline_cancel_white_12pt_2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "baseline_cancel_white_12pt_3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/baseline_cancel_white_12pt_1x.png b/Kit/Supporting Files/Assets.xcassets/close_12pt.imageset/baseline_cancel_white_12pt_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..2e69e83f5bdec42e50b124ba4ef898cb61690571 GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$0wn*`OvwRKv7RoDArhBsFC64;P!Mnlw0gk9 zDmi{v;S3j3^P6`eUUVU3`L_TPX+B1qQ}1fz+<1X0}@T)e2JU ziKsnV#WteW*c4l>V)IuUM~VYdb!034MEr){;~oioTB&r(00000NkvXXu0mjfeb9Xj literal 0 HcmV?d00001 diff --git a/Kit/helpers.swift b/Kit/helpers.swift index b6faf59f..ad494c1b 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -654,15 +654,34 @@ public class ProcessView: NSStackView { let imageBox = NSView(frame: NSRect(x: 0, y: 0, width: 0, height: 0)) imageBox.addSubview(self.imageView) + let closeBox = NSView(frame: NSRect(x: 0, y: 0, width: 0, height: 0)) + let closeBtn = NSButton(frame: NSRect(x: 5, y: 5, width: 12, height: 12)) + closeBtn.bezelStyle = .regularSquare + closeBtn.translatesAutoresizingMaskIntoConstraints = false + closeBtn.imageScaling = .scaleNone + closeBtn.image = Bundle(for: type(of: self)).image(forResource: "close_12pt")! + if #available(OSX 10.14, *) { + closeBtn.contentTintColor = .lightGray + } + closeBtn.isBordered = false + closeBtn.action = #selector(closeApp) + closeBtn.target = self + closeBtn.toolTip = localizedString("Close application") + closeBtn.focusRingType = .none + closeBox.addSubview(closeBtn) + self.addArrangedSubview(imageBox) self.addArrangedSubview(self.labelView) self.addArrangedSubview(self.valueView) + self.addArrangedSubview(closeBox) NSLayoutConstraint.activate([ imageBox.widthAnchor.constraint(equalToConstant: self.bounds.height), imageBox.heightAnchor.constraint(equalToConstant: self.bounds.height), self.labelView.heightAnchor.constraint(equalToConstant: 16), self.valueView.widthAnchor.constraint(equalToConstant: self.valueView.bounds.width), + closeBox.widthAnchor.constraint(equalToConstant: self.bounds.height), + closeBox.heightAnchor.constraint(equalToConstant: self.bounds.height), self.widthAnchor.constraint(equalToConstant: self.bounds.width), self.heightAnchor.constraint(equalToConstant: self.bounds.height) ]) @@ -686,6 +705,12 @@ public class ProcessView: NSStackView { self.pid = nil self.toolTip = "" } + + @objc private func closeApp() { + if let pid = self.pid { + _ = syncShell("kill \(pid)") + } + } } public class CAText: CATextLayer {