Runtime Notes
Content runs in JavaScriptCore, not in a browser. The type declarations (the API reference) are compiled from the engine's source, with only the APIs that really exist. The main points:
- There is no DOM and no Node.js: no
document, nowindow; see Network for the network, Storage and Files forlocalStorageand files, and Audio for sound. Modules in the runtime are CommonJSrequire(); to useimport, put your code insrc/and let the SDK bundle it (see Projects and Builds). DesktopEngine.system.cpuUsage()/memoryUsage()give CPU and memory usage; they need thesystem-infopermission and throw without it.
Canvas
- Canvases have 2D, WebGL 1 and WebGL 2 (
getContext('webgl2'), OpenGL ES 3.0 on ANGLE).texImage3D/texSubImage3Dalso take images,ImageDataand canvases, with the layers top to bottom in the source image (spaced byUNPACK_IMAGE_HEIGHT, the height by default). Macs with Apple silicon haveWEBGL_compressed_texture_astc. - As in browsers, a WebGL 2 context isn't
instanceof WebGLRenderingContext: check the version withinstanceof WebGL2RenderingContext. - Canvases render with Metal. On old Macs whose graphics don't support Metal, every
getContextreturns null andCanvasImagefails to load, so check what they return. - Canvases have an alpha channel by default (as on the web). Widget and pet windows are transparent, so the desktop shows where nothing is drawn.
- A canvas's drawing buffer (
width×height) is stretched to the size of its style, smoothly by default. For pixel art, draw 1:1 in a small buffer and set the styleimageRendering: 'pixelated'to scale it up into sharp squares (the built-in pixel cat is drawn this way);'crisp-edges'doesn't smooth when scaling down either. - Canvases follow the scale of their display, see Displays and scale.
- The GPU gives a frame's work a few seconds at most. When a canvas takes longer (a huge draw, a shader that loops for long), macOS resets the GPU, which freezes the whole screen for a moment. The canvas' context is lost then, for good, so that it can't happen again: the canvas fires
webglcontextlost(contextlostfor 2D), keeps what it last showed, and draws nothing more; the context'sisContextLost()returns true. Keep each frame's GPU work small, especially on large canvases. WideshadowBlurshadows are blurred at a lower resolution, which looks the same. - WebGL buffers, textures and shader programs are freed by
gl.deleteXxx()or when the canvas is destroyed; dropping them in JavaScript doesn't delete them (they may still be bound). Programs that keep creating resources mustdeletethem.
Not there yet
- Signing, review and an online library: content is shared by importing a .zip or a folder for now.
- APIs for the
files,now-playingandwindow-positionspermissions. - Reading the system's audio output (music visualizers), IndexedDB.
- Native ES modules in the runtime (bundling
src/covers them for now).
Ask for what you need on GitHub.
