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
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
A user-friendly message explaining why authentication is needed.
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
Returns true if encryption is available, false otherwise.
encrypt()
Encrypt a string using the system’s encryption capabilities.
System::encrypt(string $string): ?string
The plain text string to encrypt.
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
The encrypted string to decrypt.
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>
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
The HTML content to print.
The printer to use. If not specified, uses the system default printer.
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
The HTML content to convert to PDF.
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));
timezone()
Get the system’s current timezone.
System::timezone(): 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
The theme to set. Options:
SystemThemesEnum::LIGHT
SystemThemesEnum::DARK
SystemThemesEnum::SYSTEM
If omitted, gets the current theme.
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,
]);
}
}