TypeScript Types

TypeScript Types

Complete TypeScript type definitions and interfaces for the DeskForge Runtime SDK.

WindowConfig

Configuration interface for window initialization.

interface WindowConfig {
  title?: string;
  width?: number;
  height?: number;
  minWidth?: number;
  minHeight?: number;
  resizable?: boolean;
  fullscreen?: boolean;
}

Properties

PropertyTypeOptionalDescription
titlestringWindow title displayed in title bar
widthnumberInitial window width in pixels
heightnumberInitial window height in pixels
minWidthnumberMinimum window width in pixels
minHeightnumberMinimum window height in pixels
resizablebooleanWhether the window can be resized
fullscreenbooleanStart in fullscreen mode

Example

import type { WindowConfig } from '@deskforge/runtime';

const config: WindowConfig = {
  title: 'My App',
  width: 1200,
  height: 800,
  minWidth: 800,
  minHeight: 600,
  resizable: true,
  fullscreen: false,
};

AppConfig

Configuration interface for application initialization.

interface AppConfig {
  name: string;
  version: string;
  author?: string;
}

Properties

PropertyTypeOptionalDescription
namestringApplication name
versionstringApplication version (semver)
authorstringApplication author or company

Example

import type { AppConfig } from '@deskforge/runtime';

const config: AppConfig = {
  name: 'My Desktop App',
  version: '1.0.0',
  author: 'Your Company',
};

IPCMessage

Structure for IPC command messages.

interface IPCMessage {
  command: string;
  payload?: any;
}

Properties

PropertyTypeOptionalDescription
commandstringCommand identifier
payloadanyCommand data (must be JSON-serializable)

Example

import type { IPCMessage } from '@deskforge/runtime';

const message: IPCMessage = {
  command: 'save_file',
  payload: {
    path: '/path/to/file.txt',
    content: 'Hello, World!',
  },
};

IPCResponse

Structure for IPC command responses.

interface IPCResponse {
  success: boolean;
  data?: any;
  error?: string;
}

Properties

PropertyTypeOptionalDescription
successbooleanWhether the command succeeded
dataanyResponse data (if successful)
errorstringError message (if failed)

Example

import type { IPCResponse } from '@deskforge/runtime';

// Success response
const successResponse: IPCResponse = {
  success: true,
  data: { id: 123, name: 'John Doe' },
};

// Error response
const errorResponse: IPCResponse = {
  success: false,
  error: 'File not found',
};

Complete Example

Here's a complete example using all the type definitions:

import type { 
  WindowConfig, 
  AppConfig, 
  IPCMessage, 
  IPCResponse 
} from '@deskforge/runtime';
import { initWindow, initApp, sendCommand } from '@deskforge/runtime';

// Define custom types
interface User {
  id: number;
  name: string;
  email: string;
}

interface SaveFilePayload {
  path: string;
  content: string;
}

// Configure window
const windowConfig: WindowConfig = {
  title: 'My Desktop App',
  width: 1200,
  height: 800,
  minWidth: 800,
  minHeight: 600,
  resizable: true,
};

// Configure app
const appConfig: AppConfig = {
  name: 'My Desktop App',
  version: '1.0.0',
  author: 'Your Company',
};

// Initialize
await initWindow(windowConfig);
await initApp(appConfig);

// Type-safe IPC
const user = await sendCommand<User>('get_user', { id: 123 });
console.log(user.name); // TypeScript knows this is a string

const savePayload: SaveFilePayload = {
  path: '/path/to/file.txt',
  content: 'Hello, World!',
};

const saved = await sendCommand<boolean>('save_file', savePayload);
if (saved) {
  console.log('File saved successfully');
}

Type Safety Tips

✓ Define Custom Interfaces

Create interfaces for your specific command payloads and responses for better type checking.

✓ Use Generic Type Parameters

Leverage TypeScript generics in sendCommand<T> for full type inference.

✓ Enable Strict Mode

Use "strict": true in your tsconfig.json for maximum type safety.

💡 Share Types

Consider sharing type definitions between your frontend and Tauri backend for consistency.