Skip to content

Conversation

connorgmeehan
Copy link
Contributor

Hi there, I love how lightweight this touchbar replacement is but I wanted some added functionality. I've developed a up next widget that displays upcoming calendar events. This is my first open source PR so go easy! However, this is also my first time writing swift so please go hard! There weren't any contributing guidelines so I hope what I've provided suffices/is handy.

Touch Bar Shot 2020-07-26 at 9 15 38 pm

Features

  • Display calendar events in touchbar
  • Adjustable width scrolling view, a lot of the code was sourced from the "dock" widget
  • Events that are < 30 mins away show up red
  • Title and time are displayed
  • Tapping opens the calendar app
  • Easily extendable to allow for more event sources (provided they have a swift interface), and tap behaviours

How to use it

from and to are used to define the window of time an event will show up. I.e. this will show events one hour in the past and one hour in the future.

{
    "from": -1,
    "to": 1,
}

"maxToShow": 3 allows you to define the maximum number of events to be shown at one time. In this case 3
"autoResize": false turns the display from a static element to a condensed scrolling view

Here is my addition the the README.md.

upnext

Calender up next plugin
Displays upcoming events from MacOS Calendar. Does not display current event.
Click on button to open calendar

{
  "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)
  "autoResize": false // If true, widget will expand to display all events. Default false (scrollable view within "width")
},

Changes and implementation summary

UpNextScrubberTouchbarItem
    stores update interval,
    stores settings of widget (interval duration, maxToShow, from, to)
    stores a list of 'IUpNextSource' classes that can source events from an application
    stores a list of 'UpNextItems' (actual buttons rendered to view)
    
    init()
        initialises and applies settings
        sets up IUpNextSources (classes that can source events from an application)
        sets up view of NSTouchBarItem
        
    getUpcomingEvents()
        iterates over list of IUpNextSources, calling their getUpcomingEvents() methods
    
    updateView()
        calls self.getUpcomingEvents()
        sorts the events by startDate
        create buttons for each event
        changes background color, binds tap to each button
        creates a new view, adds all the buttons and overrides existing scroll view
        resizes scroll view to new width

UpNextEventModel
    model passed to UpNextItem
    has a title (String), startDate (Date), sourceType (UpNextSourceType, where the event came from)

UpNextItem
    takes an UpNextEventModel and converts it to a button to be displayed
    has the rendering logic for each button element

UpNextSourceType
    is an enum that stores different source types, used by UpNextItem to know how to render itself and what action to take on the tapEvent

IUpNextSource
    interface for event sources
    
UpNextCalendarSource (implements IUpNextSource)
    manages getting Calendar events
    
    init(updateCallback)
        initialises dependencies
        stores the callback and adds an observer to EKEventStoreHasChanged to run the updateCallback
        
    getUpcomingEvents()
        takes a lower and upper bounds (calculated by "from" and "to"
        uses EventKitto get the events in this range
        formats them as UpNextEventModel (with an UpNextSourceType of iCalendar) and returns it

@connorgmeehan
Copy link
Contributor Author

connorgmeehan commented Jul 26, 2020

Just saw the automatically generated pending warnings, ill see if I can address some of these after work tonight

@Toxblh
Copy link
Owner

Toxblh commented Jul 26, 2020

That is fine. Thank you

@Toxblh Toxblh merged commit 87141e3 into Toxblh:master Jul 26, 2020
tomeresk pushed a commit to tomeresk/MTMR that referenced this pull request Jul 16, 2021
* WIP Implementation of up next widget

* Seperated button view and event source logic

* Adjusted default parameters

* Added the ability to view multiple events

* Added ability to click touchbar item and go to calendar

* renamed nthEvent to maxToShow and changed default

* Updated CFBundleVersion

* Renamed UpNext class and fix ups

* Added "autoResize" property (same functionality as dock)

* Added EKEventStore listener to reduce perfomance impact

* Log cleanup

* Made button blue for current/past events

* Added handling of unauthorised access to calendar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants