App
Provides methods to manage application lifecycle.
import { app } from '@mobrowser/api';
Example
import { app } from '@mobrowser/api';
console.log(app.name)
console.log(app.version)
Properties
packaged
readonly packaged: boolean;
Indicates whether the application is packaged (i.e., running in production mode) or running in development mode.
Example
import { app } from '@mobrowser/api';
if (app.packaged) {
console.log('Running in production')
}
url
readonly url: string;
The URL of the application frontend entry point.
It can be different based on whether the application is running in the development or
production mode. The value for each mode is configured in the mobrowser.conf.json file
in the configurations section.
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win = new BrowserWindow()
win.browser.loadUrl(app.url)
name
readonly name: string;
The application name defined in the mobrowser.conf.json file.
version
readonly version: string;
The application version defined in the mobrowser.conf.json file.
description
readonly description: string;
The application description defined in the mobrowser.conf.json file.
copyright
readonly copyright: string;
The application copyright information defined in the mobrowser.conf.json file.
schemes
readonly schemes: string[];
Custom URL schemes (without ://) declared in mobrowser.conf.json as app.schemes.
For example, "demoapp" allows demoapp://… links.
On macOS, these values populate CFBundleURLSchemes when the app bundle is branded.
When non-empty, the runtime registers the app as a handler so other software can open
those schemes. Matching activations invoke the app.handle('openUrl', …) handler when
it is registered.
launchInfo
readonly launchInfo: LaunchInfo;
Contains information about the application launch, including whether it is the first run and the version that was previously launched.
Example
import { app } from '@mobrowser/api';
if (app.launchInfo.isFirstRun) {
console.log('Welcome!')
}
windows
readonly windows: BrowserWindow[];
An array of all currently open browser windows. This array is updated automatically as windows are created and closed.
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win = new BrowserWindow()
win.setTitle('MyApp')
app.windows.forEach(win => console.log(win.title))
theme
readonly theme: Theme;
The current application theme.
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win = new BrowserWindow()
if (app.theme === 'dark') {
win.setTitle('App (Dark Mode)')
}
menu
readonly menu: Menu;
The application main menu.
trustedOrigins
readonly trustedOrigins: string[];
Origins that are allowlisted for automatic permission grants without invoking
the requestPermissions handler.
Trusted origins will be granted with all permissions including:
- camera access
- display-capture
- microphone access
- notifications
- persistent-storage access
- clipboard read and write access
- geolocation access
- audio and video capture access
To grant permissions for additional origins without handling each request, add entries to
app.trustedOrigins in mobrowser.conf.json. Each entry must be an origin or hostname
pattern up to eTLD+1. For example, "http://foo.com", "http://foo.com:8000",
"*.foo.com", "*.foo.*.bar.com", and "http://*.foo.bar.com", but not "*.co.uk", "*.com", or
"test.*.com". Hostname patterns must include a wildcard somewhere, so "test.com" alone is not a valid
pattern, and wildcards may only replace full hostname components ("test*.foo.com" is not valid).
Example
"trustedOrigins": [ "https://foo.com", "*.foo.com", "https://*.foo.bar.com" ],
loginItemSettings
readonly loginItemSettings: LoginItemSettings;
The current login-item settings for the application.
Example
import { app } from '@mobrowser/api';
if (app.loginItemSettings.openAtLogin) {
console.log('Launch at login is enabled')
}
permissions
readonly permissions: AppPermissions;
Provides access to system permissions on macOS and Windows.
On Windows, getStatus() and openSystemSettings() support microphone
and camera.
Example
import { app } from '@mobrowser/api';
const permission = 'microphone'
let status = app.permissions.getStatus(permission)
if (status === 'notDetermined') {
await app.permissions.request(permission)
status = app.permissions.getStatus(permission)
}
if (status === 'denied') {
app.permissions.openSystemSettings(permission)
}
Methods
setMenu()
setMenu(menu: Menu): void;
Sets the application main menu.
| Parameter | Type | Description |
|---|---|---|
menu | Menu | The menu to set as the application main menu. |
Example
import { app } from '@mobrowser/api';
app.setMenu(new Menu({
items: [
new MenuItem({
id: 'quit',
label: 'Quit',
action: (item: MenuItem) => {
app.quit()
}
})
]
}))
setTheme()
setTheme(theme: Theme): void;
Sets the application theme.
| Parameter | Type | Description |
|---|---|---|
theme | Theme | The theme to set. |
Example
import { app } from '@mobrowser/api';
// Set the dark theme
app.setTheme('dark')
// Set the light theme
app.setTheme('light')
// Set the theme of the operating system
app.setTheme('system')
showMessageDialog()
showMessageDialog(options: MessageDialogOptions): Promise<MessageDialogResult>;
Opens a message dialog with the given options.
| Parameter | Type | Description |
|---|---|---|
options | MessageDialogOptions | The options to use for opening the message dialog. |
Return value
The result of the message dialog as a promise that resolves to a MessageDialogResult object.
Example
import { app, BrowserWindow } from '@mobrowser/api';
// Create a new window.
const win = new BrowserWindow()
win.setTitle('MyApp')
win.show()
// Show a message dialog.
const result = await app.showMessageDialog({
parentWindow: win,
title: 'Would you like to delete this conversation?',
message: 'This conversation will be deleted from all of your devices. ' +
'You cannot undo this action.',
buttons: [
{ label: 'Cancel', type: 'secondary' },
{ label: 'Delete', type: 'primary' }
]
})
if (result.button.type === 'primary') {
// The 'Delete' button was clicked.
}
showOpenDialog()
showOpenDialog(options: OpenDialogOptions): Promise<OpenDialogResult>;
Opens a file open dialog with the given options.
| Parameter | Type | Description |
|---|---|---|
options | OpenDialogOptions | The options to use for opening the file open dialog. |
Return value
The result of the file open dialog as a promise that resolves to a OpenDialogResult object.
Example
import { app, BrowserWindow } from '@mobrowser/api';
// Create a new window.
const win = new BrowserWindow()
win.setTitle('MyApp')
win.show()
// Show a file open dialog.
const result = await app.showOpenDialog({
parentWindow: win,
title: 'Open Files',
defaultPath: '/Users/john/Desktop',
selectionPolicy: 'files',
features: {
allowMultiple: true,
canCreateDirectories: true
},
})
if (!result.canceled) {
console.log('Selected paths: ', result.paths[0])
}
showSaveDialog()
showSaveDialog(options: SaveDialogOptions): Promise<SaveDialogResult>;
Opens a file save dialog with the given options.
| Parameter | Type | Description |
|---|---|---|
options | SaveDialogOptions | The options to use for opening the file save dialog. |
Return value
The result of the file save dialog as a promise that resolves to a SaveDialogResult object.
Example
import { app, BrowserWindow } from '@mobrowser/api';
// Create a new window.
const win = new BrowserWindow()
win.setTitle('MyApp')
win.show()
// Show a file save dialog.
const result = await app.showSaveDialog({
parentWindow: win,
title: 'Save File',
defaultPath: '/Users/john/Desktop',
filters: [{ name: 'Text Files', extensions: ['txt'] }]
})
if (!result.canceled) {
console.log('Selected path: ', result.path)
}
getPath()
getPath(name: PathName): FilePath;
Gets the absolute path to a directory identified by the given name.
| Parameter | Type | Description |
|---|---|---|
name | PathName | Identifies which path should be retrieved. |
Return value
The absolute path to the directory or an empty string if the path is not found.
Example
import { app } from '@mobrowser/api';
// Get the path to the app resources directory.
const dirPath = app.getPath('appResources')
console.log(dirPath)
quit()
quit(): void;
Quits the application, closing all windows and terminating the process.
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win = new BrowserWindow()
win.show()
const result = await app.showMessageDialog({
parentWindow: win,
title: 'Quit',
message: 'Are you sure you want to quit?',
buttons: [
{ label: 'Cancel', type: 'secondary' },
{ label: 'Quit', type: 'primary' }
]
})
if (result.button.type === 'primary') {
app.quit()
}
restart()
restart(): void;
Restarts the application, closing all windows and terminating the process.
The new application instance will use the same working directory and the command line arguments as the current one.
Example
import { app, BrowserWindow } from '@mobrowser/api';
const win = new BrowserWindow()
win.show()
const result = await app.showMessageDialog({
parentWindow: win,
title: 'Restart',
message: 'Restart to apply the new settings?',
buttons: [
{ label: 'Later', type: 'secondary' },
{ label: 'Restart', type: 'primary' }
]
})
if (result.button.type === 'primary') {
app.restart()
}
setLoginItemSettings()
setLoginItemSettings(settings: LoginItemSettings): void;
Configures the application’s login-item settings on Windows and macOS.
| Parameter | Type | Description |
|---|---|---|
settings | LoginItemSettings | The login-item settings to apply. |
Example
import { app } from '@mobrowser/api';
app.setLoginItemSettings({
openAtLogin: true,
args: ['--hidden'], // Windows only
})
checkForUpdate()
checkForUpdate(source: string): Promise<AppUpdate | undefined | string>;
Checks for an available application update.
Available only on Windows and macOS.
| Parameter | Type | Description |
|---|---|---|
source | string | a web server with files for application updates. |
Return value
A promise that resolves to the application update object if an update is available, or undefined if no update is available, or a string containing the error message if an error occurs.
Example
import { app, AppUpdate } from '@mobrowser/api';
const result = await app.checkForUpdate('https://app.com/updates')
if (!result) {
// No update is available or do nothing.
} else if (typeof result === 'string') {
// An error occurred while checking for updates.
} else {
// An update is available.
const appUpdate: AppUpdate = result
console.log('Update available: ', appUpdate.version)
}
Events
‘activated’
on(event: 'activated', listener: () => void): void;
off(event: 'activated', listener: () => void): void;
Emitted when the application is activated. On macOS, this event can be triggered by various actions, such as clicking the Dock icon or switching to the application using Cmd+Tab. On Windows and Linux, this event is not triggered because these platforms do not have the same concept of application activation.
Example
import { app, BrowserWindow } from '@mobrowser/api';
app.on('activated', () => {
if (app.windows.length === 0) {
const win = new BrowserWindow({
size: { width: 800, height: 650 },
})
win.browser.loadUrl(app.url)
win.show()
}
})
‘allWindowsClosed’
on(event: 'allWindowsClosed', listener: () => void): void;
off(event: 'allWindowsClosed', listener: () => void): void;
Emitted when all windows have been closed.
If you do not subscribe to this event and all windows are closed, the default
behavior is to quit the app. However, if you subscribe, you control whether the
app quits or not. For example, you can call app.quit() to quit, or do nothing
to keep the app running.
Example
import { app } from '@mobrowser/api';
app.on('allWindowsClosed', () => {
// On macOS it is common for applications to stay open
// until the user explicitly quits.
if (process.platform !== 'darwin') {
app.quit()
}
})
Handlers
openUrl
handle(action: 'openUrl', handler: (url: string, queryParams: Record<string, string>) => void): void;
removeHandler(action: 'openUrl'): void;
Invoked when the app is opened or activated via a custom URL scheme associated with
the application in mobrowser.conf.json as app.schemes.
A custom URL scheme allows external sources to trigger the application.
myapp://open?file=123&mode=edit
When a user opens such a link:
- If the app is not running → it will be launched
- The URL is passed to the app for handling
You can use this handler to react to the passed URL and perform actions accordingly. For example, you can just activate the app and show a specific window or parse the URL query parameters and perform actions based on them.
On macOS this handler is invoked in both cases, when the app is not running and when it is already running. If the app is already running, the handler will be invoked. If the app is not running, it will be launched and the handler will be invoked. So make sure to install the handler at the application startup as soon as you can, because the operating system will call the handler right after application startup.
On Windows and Linux the handler is called only when the app is already running.
If the user opens a custom-scheme link while the app is not running, the URL is passed
through the app the command line you can read using commandLine.hasSwitch('url')
and commandLine.getSwitchValue('url').
The handler receives the full URL string (including fragment, if present) and a plain object of decoded query parameters (duplicate keys keep the last value).
Example
import { app } from '@mobrowser/api';
app.handle('openUrl', (url: string, queryParams: Record<string, string>) => {
console.log('URL:', url, queryParams)
})