SamRothCA / Today-Scripts

A widget for running scripts in the Today View in OS X Yosemite's Notification Center
1.58k stars 183 forks source link

Assertion failed: (view), function NCViewLayoutSubviewWithInsetsAndSize #25

Open jean-io opened 9 years ago

jean-io commented 9 years ago

Since this app does not work on OS X El Capitain (see #24) and nothing seems to be moving on this repo, I decided to take a look myself and I encountered this error (here) when I tried to add a new script:

Assertion failed: (view), function NCViewLayoutSubviewWithInsetsAndSize, file /Library/Caches/com.apple.xbs/Sources/NotificationCenter/NotificationCenter-448/NotificationCenterPlugIn/NotificationCenterPlugIn/NCViewLayout.m, line 32.

It looks like the notifications framework has been updated and so prevent this widget to work properly.

My knowledge of Objective-C is really limited so any suggestion on how to fix this is welcome.

ujell commented 9 years ago

I don’t have much OS X knowledge but with the same reasons I also took a look.

As far as I understood presentViewControllerInWidget:viewController: method is not working as described in the Apple documentations on 10.11. If the viewController parameter is subclass of NCWidgetSearchViewController (which is the case in this project) it basically crashes. If viewController is a NSViewController (or subclass of NSViewController) app doesn’t crash but doesn’t add anything to parent view either. Only NCWidgetSearchViewController objects work properly.

Unfortunately I couldn’t find any similar issues or examples on the web. I'll try to find a workaround but for me it seems more like an API bug.

lowell commented 8 years ago

@ujell you were on the right track - it doesn't crash if EditViewController inherits from NCWidgetListViewController instead of NCWidgetSearchViewController. I still haven't spent any time working with app extensions, so I'm completely unaware of the implications of making that change. It (the widget) is fully functional after making that change - as far as I can tell, so it's enough to hold me over until 2.0 is released. Maybe it'll be enough for others as well. For the moment, at least.

Today-Scripts (292993b) OS X 10.11.2 (15C27e)

SpencerMichaels commented 8 years ago

@lowell, I interpret your fix as changing the following line in EditViewController.h:

@interface EditViewController : NCWidgetSearchViewController

to

@interface EditViewController : NCWidgetListViewController

This lets me edit and add scripts, which work initially. However, seemingly as soon as the script refreshes, the indicator dot turns yellow permanently, and no content appears below the title. This seems to be deeper than a UI bug, since tested by I adding a script that echoes the output of date at execution into a logfile, it only runs twice in short succession, even if I open the notification center again. Interestingly, if I manually click on the script titles, they refresh and appear as normal. The initial run seems to be executed by calling [script run] whereas auto run uses [script runWithLock]; the latter probably runs properly the first time and then hangs on future invocations. My guess is that there's a lock misbehaving somewhere. I know little ObjC but will experiment as best as I can.

Edit, Nov 3, 2:00pm New findings. Found why this bug occurs, but I don't know how to fix it. I've noticed that the following appears in the console near the time after the bug occurs:

11/3/15 1:48:20.580 PM Widget[13016]: <NSXPCConnection: 0x7fca99744260> connection to service named org.samroth.Today-Scripts.Widget.XPC: Warning: Exception caught during decoding of received reply to message 'launchScript:forUUID:handler:', dropping incoming message and calling failure block.

Exception: -[__NSCFConstantString isEqualToAttributedString:]: unrecognized selector sent to instance 0x10ecdd660
11/3/15 1:48:23.830 PM Widget[13016]: Error in CoreDragRemoveTrackingHandler: -1856
11/3/15 1:48:23.830 PM Widget[13016]: Error in CoreDragRemoveReceiveHandler: -1856
11/3/15 1:48:23.835 PM NotificationCenter[12725]: plugin org.samroth.Today-Scripts.Widget invalidated
11/3/15 1:48:23.835 PM Widget[13016]: host connection <NSXPCConnection: 0x7fca9941a750> connection from pid 12725 invalidated

The first error seems to occur at line 203 of TodayScript.m but I'm not yet sure why. The second and third lines persist even after I comment out that conditional, and are mentioned here in the same context, though with no solution — I think they're the error we need to fix, though. Any app with the Today view will have this error, so this is another API bug, grr! We'll have to find a workaround. I've submitted a bug report to Apple meanwhile.