objective-cfirefox-addoncore-graphicscore-foundationjsctypes

Ported OSX Obj-C/CG Screenshot Code to js-ctypes - crash on final line


I ported some objective-c/CoreGraphics code that takes a screenshot of multiple monitors but it's not working. The jsctypes guys won't be able to help because the section is just me answering questions lol

The objc/cg code is from here: https://stackoverflow.com/a/28247749/1828637

My jsctypes type/struct/declares are here: https://github.com/Noitidart/NativeShot/blob/mac-troubleshooting/modules/ostypes_mac.jsm

The jsctypes port is here: https://github.com/Noitidart/NativeShot/blob/mac-troubleshooting/modules/workers/MainWorker.js#L443-656

And the last line is line 643 which causes the crash:

var rez_writeToFile = ostypes.API('objc_msgSend')(data, ostypes.HELPER.sel('writeTofile:atomically:'), myNSStrings.get(OS.Path.join(OS.Constants.Path.desktopDir, 'full_ss.png')), ostypes.CONST.YES);

This coincides with the objectivec of

[data writeToFile:@"/tmp/screenshot.png" atomically:YES];

except i changed path to ...desktop/...png

I wrote to sepearte gists, to align the lines in text diff software to make sure I did everything.

I dont think i missed anything i dont know why it crashes on that final line

Do any of the ObjC/CG people see any type definition that is wrong or something that I missed (for example the ObjC code uses compound statments I'm not sure I understood/translated them correctly in the port).


Solution

  • Wowww so after struggling for like some hours then posting this I realize it right away haha

    Casing typo in selector!! I had writeTofile:atomically instead of writeToFile:atomically!

    If anyone would like to test this out, it's a simple firefox addon test case.

    1. Install an addon that allows installing addons from github repos from here: https://addons.mozilla.org/en-US/firefox/addon/github-extension-installer/
    2. Go to commit on this branch that works here: https://github.com/Noitidart/NativeShot/tree/f5f2e8606d3c5c657e901239d3ceb8c8c79a4494
    3. Then click the "Add to Firefox" button at bottom right, below the "Download Zip" button
    4. Click on the toolbar button icon that gets added to firefox, as seen in this screenshot: https://i.sstatic.net/gOKHC.png
    5. Check desktop you now have a single png file with a screenshot of all the monitors, huge props to @KenThomas!