Skip to main content
The System API provides access to various system-level features including biometric authentication (Touch ID), encryption, printing, timezone detection, and theme management.

Usage

use Native\Desktop\Facades\System;

// Check if Touch ID is available
if (System::canPromptTouchID()) {
    $authenticated = System::promptTouchID('Authenticate to continue');
}

// Encrypt sensitive data
$encrypted = System::encrypt('secret data');

// Get system theme
$theme = System::theme();

Biometric Authentication

canPromptTouchID()

Check if the system supports Touch ID or biometric authentication.
System::canPromptTouchID(): bool
return
bool
Returns true if Touch ID is available, false otherwise.
Example:
if (System::canPromptTouchID()) {
    // Show Touch ID login option
}

promptTouchID()

Prompt the user for Touch ID authentication.
System::promptTouchID(string $reason): bool
reason
string
required
A user-friendly message explaining why authentication is needed.
return
bool
Returns true if authentication was successful, false otherwise.
Example:
$authenticated = System::promptTouchID('Authenticate to access sensitive data');

if ($authenticated) {
    // Grant access
} else {
    // Deny access
}

Encryption

canEncrypt()

Check if the system supports encryption.
System::canEncrypt(): bool
return
bool
Returns true if encryption is available, false otherwise.

encrypt()

Encrypt a string using the system’s encryption capabilities.
System::encrypt(string $string): ?string
string
string
required
The plain text string to encrypt.
return
string|null
Returns the encrypted string, or null if encryption failed.
Example:
$encrypted = System::encrypt('my secret data');

decrypt()

Decrypt a previously encrypted string.
System::decrypt(string $string): ?string
string
string
required
The encrypted string to decrypt.
return
string|null
Returns the decrypted string, or null if decryption failed.
Example:
$encrypted = System::encrypt('secret');
$decrypted = System::decrypt($encrypted);
// $decrypted === 'secret'

Printing

printers()

Get a list of available printers on the system.
System::printers(): array<\Native\Desktop\DataObjects\Printer>
return
array
Returns an array of Printer objects, each containing:
  • name (string): The printer’s system name
  • displayName (string): The printer’s display name
  • description (string): The printer description
  • options (array): Additional printer options
Example:
$printers = System::printers();

foreach ($printers as $printer) {
    echo $printer->displayName;
}

print()

Print HTML content to a physical printer.
System::print(string $html, ?\Native\Desktop\DataObjects\Printer $printer = null, ?array $settings = []): void
html
string
required
The HTML content to print.
printer
Printer
The printer to use. If not specified, uses the system default printer.
settings
array
Print settings. See Electron’s print options for available options.
Example:
$html = '<h1>Invoice</h1><p>Total: $100</p>';

// Print to default printer
System::print($html);

// Print to specific printer with settings
$printers = System::printers();
System::print($html, $printers[0], [
    'silent' => false,
    'copies' => 2,
]);

printToPDF()

Convert HTML content to a PDF and return it as a base64-encoded string.
System::printToPDF(string $html, ?array $settings = []): string
html
string
required
The HTML content to convert to PDF.
settings
array
PDF generation settings. See Electron’s PDF options for available options.
return
string
Returns the PDF as a base64-encoded string.
Example:
$html = '<h1>Report</h1><p>Content...</p>';

$pdfBase64 = System::printToPDF($html, [
    'pageSize' => 'A4',
    'printBackground' => true,
]);

// Save to file
file_put_contents('report.pdf', base64_decode($pdfBase64));

System Information

timezone()

Get the system’s current timezone.
System::timezone(): string
return
string
Returns the timezone identifier (e.g., “America/New_York”).
Example:
$timezone = System::timezone();
config(['app.timezone' => $timezone]);

theme()

Get or set the system theme.
System::theme(?\Native\Desktop\Enums\SystemThemesEnum $theme = null): \Native\Desktop\Enums\SystemThemesEnum
theme
SystemThemesEnum
The theme to set. Options:
  • SystemThemesEnum::LIGHT
  • SystemThemesEnum::DARK
  • SystemThemesEnum::SYSTEM
If omitted, gets the current theme.
return
SystemThemesEnum
Returns the current system theme.
Example:
use Native\Desktop\Enums\SystemThemesEnum;

// Get current theme
$currentTheme = System::theme();

if ($currentTheme === SystemThemesEnum::DARK) {
    // Apply dark theme styles
}

// Set theme
System::theme(SystemThemesEnum::DARK);

Complete Examples

Secure Data Access

use Native\Desktop\Facades\System;

class SecureVault
{
    public function accessVault()
    {
        if (!System::canPromptTouchID()) {
            return response()->json(['error' => 'Biometric auth not available']);
        }
        
        $authenticated = System::promptTouchID('Access secure vault');
        
        if (!$authenticated) {
            return response()->json(['error' => 'Authentication failed'], 401);
        }
        
        // User authenticated, decrypt sensitive data
        $encryptedData = cache('user_secrets');
        $decrypted = System::decrypt($encryptedData);
        
        return response()->json(['data' => $decrypted]);
    }
}

Invoice Printing

use Native\Desktop\Facades\System;

class InvoiceController
{
    public function print($invoiceId)
    {
        $invoice = Invoice::findOrFail($invoiceId);
        $html = view('invoices.print', compact('invoice'))->render();
        
        // Get available printers
        $printers = System::printers();
        
        // Let user select printer or use default
        System::print($html, $printers[0] ?? null);
    }
    
    public function exportPDF($invoiceId)
    {
        $invoice = Invoice::findOrFail($invoiceId);
        $html = view('invoices.print', compact('invoice'))->render();
        
        $pdfBase64 = System::printToPDF($html, [
            'pageSize' => 'Letter',
            'printBackground' => true,
        ]);
        
        return response()->json([
            'filename' => "invoice-{$invoiceId}.pdf",
            'data' => $pdfBase64,
        ]);
    }
}

Build docs developers (and LLMs) love