Host functions

This page details each host function and what it does. Each different module and group of functions are separated into their own section so you can quickly find what you need.

In-Depth starter info

I recommend you read these first few sections before getting started.

Global Types

Color:
- r: int - Red
- g: int - Green
- b: int - Blue
- a: Optional[int] - An optional alpha, default to 255 if not passed
TextColors:
- foreground: Color - The text color
- background: Optional[Color] - An optional background to put behind the text, to help with visibility
ConfigGet[T]: - Make sure you parse the value correctly once you receive it
- value: T - The typed return value 
ConfigSet[T]: - Make sure you serialize the value correctly when sending it
- key: str - The key of the particular item to be set
- value: T - The typed value to set
MossState:
- width: int - The width and of the moss window
- height: int
- current_screen: str - The class name of the current moss screen
- opened_context_menus: List[str] - A list of class names of all opened context menus
- icons: List[str] - A list of all the icons loaded by moss

Safe paths

Your extension will most of the time only be allowed several types. Moss will check these to ensure security. You can also access these paths in your extension where the filesystem access is handled by extism and not Moss.

For example if I had an asset in my extension folder assets/ico.svg I could simply refer to it as extension/assets/ico.svg

Or if you wanted to do some manual evaluation of the cached sync files you could do something like sync/{hash} and so on...

Default configuration and assets

Your extension is typically in .wasm format, but moss will automatically provide a folder for your extension. Moss will also accept .zip files too and even ask the user if they want to enable it.

Your extension can provide a default config to the Moss extension manager by having a valid options.json file in its associated folder.

Registering your extension

Moss has 3 main functions that must be defined. These functions are your entrypoints.

This function will be initially called by Moss when loading your extension. Its job is to define any extension wide values, prepare config, change defaults, register context menus and so forth. You are also required to return your extension information.

This function is called once every frame. Please note that this function will not be called until the loading of Moss is completed!

This function serves as a last chance for your extension to clean up any files or do any last minute configuration updates. This function gets called during reloads and when closing Moss.

GUI functions

GUI types

Context menu functions

Creates a context menu within Moss that you can refer to. This function is usually meant to be called during extension registration.

Activates any registered context menu onto your screen on the specified xand y coordinates. The context menu will remain open unless the user clicks outside of it.

Miscellaneous functions

This function inverts any icon key you give it and will store the result into the respective result_key. You can pass the same key both arguments to permanently invert that icon instead of making an inverted duplicate. You can use this to invert your own assets or to create something like the Moss dark mode extension.

Defaults functions

Defaults refers to a class in Moss which globally describes every single configuration such as paths to folders or colors, these can be changed or viewed by extensions but whether or not Moss would respond to any changes depends highly on when you call any set function, it is recommended to do so at the registration stage!

Functions for setting/getting colors

This function sets that particular color in the Defaults, ideal at registration.

Likewise this function will return any particular color from the Defaults.

This function sets that particular set of text colors in the Defaults, again ideal at registration, even though most UI will refresh texts depending on the situation.

This function returns that particular set of text colors from the Defaults.

Functions for setting/getting values

This function returns any value given the key in Defaults, it is passed to the extension as an object containing the typed value, your extension needs to properly parse the value's type.

This function sets any value given the key in Defaults, it accepts the value as is from the extension and your extension needs to properly type it if it is updating an existing value. Your SDK should abstract any type to be passed directly instead of ConfigSet .

Extension manager functions (EM)

All these functions are closely related to either your interactions with Moss and the extension manager or accessing things available to your extensions / other extensions.

Functions for setting/getting config values

Some of these are very similar to the defaults as they are related to setting the config file. You can take a look above for more information on these functions. Your extension is granted one config file it can use and it is automatically saved and managed for you.

Functions for managing your extension

You can find more info on ContextButton above

This function registers one or more context buttons to be passed to the side menu "Extensions" context menu. It is recommended that if you choose to add a button you'd only add one and then that would open a context menu or a screen that can there allow the user to further interact with your extension.

Functions of the extension manager

This function exports the extension manager's statistical call data to TEMP_DIR/extension_calls.json , the data is stored in the following format:

dictionary -> extension_name : dictionary -> function_name : call count

This function is useful if you need the state of Moss but are running code outside the loop function which would otherwise receive the state automatically.

Pygame extra functions (PE)

Pygame extra types

Notice that everything except the key and loop are optional functions you can use and are not required to be passed!

Functions for drawing basic shapes

This function draws a basic rectangle. Your SDK should abstract this, typically to expand the individual components of PygameExtraRect into arguments instead.

Custom screens

The first steps for making custom screens with Moss is registering your extension's functions with a custom screen, so Moss can create your screen and call your extension

This function will register your screen with Moss, you can also use to register children screens, which are screens to be rendered on top of other screens (things like popups, context menus for example, but Moss already has those for you)

This function will open a new instance of your screen in Moss. Your SDK should manage the initial_values to be serialized before passing through extism. It returns the id of the screen in Moss.

This function will get any value from the screen that you passed through using initial_values or set separately. This function can optionally fetch variables or properties on the screen, as long as they are serializable.

This function will update any value from the screen that you passed through using initial_values or set any extra values.

Text

Moss has an approach to text where you can create a text and Moss returns an id, from there you can call functions on this text through many small functions. Your SDK should implement this in an OOP way that allows the user to store and manipulate text objects easily on the extension while forwarding all changes to Moss.

Functions for managing text

Creates a text and gives you the ID that you can use to refer to this text object. Please note that the font here refers to the font path.

Any further functions where you see text_id: int it is referring you to pass the ID you got from moss_text_make .

This updates the text object and renders new text, this operation shouldn't be done extensively unless your text needs to change often, text objects are optimized to not be updated often and just displayed.

This updates both the font file, given a path and the font size, it will also regenerate the text object for you and position it in the center of wherever it was before.

Notice that the above functions return the text rect, this is important and it is due to the fact that the rect of the text would have changed. It simplifies calls

Updates the text rect, this determines the text position.

Gets the text rect, the reason it's a rect is to provide the text size. The SDK you use should probably run this after making a text in order to have all the values of the text locally in your extension

Displaying text

There's not much special about this function, it will display the text at the topleft of the rect, the size of the rect is determined by the text size so the text should be effectively be drawn within this are. Please note that the text background you passed is automatically drawn too as part of this operation.

Basic API usage

API Models

Additionally here are some of the enums that you may have noticed above.

Accessors

Let's cover everything there is to know about how your extension manages document data inside of Moss. There are a few terms that will be used often and here's what they mean

  • API item - The item is stored on rm_api meaning that it will visible to menus and the api itself.

  • Standalone item - The item is stored inside of the extension manager and not visible to rm_api and won't show up in menus.

  • Sub item - This can refer to a metadata/content inside of a document or collection. If this accessor is used, the uuid refers to the document or collection that the item is inside of.

The accessor data model

It's important to note that some functions will not accept your accessor if they aren't made to handle it. For example you obviously cannot pass a metadata accessor to a document management function. It will throw a violation error.

Accessors footnote

Moss has a way of dealing with the diverse quantity of data combinations. It uses what's called the accessor system, where each item access type is referenced by an accessor field.

The accessor list

The accessors are strings. You should check how your SDK provides them if at all, these should otherwise be automatically handled by your SDK.

Data models

These models are referenced below when creating new instance of API objects

Main accessor functions

This function gets only one field from the accessor.

This function sets only one field of the accessor.

This function will fetch the entire accessor with all it's fields.

Functions for documents

All the functions here are related to either creating or managing documents

Creating documents

Each creating function below returns the new document's UUID. Your SDK should apply it to the accessor automatically.

Managing documents

Returns the UUID of the new duplicate. This function randomizes a lot of the UUIDs of the document, it will also update timestamps and set the document to provision.

This function is self explanatory, it will modify all the document UUIDs including nested UUID references to a new random UUID and return the new UUID.

Simply unloads any files that Moss has loaded on the document. Documents will usually be automatically unloaded upon closing. If your extension loaded files though, this is the way to unload them and you should!

This function loads all the files enforcing cache usage only. If the cache misses a file, it will not be downloaded.

Document downloads are threaded, this is one way to check for when your document has finished downloading. The callback as all other extension functions accepts the name of your extension callback function.

This function is very similar to the above, but it does not run a callback. It will halt until the document is finished downloading.

This function prepares the document for uploading to the cloud. It prepares data and hashes converting the metadata and content data into raw data for upload.

Functions for metadata

Creates a new standalone metadata object and returns the id of it.

Functions for content

This function creates a content object for a blank notebook with a specified page count. You must pass at minimum one page! Returns standalone content id

These functions create blank content objects for pdf and epub. Notice that they do not identify any data, it's just a blank content template, the data for the pdf or epub would be on the document object. If you wanted to make a pdf or epub document check the document creation functions above. Returns standalone content id.

Advance API usage

This covers real API interactions. So be careful what you do. Always test on a suitable secondary account if possible, and use the recovery tools provided by the open source version of Moss if you ever find yourself in a pickle.

You'll notice that accessors are used here too. Extension manager will catch any loose sync progress objects and make them available to your extension. So you can receive external sync operations as well as start your own.

Advance API models

Making sync operations

Some API functions require you to define a sync operation before you call them. These are simple objects for tracking progress. Moss provides two functions for creating both sync operation types

In Moss a file sync operation contains all the tasks to be completed for this sync task. This returns the operation ID.

Document sync operations are more specific since they internally need a file sync operation too. They identify the document and have the top most amount of steps/files needed to upload the document. If this is sent to the menus it will display as a progress bar of the files being uploaded. The file sync progress on the other hand is usually contains the total amount of bytes.

Please note that these operations need to be transmitted as events in the API for them to register in menus. API functions requesting sync progress object will usually do this for you. However you can also send events for these yourself if you has some custom sync event going on.

Creating your own sync messages and icons

Moss has an accessor for this but there are a few things to note.

First off ALL stages of sync from 0 until 99 are reserved by rm_api so you cannot set new ones under those indexes, but if you desire you can modify them.

You can check what sync stages rm_api has here. These are unlikely to change. Your extension can create its own stage between 100 - 999.

What you want to do is simply use the accessor sync_stage (id is the index) and set the individual icon and text using moss_api_set

The result

Rust SDK custom sync stage

Raw API requests BE CAREFUL!!!

These functions allow you to access the user cloud directly. The protective measures of Moss and rm_api won't be there, so be very careful what you are doing and make sure to ask for user consent. Be careful how you test your extension, always use a test cloud for these kinds of things. Follow reMarkable's cloud conventions to protect the user from take down.

This function will fetch the current root file from the cloud. Please note that if the generation is missing Moss is running in a semi-offline mode. You won't be able to perform any further actions except maybe getting cached files. Moss keeps track of the last synced root file and if it is offline this is what you will get, but without the generation.

This function is mainly for getting the list of files in one of the .doc entries, this includes the root file and all of the file it lists, after that they contain actual data files root->docfile->*content

Tells the cloud the file that should become your new root file. Ensure it is uploaded!!!

Miscellaneous functions

This function will spread an event to any event subscriber on the rm_api. These include the sync operation events but also other events which Moss can spread for you, check accessors above.

Last updated