App API

App Utilities

Application lifecycle management, version information, and system integration utilities.

initApp

Initialize your application with configuration and logging.

async function initApp(config: AppConfig): Promise<void>

Parameters

PropertyTypeDescription
namestringApplication name
versionstringApplication version
authorstring?Application author

Example

import { initApp } from '@deskforge/runtime';

await initApp({
  name: 'My Desktop App',
  version: '1.0.0',
  author: 'Your Name',
});

// Logs: "My Desktop App v1.0.0"
// Logs: "By Your Name"

getAppVersion

Get the current application version from Tauri.

async function getAppVersion(): Promise<string>

Returns

Returns the app version string, or "0.0.0" if unavailable.

Example

import { getAppVersion } from '@deskforge/runtime';

const version = await getAppVersion();
console.log(`Running version: ${version}`);

// Display in UI
document.getElementById('version').textContent = `v${version}`;

getAppName

Get the application name from Tauri configuration.

async function getAppName(): Promise<string>

Returns

Returns the app name, or "DeskForge App" if unavailable.

Example

import { getAppName } from '@deskforge/runtime';

const appName = await getAppName();
document.title = appName;

exitApp

Exit the application with an optional exit code.

async function exitApp(code?: number): Promise<void>

Parameters

ParameterTypeDescription
codenumber?Exit code (default: 0)

Example

import { exitApp } from '@deskforge/runtime';

// Normal exit
await exitApp();

// Exit with error code
await exitApp(1);

// Exit after cleanup
async function handleQuit() {
  await saveUserData();
  await exitApp();
}

Note: If the Tauri command fails, this will fall back to closing the window.

relaunchApp

Restart the application. Useful for applying updates or resetting state.

async function relaunchApp(): Promise<void>

Example

import { relaunchApp } from '@deskforge/runtime';

// Relaunch after update
async function applyUpdate() {
  await downloadUpdate();
  await installUpdate();
  
  // Restart to apply changes
  await relaunchApp();
}

// Relaunch with user confirmation
button.addEventListener('click', async () => {
  const confirmed = confirm('Restart application?');
  if (confirmed) {
    await relaunchApp();
  }
});

Complete Example

Here's a complete example showing how to use app utilities together:

import { 
  initApp, 
  getAppVersion, 
  getAppName,
  exitApp,
  relaunchApp 
} from '@deskforge/runtime';

// Initialize app
await initApp({
  name: 'My Desktop App',
  version: '1.0.0',
  author: 'Your Company',
});

// Get and display version info
const version = await getAppVersion();
const name = await getAppName();

document.getElementById('app-info').innerHTML = `
  <h1>${name}</h1>
  <p>Version: ${version}</p>
`;

// Handle quit button
document.getElementById('quit-btn').addEventListener('click', async () => {
  // Save data before quitting
  await saveApplicationState();
  await exitApp();
});

// Handle restart button
document.getElementById('restart-btn').addEventListener('click', async () => {
  const confirmed = confirm('Restart the application?');
  if (confirmed) {
    await relaunchApp();
  }
});

Best Practices

✓ Initialize Early

Call initApp() at the start of your application to log version info.

✓ Save Before Exit

Always save user data and application state before calling exitApp().

✓ Confirm Relaunch

Ask for user confirmation before calling relaunchApp() to avoid unexpected restarts.