tag:support.markedapp.com,2011-09-11:/discussions/problems/161844-streaming-preview-beachballs-when-url-is-suppliedMarked: Discussion 2021-02-23T18:43:10Ztag:support.markedapp.com,2011-09-11:Comment/490374402021-02-16T04:26:40Z2021-02-16T04:26:42Zstreaming preview beachballs when URL is supplied<div><p>I turned on debug logging in Marked, opened up Activity Monitor, and gathered debug information while reproducing this issue:</p>
<ul>
<li>Generate preview at 22:57:00</li>
<li>Request spindump at 22:57:03</li>
<li>Marked un-freezes and writes logs at 22:57:57</li>
</ul>
<p>I've attached both the spindump and the logs that Marked wrote out.</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-16T13:28:15Z2021-02-16T13:28:15Zstreaming preview beachballs when URL is supplied<div><p>How are you sending the base URL? It's expecting an NSURL in the URL<br>
pasteboard, not a plain text one. Based on the Marked logs it appears to<br>
be processing it fine, just wondering if it's getting gummed up in the<br>
conversion at all.</p>
<p>It might help me debug if you could provide me with a working example I<br>
could run a trace on. I'm not a Python expert, so I need something I can<br>
just run from the command line, even if it has hardcoded text and URL.<br>
(I'm also a Sublime user, if sharing a package is easier.)</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-16T13:28:42Z2021-02-16T13:28:42Zstreaming preview beachballs when URL is supplied<div><p>Also I'm excited that you're working on this, I would love a streaming<br>
package for Sublime!</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-16T20:39:16Z2021-02-16T20:40:02Zstreaming preview beachballs when URL is supplied<div><p>I'm sending the URL as an NSURL.</p>
<p>Am working through my employer's <a href="https://opensource.google/docs/releasing/">Open Source Releasing</a> process now to see if I can share the package. Will reply back when I hear back from them.</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-17T12:27:00Z2021-02-17T12:27:00Zstreaming preview beachballs when URL is supplied<div><p>Here's the code I'm using for testing. I only know of one other developer that has for sure integrated the base url feature, so it's entirely possible there's an edge case I'm failing to compensate for. Seeing your code might help me find it. But this works (tested with the non-MAS version):</p>
<pre>
<code>#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <AppKit/AppKit.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *rawString = @"marked style: FadingFast\n\n![Connections button](images/connections-x.png)\n\n";
NSURL *baseURL = [NSURL fileURLWithPath:@"/Users/ttscoff/Desktop/Code/nvultra-docs/content/"];
// pasteboard *must* be named 'mkStreamingPreview'
NSPasteboard* pb = [NSPasteboard pasteboardWithName:@"mkStreamingPreview"];
[pb clearContents];
[pb writeObjects:@[rawString, baseURL]];
[[NSWorkspace sharedWorkspace]
openURL:[NSURL URLWithString:@"x-marked://stream?x-success=com.krill.CodeRunner-setapp"]];
}
}</code>
</pre></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-18T20:38:52Z2021-02-18T20:38:52Zstreaming preview beachballs when URL is supplied<div><p>Thanks, Brett!</p>
<p>Code is live now: <a href="https://github.com/willangley/PreviewInMarked">https://github.com/willangley/PreviewInMarked</a></p>
<p>My code looks like a near equivalent of it, but I'm not exactly sure. FWIW, I've been testing with Marked open already and haven't tried adding an <code>openURL</code> call.</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-20T01:35:16Z2021-02-20T01:35:16Zstreaming preview beachballs when URL is supplied<div><p>I'm impressed by the subtlety of this. I don't have CodeRunner, but I copied the code in <a href="#comment_49040398">#5</a> into a new Command Line Tool in Xcode and confirmed it opened Marked and then crashed Marked immediately.</p>
<p>This wasn't what I was hoping for, but it wasn't a beachball, and then I realized I needed to revised the code a bit:</p>
<ol>
<li>pointed <code>baseURL</code> at a file on my system<br></li>
<li>realized that <code>openURL</code> might rely on the destination app running at the time, and commented it out</li>
</ol>
<p>When I ran it again, it opened Marked and Marked became responsive immediately...</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-20T01:45:14Z2021-02-20T01:45:14Zstreaming preview beachballs when URL is supplied<div><p>I clearly need a guard statement when reading the url…</p>
<p>Is it possible the sublime plugin is sending an invalid url? I haven't had a chance to actually test it out yet.</p>
<ul>
<li>Brett</li>
</ul></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-20T18:08:12Z2021-02-20T18:13:45Zstreaming preview beachballs when URL is supplied<div><p>That's a good question – trying to answer it was revealing.</p>
<p>I changed the plugin to write to <code>[NSPasteboard generalPasteboard]</code> and looked at the pasteboard contents in <a href="https://github.com/sindresorhus/Pasteboard-Viewer">Pasteboard Viewer</a> . When I did, I was able to access the text instantly; clicking on the file URL caused Pasteboard Viewer to hang for a while before displaying the URL.</p>
<p>Pasteboard Viewer did <em>not</em> hang when I made a similar change to the code used for testing.</p>
<p>Pasteboard Viewer doesn't just display file URLs; it will try to show a QuickLook preview of their contents. I'm using the Mac App Store version of this for now, so it won't actually show them even when I point to an extant path on the filesystem, but I'm guessing that <em>trying</em> to access the file at the URL is enough to result in a hang when it happens.</p>
<p>I'm not sure the root cause of the hang yet, but it's not specific to Marked.</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-21T13:17:38Z2021-02-21T13:17:38Zstreaming preview beachballs when URL is supplied<div><p>Let me know if you do find the cause.</p>
<ul>
<li>Brett</li>
</ul></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-23T06:21:25Z2021-02-23T06:21:25Zstreaming preview beachballs when URL is supplied<div><p>Brett,</p>
<p>I did, and I was able to work around it. I've pushed an early-but-usable version to GitHub. LMK if you give it a try.</p>
<hr>
<p>A client that reads the URL from the pasteboard may ask for <a href="https://nshipster.com/inter-process-communication/#pasteboard">alternative representations</a>, and <code>pboard</code> will try to call back to the process that wrote the URL.</p>
<ul>
<li>If the process has exited, pboard returns immediately</li>
<li>If the process is running and has a main CFRunLoop, it'll answer pboard and pboard will return promptly</li>
<li>If the process is running and does <em>not</em> have a main CFRunLoop, pboard will wait for an answer and then timeout. The reader will hang while pboard is waiting.</li>
</ul>
<p>I don't control the Sublime Text plugin host, so I can't start a CFRunLoop on its main thread. But I can spawn a subprocess and start a CFRunLoop there...</p>
<p>Cheers,<br>
Will</p></div>Will Angleytag:support.markedapp.com,2011-09-11:Comment/490374402021-02-23T12:59:56Z2021-02-23T12:59:56Zstreaming preview beachballs when URL is supplied<div><p>Awesome, will try this out!</p>
<ul>
<li>Brett</li>
</ul></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-23T13:15:31Z2021-02-23T13:15:31Zstreaming preview beachballs when URL is supplied<div><p>By the way, in case it wasn't clear, the openURL in my example code just calls the Marked URL handler for opening the streaming preview and returning focus to the originating app by bundle identifier, in that case CodeRunner. I just left it there as an example of how the plugin could open the streaming preview. You wouldn't want to call it with every update, but it might be nice when first initializing. (You may have already implemented this, I haven 't tested yet!)</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-23T13:21:31Z2021-02-23T13:21:31Zstreaming preview beachballs when URL is supplied<div><p>Ok, stupid question: I should be able to just drag the PreviewInMarked folder into <code>Application Support/Sublime Text 3/Packages</code> and it should show up in the palette right? It's been a long time since I manually installed a package...</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/490374402021-02-23T18:39:05Z2021-02-23T18:43:10Zstreaming preview beachballs when URL is supplied<div><p>Brett,</p>
<p>Thanks for trying this out! To answer your questions,</p>
<ul>
<li>
<p>I have indeed integrated URL opening already! It's not perfect though; sometimes things load without styling or load to a blank page. Refreshing Marked should work around that. <a href="https://github.com/willangley/PreviewInMarked/issues/4">PreviewInMarked#4</a></p>
</li>
<li>
<p>That's not a stupid question, and that is indeed what you need to do. (And, if you've already got a PreviewInMarked folder locally, you should download it again – I fixed a pretty serious threading bug between then and now.)</p>
<p>I'm hoping to get this stable enough to ship to Package Control over the weekend, since manual installs are a lot of work. <a href="https://github.com/willangley/PreviewInMarked/issues/11">PreviewInMarked#11</a></p>
</li>
</ul>
<p>Cheers,<br>
Will</p></div>Will Angley