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)

This commit is contained in:
Serhiy Mytrovtsiy
2024-12-13 12:49:30 +01:00
parent 6d1baa5926
commit 1093b27fb2
17 changed files with 72 additions and 17 deletions

View File

@@ -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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

View File

@@ -67,6 +67,8 @@ public enum ModuleType: Int {
case bluetooth case bluetooth
case clock case clock
case combined
public var rawValue: String { public var rawValue: String {
switch self { switch self {
case .CPU: return "CPU" case .CPU: return "CPU"
@@ -78,6 +80,7 @@ public enum ModuleType: Int {
case .battery: return "Battery" case .battery: return "Battery"
case .bluetooth: return "Bluetooth" case .bluetooth: return "Bluetooth"
case .clock: return "Clock" case .clock: return "Clock"
case .combined: return ""
} }
} }
} }

View File

@@ -82,6 +82,8 @@ open class Module {
} }
public var userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets") public var userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
private var moduleType: ModuleType
private var settingsView: Settings_v? = nil private var settingsView: Settings_v? = nil
private var popup: PopupWindow? = nil private var popup: PopupWindow? = nil
private var popupView: Popup_p? = nil private var popupView: Popup_p? = nil
@@ -99,7 +101,8 @@ open class Module {
} }
} }
public init(popup: Popup_p? = nil, settings: Settings_v? = nil, portal: Portal_p? = nil, notifications: NotificationsWrapper? = nil) { public init(moduleType: ModuleType, popup: Popup_p? = nil, settings: Settings_v? = nil, portal: Portal_p? = nil, notifications: NotificationsWrapper? = nil) {
self.moduleType = moduleType
self.portal = portal self.portal = portal
self.config = module_c(in: Bundle(for: type(of: self)).path(forResource: "config", ofType: "plist")!) self.config = module_c(in: Bundle(for: type(of: self)).path(forResource: "config", ofType: "plist")!)
@@ -145,7 +148,7 @@ open class Module {
notificationsSettings: self.notificationsView notificationsSettings: self.notificationsView
) )
self.popup = PopupWindow(title: self.config.name, view: self.popupView, visibilityCallback: self.visibilityCallback) self.popup = PopupWindow(title: self.config.name, module: self.moduleType, view: self.popupView, visibilityCallback: self.visibilityCallback)
} }
deinit { deinit {

View File

@@ -27,11 +27,12 @@ open class PopupWrapper: NSStackView, Popup_p {
} }
public class PopupWindow: NSWindow, NSWindowDelegate { public class PopupWindow: NSWindow, NSWindowDelegate {
private let viewController: PopupViewController = PopupViewController() private let viewController: PopupViewController
internal var locked: Bool = false internal var locked: Bool = false
internal var openedBy: widget_t? = nil internal var openedBy: widget_t? = nil
public init(title: String, view: Popup_p?, visibilityCallback: @escaping (_ state: Bool) -> 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) self.viewController.setup(title: title, view: view)
super.init( super.init(
@@ -80,13 +81,13 @@ internal class PopupViewController: NSViewController {
fileprivate var visibilityCallback: (_ state: Bool) -> Void = {_ in } fileprivate var visibilityCallback: (_ state: Bool) -> Void = {_ in }
private var popup: PopupView private var popup: PopupView
public init() { public init(module: ModuleType) {
self.popup = PopupView(frame: NSRect( self.popup = PopupView(frame: NSRect(
x: 0, x: 0,
y: 0, y: 0,
width: Constants.Popup.width + (Constants.Popup.margins * 2), width: Constants.Popup.width + (Constants.Popup.margins * 2),
height: Constants.Popup.height+Constants.Popup.headerHeight height: Constants.Popup.height+Constants.Popup.headerHeight
)) ), module: module)
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
} }
@@ -138,13 +139,13 @@ internal class PopupView: NSView {
private var windowHeight: CGFloat? private var windowHeight: CGFloat?
private var containerHeight: CGFloat? private var containerHeight: CGFloat?
override init(frame: NSRect) { init(frame: NSRect, module: ModuleType) {
self.header = HeaderView(frame: NSRect( self.header = HeaderView(frame: NSRect(
x: 0, x: 0,
y: frame.height - Constants.Popup.headerHeight, y: frame.height - Constants.Popup.headerHeight,
width: frame.width, width: frame.width,
height: Constants.Popup.headerHeight height: Constants.Popup.headerHeight
)) ), module: module)
self.body = NSScrollView(frame: NSRect( self.body = NSScrollView(frame: NSRect(
x: Constants.Popup.margins, x: Constants.Popup.margins,
y: Constants.Popup.margins, y: Constants.Popup.margins,
@@ -300,10 +301,12 @@ internal class HeaderView: NSStackView {
private var title: String = "" private var title: String = ""
private var isCloseAction: Bool = false private var isCloseAction: Bool = false
private let app: URL? private let activityMonitor: URL?
private let calendar: URL?
override init(frame: NSRect) { init(frame: NSRect, module: ModuleType) {
self.app = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.ActivityMonitor") 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)) 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.bezelStyle = .regularSquare
activity.translatesAutoresizingMaskIntoConstraints = false activity.translatesAutoresizingMaskIntoConstraints = false
activity.imageScaling = .scaleNone activity.imageScaling = .scaleNone
activity.image = Bundle(for: type(of: self)).image(forResource: "chart")!
activity.contentTintColor = .lightGray activity.contentTintColor = .lightGray
activity.isBordered = false activity.isBordered = false
activity.action = #selector(openActivityMonitor)
activity.target = self 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 activity.focusRingType = .none
self.activityButton = activity self.activityButton = activity
@@ -348,7 +357,7 @@ internal class HeaderView: NSStackView {
settings.image = Bundle(for: type(of: self)).image(forResource: "settings")! settings.image = Bundle(for: type(of: self)).image(forResource: "settings")!
settings.contentTintColor = .lightGray settings.contentTintColor = .lightGray
settings.isBordered = false settings.isBordered = false
settings.action = #selector(openSettings) settings.action = #selector(self.openSettings)
settings.target = self settings.target = self
settings.toolTip = localizedString("Open module settings") settings.toolTip = localizedString("Open module settings")
settings.focusRingType = .none settings.focusRingType = .none
@@ -385,7 +394,12 @@ internal class HeaderView: NSStackView {
} }
@objc func openActivityMonitor() { @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()) NSWorkspace.shared.open([], withApplicationAt: app, configuration: NSWorkspace.OpenConfiguration())
} }

View File

@@ -61,6 +61,7 @@ public class Battery: Module {
self.notificationsView = Notifications(.battery) self.notificationsView = Notifications(.battery)
super.init( super.init(
moduleType: .battery,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -85,6 +85,7 @@ public class Bluetooth: Module {
self.notificationsView = Notifications(.bluetooth) self.notificationsView = Notifications(.bluetooth)
super.init( super.init(
moduleType: .bluetooth,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
notifications: self.notificationsView notifications: self.notificationsView

View File

@@ -90,6 +90,7 @@ public class CPU: Module {
self.notificationsView = Notifications(.CPU) self.notificationsView = Notifications(.CPU)
super.init( super.init(
moduleType: .CPU,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -74,6 +74,7 @@ public class Clock: Module {
self.portalView = Portal(.clock, list: Clock.list) self.portalView = Portal(.clock, list: Clock.list)
super.init( super.init(
moduleType: .clock,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView portal: self.portalView

View File

@@ -199,6 +199,7 @@ public class Disk: Module {
public init() { public init() {
super.init( super.init(
moduleType: .disk,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -87,6 +87,7 @@ public class GPU: Module {
self.notificationsView = Notifications(.GPU) self.notificationsView = Notifications(.GPU)
super.init( super.init(
moduleType: .GPU,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -156,6 +156,7 @@ public class Network: Module {
self.portalView = Portal(.network) self.portalView = Portal(.network)
super.init( super.init(
moduleType: .network,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView portal: self.portalView

View File

@@ -96,6 +96,7 @@ public class RAM: Module {
self.notificationsView = Notifications(.RAM) self.notificationsView = Notifications(.RAM)
super.init( super.init(
moduleType: .RAM,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -33,6 +33,7 @@ public class Sensors: Module {
self.selectedSensor = Store.shared.string(key: "\(ModuleType.sensors.rawValue)_sensor", defaultValue: "Average System Total") self.selectedSensor = Store.shared.string(key: "\(ModuleType.sensors.rawValue)_sensor", defaultValue: "Average System Total")
super.init( super.init(
moduleType: .sensors,
popup: self.popupView, popup: self.popupView,
settings: self.settingsView, settings: self.settingsView,
portal: self.portalView, portal: self.portalView,

View File

@@ -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 { if self.status {
self.enable() self.enable()