-
Notifications
You must be signed in to change notification settings - Fork 1
DevJSRuntime
The JSRuntime in ImMobile enables powerful scripting using QuickJS, giving developers access to internal APIs through a global object called imm. It allows you to create extensions, automation scripts, and interactive tools with familiar JavaScript syntax.
To use JSRuntime:
- Your script should access ImMobile's APIs via the global
immobject. - You can use functions like
setTimeout,sleepAsync, and many others.
// Delay execution by 2.5 seconds
imm.setTimeout(startTest, 2500);
// Async sleep for 1 second
await imm.sleepAsync(1000);Note: The
immobject in ImMobile containsosandstdin QuickJS-NG documentation.
By default ImMobile JSRuntime will load this part before your script
import * as std from "std";
import * as os from "os";
imm.std = std;
imm.os = os;
imm.setTimeout = function(fun, delay) {
return imm.os.setTimeout(fun, delay);
}
imm.clearTimeout = function(id) {
return imm.os.clearTimeout(id);
}
imm.sleepAsync = async function(ms) {
return await imm.os.sleepAsync(ms);
}you don't have to do this it happens normally,
as you can see I shorten the way for timeout and sleep like imm.sleepAsync instead of imm.os.sleepAsync
Using imm.os or imm.std you can access to the functions that integrated with QuickJS-NG runtime
It's very recommeneded to reset the runtime for your script before start using this code
imm.resetRuntime();Check this file for more examples
ImMobile Runtime may not always throw exceptions for the script, so you mostly may not see error in the console
to catch the exact issue always ensure to use try/catch for the part you need to track
var handle = null;
try {
handle = imm.os.open(filename, imm.os.O_RDONLY);
} catch (e) {
console.error(e);
}JSRuntime supports special string constants that are auto-replaced with paths to relevant folders:
| Constant | Description |
|---|---|
$exts |
Extensions folder |
$runs |
Runtime scripts folder |
$updates |
Updates folder |
$startup |
Startup scripts folder |
$cfgs |
Configuration folder |
$fonts |
Fonts folder |
$temp |
Temporary files directory |
$local |
Local app data folder |
$music |
Music folder (ImMobile scoped) |
$pics |
Pictures folder (ImMobile scoped) |
$vids |
Videos folder (ImMobile scoped) |
$data |
Root working data folder |
$backups |
Backups folder |
$downloads |
Downloads folder |
$textures |
Cached textures |
$tmpfiles |
Temporary files |
| Constant | Description |
|---|---|
$jsID |
Unique ID for the script |
$jsIndex |
Index of the script in execution stack |
$jsTime |
Timestamp of when the script started |
You can use console.log(...) or similar functions, and output will appear in the script-specific console in ImMobile.
note that constants my not appear in the real full value in console but that's fine I forgot to replace the value for output print.
Below is a categorized list of available API functions accessible through imm.
-
imm.toast(title, message)
Display a system notification. -
imm.notify(message, type)
Show an ImMobile in-app notification.
type:"info","success","warn","error" -
imm.noticeDialog(title, text, onClose)
Show an info dialog. -
imm.confirmDialog(title, message, callback)
Confirmation dialog with callback returningtrue/false. -
imm.inputDialog(title, text, onClose)
Prompt input dialog.
-
imm.openURI(url)
Open a URL in the default browser. -
imm.quickDownload(url, dest)
Download a file quickly todest.destexpected as file name/sub path not a full path, file will be at downloads folder by default -
imm.getOnlineFileName(url, defaultName)
Get filename from a remote resource, it may return the string before '?' if fail, ensure to use your own way to cover fail case. -
imm.getResponse(url)
Fetch a remote response as string, return the response or undefined if fail. -
imm.downloadResponse(url, dest)
Download response to a file.destexpected as file name/sub path not a full path, file will be at downloads folder by default -
imm.gitHubContent(user, repo, sub, callback)
Load GitHub content (optionally from a subdirectory). -
imm.gitHubLatestRelease(user, repo, callback)
Get info about the latest release. -
imm.showGitHubReadMeUI(url, token)
Show UI to browse a GitHub README. -
imm.showGitHubReleasesUI(url, token)
UI for browsing and downloading GitHub releases. -
imm.showGitHubFilesUI(url, token)
UI for browsing and downloading repository content. -
imm.isOnline()
Returnstrueorfalsebased on network availability.
Note that you can check QuickJS-NG Docs for more functions
-
imm.createFolder(parent, name)
Create a folder under a given path, return the full path for folder or undefined if fail. -
imm.filePutContents(path, content)
Write text to a file. -
imm.fileGetContents(path)
Read the content of a file, return file content or undefined if fail. -
imm.openFile(path)
Open file with the default OS app. -
imm.openFolder(path)
Reveal folder in OS file explorer. -
imm.unZip(file, dest, callback)
Unzip archive with callback. -
imm.zipFolder(folder, dest, callback)
Zip folder with callback.
-
imm.installPackage(path)
Install.appx,.msix, or similar package. -
imm.registerPackage(path)
Register a package via its manifest. -
imm.removePackage(id)
Remove installed package by ID or name.
-
imm.loadExten(path, window, confirm)
Load an ImMobile extension. -
imm.unloadExten(path)
Unload an ImMobile extension. -
imm.extenToggleGUI(path)
Toggle extensionโs UI visibility. -
imm.isExtenLoaded(path)
Check if an extension is currently loaded.
-
imm.chooseFile(callback)
File picker; returns selected path. -
imm.saveFile(callback)
Save-as file dialog. -
imm.chooseFolder(callback)
Folder picker; returns selected path.
-
imm.setClipboard(text)
Set system clipboard text. -
imm.getClipboard()
Get current clipboard text. -
imm.showKeyboard(state)
Show or hide on-screen keyboard. -
imm.changeBackground(path)
Change ImMobile background.I forgot to apply constants replacement on
pathat this function so ensure to use proper full path
Some functions like change background has no constants replacement,
as solution for path constants you my do it like:
var downloadsFolder = "$downloads";
var bingWallpapers = "BingsWallpapers";
// Create if not exists
var folderPath = imm.createFolder(downloadsFolder, bingWallpapers);
// Now you have full resolved path: folderPath same goes for path parts, most functions do replace / by \ for windows
but some like background change don't, so ensure to use \\ by default to avoid issues
- QuickJS-NG Docs โ for general JS behavior
- ImMobile Extensions โ for advanced extension development