From 1093b27fb2e70a44663118ff937b7590e474687e Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Fri, 13 Dec 2024 12:49:30 +0100 Subject: [PATCH] feat: changed the icon and behavior of the button in the popup header for the calendar module to open the default macOS calendar app (#2227) --- .../calendar.imageset/Contents.json | 26 +++++++++++ .../baseline_calendar_month_black_24pt_1x.png | Bin 0 -> 142 bytes .../baseline_calendar_month_black_24pt_2x.png | Bin 0 -> 201 bytes .../baseline_calendar_month_black_24pt_3x.png | Bin 0 -> 278 bytes Kit/constants.swift | 3 ++ Kit/module/module.swift | 7 ++- Kit/module/popup.swift | 42 ++++++++++++------ Modules/Battery/main.swift | 1 + Modules/Bluetooth/main.swift | 1 + Modules/CPU/main.swift | 1 + Modules/Clock/main.swift | 1 + Modules/Disk/main.swift | 1 + Modules/GPU/main.swift | 1 + Modules/Net/main.swift | 1 + Modules/RAM/main.swift | 1 + Modules/Sensors/main.swift | 1 + Stats/Views/CombinedView.swift | 2 +- 17 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json create mode 100644 Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_1x.png create mode 100644 Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_2x.png create mode 100644 Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_3x.png diff --git a/Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json b/Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json new file mode 100644 index 00000000..1f58adbb --- /dev/null +++ b/Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "baseline_calendar_month_black_24pt_1x.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "baseline_calendar_month_black_24pt_2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "baseline_calendar_month_black_24pt_3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_1x.png b/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..9e55571609684bed4326f5a4e8f74d9662d70f1d GIT binary patch literal 142 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iP)`@f5R22v2@CXp@V6Z4n7H_0 z^FzZ3F7X0;d0*7p7z@-1OY?`EY%a pslZ#6Nv1YRrj^x`W;JH8Ge~~E9G2ptq5`yl!PC{xWt~$(69CnXFNy#F literal 0 HcmV?d00001 diff --git a/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_2x.png b/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0f0ba543eed86dcb6d34b2e2b93d79db66606916 GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0D37#&FArXh)Ubp3IFyLT)P|o-D zi&~Z5bgQe}Kia!@g|1~aeRlB5lBd!VTnvwQD`sciRW8_?(jGi|C1!l}+yE5D7fyj)tvwak# z0`fNrSX94X(|-R}RgM0In|cZkiMyQ)?{%=gKJQzn_EPQ+&}|H!u6{1-oD!M<(~V9U literal 0 HcmV?d00001 diff --git a/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_3x.png b/Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_3x.png new file mode 100644 index 0000000000000000000000000000000000000000..ca4ca2c41be8696271be11f54f87f51d040e5d98 GIT binary patch literal 278 zcmV+x0qOpUP)2Qs*jXv} z5=2nVAP0{I$B*9)wE|Y~aKCWIXjLfP)nX#$jIdGXL_}<*r!-5#iHMlXK+9yHMg}@0 z0|goAlnf-i2+jl%M36G*LJ&c Void) { + public init(title: String, module: ModuleType, view: Popup_p?, visibilityCallback: @escaping (_ state: Bool) -> Void) { + self.viewController = PopupViewController(module: module) self.viewController.setup(title: title, view: view) super.init( @@ -80,13 +81,13 @@ internal class PopupViewController: NSViewController { fileprivate var visibilityCallback: (_ state: Bool) -> Void = {_ in } private var popup: PopupView - public init() { + public init(module: ModuleType) { self.popup = PopupView(frame: NSRect( x: 0, y: 0, width: Constants.Popup.width + (Constants.Popup.margins * 2), height: Constants.Popup.height+Constants.Popup.headerHeight - )) + ), module: module) super.init(nibName: nil, bundle: nil) } @@ -138,13 +139,13 @@ internal class PopupView: NSView { private var windowHeight: CGFloat? private var containerHeight: CGFloat? - override init(frame: NSRect) { + init(frame: NSRect, module: ModuleType) { self.header = HeaderView(frame: NSRect( x: 0, y: frame.height - Constants.Popup.headerHeight, width: frame.width, height: Constants.Popup.headerHeight - )) + ), module: module) self.body = NSScrollView(frame: NSRect( x: Constants.Popup.margins, y: Constants.Popup.margins, @@ -300,10 +301,12 @@ internal class HeaderView: NSStackView { private var title: String = "" private var isCloseAction: Bool = false - private let app: URL? + private let activityMonitor: URL? + private let calendar: URL? - override init(frame: NSRect) { - self.app = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.ActivityMonitor") + init(frame: NSRect, module: ModuleType) { + self.activityMonitor = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.ActivityMonitor") + self.calendar = URL(fileURLWithPath: "/System/Applications/Calendar.app") super.init(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: frame.height)) @@ -317,12 +320,18 @@ internal class HeaderView: NSStackView { activity.bezelStyle = .regularSquare activity.translatesAutoresizingMaskIntoConstraints = false activity.imageScaling = .scaleNone - activity.image = Bundle(for: type(of: self)).image(forResource: "chart")! activity.contentTintColor = .lightGray activity.isBordered = false - activity.action = #selector(openActivityMonitor) activity.target = self - activity.toolTip = localizedString("Open Activity Monitor") + if module == .clock { + activity.action = #selector(self.openCalendar) + activity.image = Bundle(for: type(of: self)).image(forResource: "calendar")! + activity.toolTip = localizedString("Open Calendar") + } else { + activity.action = #selector(self.openActivityMonitor) + activity.image = Bundle(for: type(of: self)).image(forResource: "chart")! + activity.toolTip = localizedString("Open Activity Monitor") + } activity.focusRingType = .none self.activityButton = activity @@ -348,7 +357,7 @@ internal class HeaderView: NSStackView { settings.image = Bundle(for: type(of: self)).image(forResource: "settings")! settings.contentTintColor = .lightGray settings.isBordered = false - settings.action = #selector(openSettings) + settings.action = #selector(self.openSettings) settings.target = self settings.toolTip = localizedString("Open module settings") settings.focusRingType = .none @@ -385,7 +394,12 @@ internal class HeaderView: NSStackView { } @objc func openActivityMonitor() { - guard let app = self.app else { return } + guard let app = self.activityMonitor else { return } + NSWorkspace.shared.open([], withApplicationAt: app, configuration: NSWorkspace.OpenConfiguration()) + } + + @objc func openCalendar() { + guard let app = self.calendar else { return } NSWorkspace.shared.open([], withApplicationAt: app, configuration: NSWorkspace.OpenConfiguration()) } diff --git a/Modules/Battery/main.swift b/Modules/Battery/main.swift index 831eec12..48ceafe0 100644 --- a/Modules/Battery/main.swift +++ b/Modules/Battery/main.swift @@ -61,6 +61,7 @@ public class Battery: Module { self.notificationsView = Notifications(.battery) super.init( + moduleType: .battery, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Modules/Bluetooth/main.swift b/Modules/Bluetooth/main.swift index 446d4b9c..f71a8b52 100644 --- a/Modules/Bluetooth/main.swift +++ b/Modules/Bluetooth/main.swift @@ -85,6 +85,7 @@ public class Bluetooth: Module { self.notificationsView = Notifications(.bluetooth) super.init( + moduleType: .bluetooth, popup: self.popupView, settings: self.settingsView, notifications: self.notificationsView diff --git a/Modules/CPU/main.swift b/Modules/CPU/main.swift index 5417de1c..1c8313ac 100644 --- a/Modules/CPU/main.swift +++ b/Modules/CPU/main.swift @@ -90,6 +90,7 @@ public class CPU: Module { self.notificationsView = Notifications(.CPU) super.init( + moduleType: .CPU, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Modules/Clock/main.swift b/Modules/Clock/main.swift index f51f9591..75530211 100644 --- a/Modules/Clock/main.swift +++ b/Modules/Clock/main.swift @@ -74,6 +74,7 @@ public class Clock: Module { self.portalView = Portal(.clock, list: Clock.list) super.init( + moduleType: .clock, popup: self.popupView, settings: self.settingsView, portal: self.portalView diff --git a/Modules/Disk/main.swift b/Modules/Disk/main.swift index 0a083413..2744a644 100644 --- a/Modules/Disk/main.swift +++ b/Modules/Disk/main.swift @@ -199,6 +199,7 @@ public class Disk: Module { public init() { super.init( + moduleType: .disk, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Modules/GPU/main.swift b/Modules/GPU/main.swift index 1ef5213d..3c57a66e 100644 --- a/Modules/GPU/main.swift +++ b/Modules/GPU/main.swift @@ -87,6 +87,7 @@ public class GPU: Module { self.notificationsView = Notifications(.GPU) super.init( + moduleType: .GPU, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Modules/Net/main.swift b/Modules/Net/main.swift index 45b65476..04267108 100644 --- a/Modules/Net/main.swift +++ b/Modules/Net/main.swift @@ -156,6 +156,7 @@ public class Network: Module { self.portalView = Portal(.network) super.init( + moduleType: .network, popup: self.popupView, settings: self.settingsView, portal: self.portalView diff --git a/Modules/RAM/main.swift b/Modules/RAM/main.swift index f22d6758..e2b96d0d 100644 --- a/Modules/RAM/main.swift +++ b/Modules/RAM/main.swift @@ -96,6 +96,7 @@ public class RAM: Module { self.notificationsView = Notifications(.RAM) super.init( + moduleType: .RAM, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Modules/Sensors/main.swift b/Modules/Sensors/main.swift index a7214235..d81959cb 100644 --- a/Modules/Sensors/main.swift +++ b/Modules/Sensors/main.swift @@ -33,6 +33,7 @@ public class Sensors: Module { self.selectedSensor = Store.shared.string(key: "\(ModuleType.sensors.rawValue)_sensor", defaultValue: "Average System Total") super.init( + moduleType: .sensors, popup: self.popupView, settings: self.settingsView, portal: self.portalView, diff --git a/Stats/Views/CombinedView.swift b/Stats/Views/CombinedView.swift index e8d51c5a..7e2b53d9 100644 --- a/Stats/Views/CombinedView.swift +++ b/Stats/Views/CombinedView.swift @@ -49,7 +49,7 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate { } } - self.popup = PopupWindow(title: "Combined modules", view: Popup()) { _ in } + self.popup = PopupWindow(title: "Combined modules", module: .combined, view: Popup()) { _ in } if self.status { self.enable()