davidlday / RemindersWidget

An Übersicht widget to display your pending Reminders tasks on the desktop.
MIT License
16 stars 2 forks source link

Not working on OS 10.15.2 #12

Closed curdaneta closed 4 years ago

curdaneta commented 4 years ago

Hello

Looks like the last mac OS update 10.15.2 broke the widget. Regards Ciro

curdaneta commented 4 years ago

The error in the console

[Error] reminders-widget-reminders-coffee: Error: Error: near line 5: database is locked { "tasks": [ ], "lists": [] } wrapError — client.js:1:778021 (anonymous function) — client.js:1:778345 (anonymous function) — client.js:1:746820 (anonymous function) — client.js:1:744328 (anonymous function) — client.js:1:542055 (anonymous function) — client.js:1:748275 redraw (client.js:1:762974) (anonymous function) (client.js:1:761515) (anonymous function) (client.js:1:746820) (anonymous function) (client.js:1:744328) (anonymous function) (client.js:1:542055) (anonymous function) (client.js:1:748275)

davidlday commented 4 years ago

Hey - Just now upgrading to 10.15.2. Will look into it this weekend.

davidlday commented 4 years ago

I think I have it sorted out now. Can you try the attached version? The only file changed is pending.sh if you just want to drop it in over the existing one. Basically, I have to test each of the datastores to find the right one. Using the timestamp was brittle anyhow.

reminders.widget.zip

curdaneta commented 4 years ago

Great work @davidlday works like a charm!

curdaneta commented 4 years ago

Hey @davidlday I found a couple of errors in the console, and Übersicht is now using 25% of CPU

[Error] TypeError: undefined is not an object (evaluating 'settings.refreshFrequency') (anonymous function) (reminders-widget-reminders-coffee:19) o (reminders-widget-reminders-coffee:1:278) r (reminders-widget-reminders-coffee:1:441) Global Code (reminders-widget-reminders-coffee:1:469)

[Error] Error: Cannot find module 'reminders-widget-reminders-coffee' o (client.js:1:229) o (public_ip2-widget-index-coffee:1:155) o (BatteryCharge-widget-index-coffee:1:155) o (client.js:1:123) (anonymous function) (client.js:1:297) (anonymous function) (client.js:1:498736)

[Error] TypeError: null is not an object (evaluating 'contentEl.style') redraw (client.js:1:763025) (anonymous function) (client.js:1:761515) (anonymous function) (client.js:1:746820) (anonymous function) (client.js:1:744356) (anonymous function) (client.js:1:542055) (anonymous function) (client.js:1:748275)

davidlday commented 4 years ago

@curdaneta - I'm not seeing this on my machine, but I'll reopen the issue and look into it.

davidlday commented 4 years ago

@curdaneta - Can verify a couple of things for me, please?

  1. Ubersicht is updated to 1.4
  2. You've restarted Ubersicht after installing the new version of RemindersWidget

Thank you!

curdaneta commented 4 years ago

Hi @davidlday yes, it's version 1.4 and I restarted the application. Take a look at the image

Screen Shot 2019-12-14 at 7 09 33 PM
davidlday commented 4 years ago

Hmmm. Can you post the 'reminders.coffee' from the widget directory? I'm suspicious of it based on the first error:

[Error] TypeError: undefined is not an object (evaluating 'settings.refreshFrequency')
(anonymous function) (reminders-widget-reminders-coffee:19)
o (reminders-widget-reminders-coffee:1:278)
r (reminders-widget-reminders-coffee:1:441)
Global Code (reminders-widget-reminders-coffee:1:469)
curdaneta commented 4 years ago

This is the one I'd grab from your last zip, I only changed the CSS variable

#############################
# Widget Settings
settings =
# Widget theme:
# - default (original)
# - sidebar (sidebar)
  theme: 'sidebar_right'
# Number of tasks to show per list, 0 for all
  tasksPerList: 0
# Whether notes get shown. Either true or false
  showNotes: true
# Lists to hide, or leave empty as [] to show all
  listsToNotShow: []
# For American's and such. Either true or false
  monthBeforeDay: false
# Set the refresh frequency (milliseconds).
  refreshFrequency: '60s'
#############################

#############################
# Do not alter below here.
#############################

#############################
# CSS styling for the widget
setStyle: (err, output) ->
  settings.style = output

#############################
# Widget refresh frequency
refreshFrequency: settings.refreshFrequency

#############################
# Widget update behavior
update: (output, domEl) ->
    str = '<ul class="lists">'
    listNameTpl = ''
    reminders = JSON.parse(output)
    listTasks = @tasksByList(output)

    # Set the widget's style
    @run("cat reminders.widget/styles/" + settings.theme + ".css", @setStyle)
    $(domEl).parent().children("style").html(settings.style)

    if !@content
        @content = $(domEl).children('#reminders-wrap').html(str)
    for listName in reminders.lists.sort().reverse() # For each list
            if listName not in settings.listsToNotShow
                n = 0
                if listTasks[listName]? # if tasks exist
                    n = if settings.tasksPerList > 0 and listTasks[listName].length > settings.tasksPerList then settings.tasksPerList else listTasks[listName].length
                if n > 0 # if there are tasks in the list
                    # Add list name to title, and number of tasks shown if not all are being shown
                    if settings.tasksPerList <= 0
                        listNameTpl = '<div class="list-info">' +
                        '<div class="list-name">' + listName + '</div>' +
                        '</div>'
                    else if settings.tasksPerList > 0
                        listNameTpl = '<div class="list-info">' +
                        '<div class="list-name">' + listName + '</div>' +
                        '<div class="tasks-length">' + n + ' of ' + listTasks[listName].length + '</div>' +
                        '</div>'
                    str +=  '<li class="list">' + listNameTpl + '<ul class="tasks">'

                    i = 0
                    for task in listTasks[listName]
                        priority =  switch(task.priority)
                            when "1" then '!!!'
                            when "5" then '!!'
                            when "9" then '!'
                            else ''
                        if i < n
                            task = listTasks[listName][i]
                            notes = if settings.showNotes and task.notes then task.notes else ''
                            str += '<li class="task">' +
                                '<mark class="priority">' + priority + '</mark> ' + task.title
                            if task.dueDate != " "
                                now = new Date()
                                d = new Date(task.dueDate)

                                # - - Formatting - -
                                # Format times and dates
                                hours = d.getHours();
                                minutes = d.getMinutes();

                                if hours >= 12
                                    ampm = 'pm'
                                else
                                    ampm = 'am'

                                hours = hours % 12;
                                if hours == 0 # the hour '0' should be '12'
                                    hours = 12

                                if minutes < 10
                                    minutes = '0'+minutes # Append leading zero

                                timeStr = hours + ':' + minutes + ' ' + ampm;
                                if settings.monthBeforeDay
                                    dateStr = (d.getMonth() + 1) + '/' + d.getDate()
                                else
                                    dateStr = d.getDate() + '/' + (d.getMonth() + 1)
                                # End format times and dates

                                # - - Natural wording - -
                                tomorrow = new Date()
                                tomorrow.setDate(now.getDate() + 1)
                                yesterday = new Date()
                                yesterday.setDate(now.getDate() - 1)

                                # Calculate days between now and task due
                                oneDay = 24*60*60*1000; # hours*minutes*seconds*milliseconds
                                diffDays = Math.ceil(Math.abs((d.getTime() - now.getTime())/(oneDay)))

                                # format wording
                                if d.getDate() == now.getDate() && d.getMonth() == now.getMonth() && d.getFullYear() == now.getFullYear()
                                    dStr = 'today at ' + timeStr
                                else if d.getDate() == tomorrow.getDate() && d.getMonth() == tomorrow.getMonth() && d.getFullYear() == tomorrow.getFullYear()
                                    dStr = 'tomorrow at ' + timeStr
                                else if diffDays <= 7 && (d.getDate() > now.getDate() || d.getMonth() > now.getMonth() || d.getFullYear() > now.getFullYear())
                                    dStr = 'in ' + diffDays.toString() + ' days at ' + timeStr
                                else if d.getDate() == yesterday.getDate() && d.getMonth() == yesterday.getMonth() && d.getFullYear() == yesterday.getFullYear()
                                    dStr = 'yesterday at ' + timeStr
                                else if d.getFullYear() > now.getFullYear()
                                    dStr = dateStr + '/' + (d.getFullYear() - 2000) + ' at ' + timeStr
                                else
                                    dStr = dateStr + ' at ' + timeStr # Formatted date
                                # End formatting

                                divcls = if d < now then 'overdue' else 'due'
                                str += '<div class="' + divcls + '">Due ' + dStr + '</div>'
                            if settings.showNotes and task.notes
                                str += '<div class="notes">' + task.notes + '</div>'
                            str += '</li>'
                            i++
                        else
                            break
                    str += '</ul></li>'
    str += '</ul>'
    @content.html(str)

#############################
# Command
command: 'reminders.widget/pending.sh'

#############################
# Transforms kludgy JSON from pending.sh
# into something more reasonable.
# TODO: Fix the shell script
tasksByList: (output) ->
    reminders = JSON.parse(output)
    listTasks = {}
    for t in reminders.tasks
        listTasks[t.list] = [] if !listTasks[t.list]
        listTasks[t.list].push(t)
    return listTasks

#############################
# Shows errors if they occur
showError: (err) ->
    if @content
        @content.html '<div class="error">' + err + '</div>'

#############################
# Wrapper div
render: (_) -> """
    <div id='reminders-wrap'>
    </div>
"""

#############################
# Launch Reminders on click
afterRender: (domEl)->
  $(domEl).on 'click', => @run "open /Applications/Reminders.app"

#############################
# CSS styling for the widget
# style: null
curdaneta commented 4 years ago

@davidlday looks like it was caused by the refreshFrequency variable

changed '60s to '6000' and the CPU returned to normal levels

davidlday commented 4 years ago

@curdaneta - That's interesting. Seems to not be a problem on mine, but I think I should change the default back to milliseconds anyhow. Thanks for uncovering this! Leaving this open for now to remind me to update it.

davidlday commented 4 years ago

Fixed in v2.1.1