GJS, in medias res

Please post suggestions for improvement of Cinnamon here
https://github.com/linuxmint/Cinnamon
Post Reply
markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

GJS, in medias res

Post by markfilipak » Sat Jun 01, 2019 1:38 pm

I approach GJS this time as I approached it other times, in medias res.

Suppose I have a web browser. Suppose that web browser has a js console. I can submit

Code: Select all

alert("Hello World!")
to that js console.

How do I do the same in Cinnamon?

User avatar
smurphos
Level 11
Level 11
Posts: 3985
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: GJS, in medias res

Post by smurphos » Sun Jun 02, 2019 2:49 am

Mmm,

As neither GJS (in Gnome 3) or CJS (in Cinnamon) are running in a browser context and alert() is AFAIK a browser specific method it's not going to work.

In Cinnamon you can bring up a console with the terminal commands cjs or cjs-console
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

Re: GJS, in medias res

Post by markfilipak » Sun Jun 02, 2019 3:11 am

Well, howdy smurfos,
You are correct. 'alert' is not of method of the global object in CJS.

In a browser (HTML page or console), submitting

Code: Select all

var s="";for (var a in this) s+=this.a+" ";alert(s);
fills an alert box with

Code: Select all

close stop focus blur open alert confirm prompt print postMessage captureEvents releaseEvents getSelection
getComputedStyle matchMedia moveTo moveBy resizeTo resizeBy scroll scrollTo scrollBy requestAnimationFrame
cancelAnimationFrame getDefaultComputedStyle scrollByLines scrollByPages sizeToContent updateCommands find
dump setResizable requestIdleCallback cancelIdleCallback btoa atob setTimeout clearTimeout setInterval
clearInterval createImageBitmap fetch self name history locationbar menubar personalbar scrollbars statusbar
toolbar status closed frames length opener parent frameElement navigator external applicationCache screen
innerWidth innerHeight scrollX pageXOffset scrollY pageYOffset screenX screenY outerWidth outerHeight
performance mozInnerScreenX mozInnerScreenY devicePixelRatio scrollMaxX scrollMaxY fullScreen
mozPaintCount onwheel ondevicemotion ondeviceorientation onabsolutedeviceorientation ondeviceproximity
onuserproximity ondevicelight content sidebar crypto onabort onblur onfocus onauxclick oncanplay
oncanplaythrough onchange onclick oncontextmenu ondblclick ondrag ondragend ondragenter ondragexit
ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended oninput oninvalid onkeydown
onkeypress onkeyup onload onloadeddata onloadedmetadata onloadend onloadstart onmousedown onmouseenter
onmouseleave onmousemove onmouseout onmouseover onmouseup onpause onplay onplaying onprogress
onratechange onreset onresize onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend
ontimeupdate onvolumechange onwaiting onselectstart ontoggle onmozfullscreenchange onmozfullscreenerror
onanimationcancel onanimationend onanimationiteration onanimationstart ontransitioncancel ontransitionend
ontransitionrun ontransitionstart onwebkitanimationend onwebkitanimationiteration onwebkitanimationstart
onwebkittransitionend onerror onafterprint onbeforeprint onbeforeunload onhashchange onlanguagechange
onmessage onoffline ononline onpagehide onpageshow onpopstate onstorage onunload localStorage 
isSecureContext indexedDB caches sessionStorage window document location top InstallTrigger addEventListener
removeEventListener dispatchEvent
If I'm to hack CJS, I need to find its equivalent. I hacked that 'print' is a method of the global object, but the equivalent of the browser code provokes

Code: Select all

cjs> for (var a in this) print this.a;
SyntaxError: missing ; before statement
Do you have any ideas?

PS: Then I tried thinking...

Code: Select all

cjs> for (var a in this) print(this.a)
interact
a
Last edited by markfilipak on Sun Jun 02, 2019 1:44 pm, edited 1 time in total.

User avatar
smurphos
Level 11
Level 11
Posts: 3985
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: GJS, in medias res

Post by smurphos » Sun Jun 02, 2019 3:25 am

Take this with a pinch of salt, given my experience with CJS is limited to modifying existing JS for applets, deskets etc and that I don't know what your eventual use-case is, but I think if you want an 'in' to CJS your best bet is to package your scripts as a Cinnamon extension.

The Cinnamon specific documentation for this is a bit sketchy - http://developer.linuxmint.com/referenc ... orter.html - http://developer.linuxmint.com/referenc ... ystem.html - but the GJS wiki I linked you to in that other thread is more informative.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

Re: GJS, in medias res

Post by markfilipak » Sun Jun 02, 2019 3:31 am

smurphos wrote:
Sun Jun 02, 2019 3:25 am
Take this with a pinch of salt, given my experience with CJS is limited to modifying existing JS for applets, deskets etc and that I don't know what your eventual use-case is, but I think if you want an 'in' to CJS your best bet is to package your scripts as a Cinnamon extension.

The Cinnamon specific documentation for this is sketchy - http://developer.linuxmint.com/referenc ... ystem.html
I'll check it out. Thanks.
...but the GJS wiki I linked you to in that other thread is more informative.
I didn't understand a single thing there except that one of the references did a lot of complaining about how bad the documentation was and that their reference would correct it, and then it went into Outer Space.

I've been doing a lot of thinking lately about why codesmiths are so clueless about how to document what they do.

markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

Re: GJS, in medias res

Post by markfilipak » Sun Jun 02, 2019 3:37 am

@smurfos,

I've read only a couple of paragraphs of 'http://developer.linuxmint.com/referenc ... pplet.html' and it looks like exactly what I need.

markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

Re: GJS, in medias res

Post by markfilipak » Sun Jun 02, 2019 1:02 pm

Code: Select all

mark@mark-VirtualBox ~ $ cjs -c "print(this)"
[object Object]
mark@mark-VirtualBox ~ $ cjs -c "print(interact)"

(cjs:3296): Cjs-WARNING **: JS ERROR: ReferenceError: interact is not defined
@<command line>:1

JS_EvaluateScript() failed
mark@mark-VirtualBox ~ $ cjs -c "print(this.interact)"
undefined
mark@mark-VirtualBox ~ $ cjs -c "for(var a in this)print(a)"
a
mark@mark-VirtualBox ~ $ cjs
cjs> for(var a in this)print(a)
interact
a
cjs> print(typeof(interact))
function
cjs> ^C
mark@mark-VirtualBox ~ $ echo "print(this))">foo.js
mark@mark-VirtualBox ~ $ cjs -c ./foo.js

(cjs:3465): Cjs-CRITICAL **: JS ERROR: SyntaxError: syntax error @ <command line>:1
JS_EvaluateScript() failed
mark@mark-VirtualBox ~ $ cat foo.js
print(this))
mark@mark-VirtualBox ~ $
What can I conclude?
The cjs namespace (or whatever it is) contains only a global variable.
The cjs global variable is available from the command line.
The global variable has 0 intrinsic properties and only 1 intrinsic method: 'interact'.
The 'interact' method is available solely from inside cjs, not from the command line.
Literal script can be submitted to cjs from the command line (cjs -c "...script..."), but script files cannot.
Since 'print' is not found as a method of the global variable via enumeration, it is either not enumerable or the cjs command input is procedural, only -- probably the later.

You probably see the direction this hacking approach takes. It may be just me, but I think such a hacking approach is the only sensible way to approach the subject.

The 'interact' method seems to be the entire user interface. A search of github yields only this:

Code: Select all

**Import with `const System = imports.system;`**

The System module offers a number of useful functions and properties for debugging and shell interaction (eg. ARGV):

  * `addressOf(object)`
That's not enough for me to proceed.

Do you have any suggestions?

PS: 'this.interact()' has no constructor, no prototype, and no __proto. Thus, I assume that 'cjs' is a wrapper that is 100% procedural (not object) that synthesizes a user interface (probably from Cpp).

PPS: I searched the file system for 'JS_EvaluateScript' and found nothing. Thus, I assume that 'JS_EvaluateScript()' is a 'cjs' internal method. That's all that I've been able to expose so far.

markfilipak
Level 5
Level 5
Posts: 655
Joined: Sun Mar 10, 2013 8:08 pm
Location: Ohio (formerly California), USA

Re: GJS, in medias res

Post by markfilipak » Sun Jun 02, 2019 2:33 pm

Steve (aka 'smurphos')

I just noticed that it's 'smurphos', not 'smurfos'. Is there a story there?

Post Reply

Return to “Cinnamon”