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
Moss will not start loading extensions until all assets are loaded
Moss will only load extension specified assets after all extensions are loaded
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 x
and 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.
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
Functions for managing your extension
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
Statistics have to be enabled by the user for Moss to setup the proper statistic tools
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
Functions for drawing basic shapes
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 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
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.
Updates the text rect, this determines the text position.
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
The above are made for connectivity of the extensions, some data is only used by Moss!Changing some things may not result in permanent changes, especially if the value is not a reMarkable value to begin with, or if you forgot to upload to the cloud!
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.
Be careful since rm_api is very particular about documents and will ensure only uploaded documents are in its list if synced.
The accessor data model
The only models that use id for their accessor reference are the standalone metadata and content!
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.
A note for SDK developers, your RM objects will receive their respective accessor reference. You do not need to worry much about the accessor, only making an updated copy in the case that you perform operations that change the identification of the object, such as duplicate or randomizing UUIDs!
The accessor list
Data models
These models are referenced below when creating new instance of API objects
You can either pass the data as bytes or file paths which are more efficient. Both of these values are otherwise optional, but Moss will complain if you didn't pass one!
Not passing a document_uuid will use a randomly generated uuid which you'll receive from the function. See below.
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
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.
The above download functions will also load the data, including using cache!
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.
This function does not upload the document to the cloud. Nor should you need to use it unless you are doing some form of manual upload processing. This function is internally automatically used by Moss before the upload happens, as the raw document data needs to be ready before upload, this means you can't modify anything during this process if you use the automatic rm_api upload functionality.
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.
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.
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
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
Last updated