mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-13 15:54:10 +09:00
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:
26
Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json
vendored
Normal file
26
Kit/Supporting Files/Assets.xcassets/calendar.imageset/Contents.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
||||
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_1x.png
vendored
Normal file
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_1x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 142 B |
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_2x.png
vendored
Normal file
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 201 B |
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_3x.png
vendored
Normal file
BIN
Kit/Supporting Files/Assets.xcassets/calendar.imageset/baseline_calendar_month_black_24pt_3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 278 B |
@@ -67,6 +67,8 @@ public enum ModuleType: Int {
|
||||
case bluetooth
|
||||
case clock
|
||||
|
||||
case combined
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
case .CPU: return "CPU"
|
||||
@@ -78,6 +80,7 @@ public enum ModuleType: Int {
|
||||
case .battery: return "Battery"
|
||||
case .bluetooth: return "Bluetooth"
|
||||
case .clock: return "Clock"
|
||||
case .combined: return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ open class Module {
|
||||
}
|
||||
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 popup: PopupWindow? = 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.config = module_c(in: Bundle(for: type(of: self)).path(forResource: "config", ofType: "plist")!)
|
||||
|
||||
@@ -145,7 +148,7 @@ open class Module {
|
||||
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 {
|
||||
|
||||
@@ -27,11 +27,12 @@ open class PopupWrapper: NSStackView, Popup_p {
|
||||
}
|
||||
|
||||
public class PopupWindow: NSWindow, NSWindowDelegate {
|
||||
private let viewController: PopupViewController = PopupViewController()
|
||||
private let viewController: PopupViewController
|
||||
internal var locked: Bool = false
|
||||
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)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -199,6 +199,7 @@ public class Disk: Module {
|
||||
|
||||
public init() {
|
||||
super.init(
|
||||
moduleType: .disk,
|
||||
popup: self.popupView,
|
||||
settings: self.settingsView,
|
||||
portal: self.portalView,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user