mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
Added "autoResize" property (same functionality as dock)
This commit is contained in:
parent
cb085b7216
commit
59867febfb
@ -227,7 +227,7 @@ enum ItemType: Decodable {
|
||||
case network(flip: Bool)
|
||||
case darkMode
|
||||
case swipe(direction: String, fingers: Int, minOffset: Float, sourceApple: SourceProtocol?, sourceBash: SourceProtocol?)
|
||||
case upnext(from: Double, to: Double, maxToShow: Int)
|
||||
case upnext(from: Double, to: Double, maxToShow: Int, autoResize: Bool)
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case type
|
||||
@ -386,7 +386,8 @@ enum ItemType: Decodable {
|
||||
let from = try container.decodeIfPresent(Double.self, forKey: .from) ?? 0 // Lower bounds of period of time in hours to search for events
|
||||
let to = try container.decodeIfPresent(Double.self, forKey: .to) ?? 12 // Upper bounds of period of time in hours to search for events
|
||||
let maxToShow = try container.decodeIfPresent(Int.self, forKey: .maxToShow) ?? 3 // 1 indexed array. Get the 1st, 2nd, 3rd event to display multiple notifications
|
||||
self = .upnext(from: from, to: to, maxToShow: maxToShow)
|
||||
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
||||
self = .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ extension ItemType {
|
||||
return DarkModeBarItem.identifier
|
||||
case .swipe(direction: _, fingers: _, minOffset: _, sourceApple: _, sourceBash: _):
|
||||
return "com.toxblh.mtmr.swipe."
|
||||
case .upnext:
|
||||
case .upnext(from: _, to: _, maxToShow: _, autoResize: _):
|
||||
return "com.connorgmeehan.mtmrup.next."
|
||||
}
|
||||
}
|
||||
@ -303,8 +303,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
barItem = DarkModeBarItem(identifier: identifier)
|
||||
case let .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash):
|
||||
barItem = SwipeItem(identifier: identifier, direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
||||
case let .upnext(from: from, to: to, maxToShow: maxToShow):
|
||||
barItem = UpNextScrubberTouchBarItem(identifier: identifier, interval: 2, from: from, to: to, maxToShow: maxToShow)
|
||||
case let .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize):
|
||||
barItem = UpNextScrubberTouchBarItem(identifier: identifier, interval: 2, from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||
}
|
||||
|
||||
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||
|
||||
@ -22,6 +22,7 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
private var pastSearchCutoff: Double
|
||||
private var maxToShow: Int
|
||||
private var widthConstraint: NSLayoutConstraint?
|
||||
private var autoResize: Bool = false
|
||||
|
||||
/// <#Description#>
|
||||
/// - Parameters:
|
||||
@ -30,12 +31,13 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
/// - from: Relative to current time, how far back we search for events in hours
|
||||
/// - to: Relative to current time, how far forward we search for events in hours
|
||||
/// - maxToShow: Which event to show (1 is first, 2 is second, and so on)
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: Double, to: Double, maxToShow: Int) {
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: Double, to: Double, maxToShow: Int, autoResize: Bool) {
|
||||
// Initialise member properties
|
||||
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updateCheck")
|
||||
pastSearchCutoff = from * 3600
|
||||
futureSearchCutoff = to * 3600
|
||||
self.maxToShow = maxToShow
|
||||
self.autoResize = autoResize
|
||||
UpNextItem.df.dateFormat = "HH:mm"
|
||||
// Error handling
|
||||
if (maxToShow <= 0) {
|
||||
@ -88,6 +90,7 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
index += 1
|
||||
}
|
||||
self.reloadData()
|
||||
self.updateSize()
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,6 +104,17 @@ class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
stackView.scroll(visibleRect.origin)
|
||||
}
|
||||
|
||||
func updateSize() {
|
||||
if self.autoResize {
|
||||
self.widthConstraint?.isActive = false
|
||||
|
||||
let width = self.scrollView.documentView?.fittingSize.width ?? 0
|
||||
self.widthConstraint = self.scrollView.widthAnchor.constraint(equalToConstant: width)
|
||||
self.widthConstraint!.isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func getUpcomingEvents() -> [UpNextEventModel] {
|
||||
var upcomingEvents: [UpNextEventModel] = []
|
||||
|
||||
|
||||
@ -352,9 +352,10 @@ Displays upcoming events from MacOS Calendar. Does not display current event
|
||||
```js
|
||||
{
|
||||
"type": "upnext",
|
||||
"from": 0, // Lower bound of search range for next event in hours. Default 0 (current time, can be negative to view events in the past)
|
||||
"to": 12, // Upper bounds of search range for next event in hours. Default 12 (12 hours in the future)
|
||||
"maxToShow": 3 // Limits the maximum number of events displayed. Default 3 (the first 3 upcoming events)
|
||||
"from": 0, // Lower bound of search range for next event in hours. Default 0 (current time)(can be negative to view events in the past)
|
||||
"to": 12, // Upper bounds of search range for next event in hours. Default 12 (12 hours in the future)
|
||||
"maxToShow": 3 // Limits the maximum number of events displayed. Default 3 (the first 3 upcoming events)
|
||||
"autoResize": false // If true, widget will expand to display all events. Default false (scrollable view within "width")
|
||||
},
|
||||
```
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user