Extend Your Laravel Desktop App with Native Power Tools
When building desktop apps with NativePHP, going beyond basic windows and routes is where the real fun begins. In this article, we’ll explore how to supercharge your Laravel-powered app by working with:
-
✅ Clipboard operations
-
✅ System tray menus
-
✅ Global hotkeys
These native integrations will make your app feel right at home on any desktop OS, enhancing UX and productivity.
📋 1. Using the Clipboard
The clipboard is one of the most powerful yet underused tools in desktop apps. With NativePHP, copying and pasting is just a few lines away.
✂️ Copy to Clipboard
use Native\Laravel\Facades\Clipboard;
Route::get('/copy', function () {
Clipboard::write('Copied from Laravel!');
return 'Text copied!';
});
📥 Read from Clipboard
Route::get('/paste', function () {
return Clipboard::read();
});
🔐 Note: Clipboard access may be restricted by your OS depending on the app’s focus and security settings.
📌 2. Creating a Tray Menu
Tray menus allow users to access app functions from the system tray (next to the clock or taskbar). This is great for apps that run in the background or need quick access.
🔧 Define a Tray Menu
use Native\Laravel\Facades\Tray;
Tray::menu([
Tray::label('NativePHP App'),
Tray::separator(),
Tray::menu('Actions', [
Tray::item('Open App', fn () => Window::open()),
Tray::item('Quit', fn () => app()->quit())
]),
]);
Tray menu items can trigger any Laravel logic — from opening windows to running custom functions or jobs.
🎹 3. Registering Global Hotkeys
Global hotkeys let your app respond to keyboard shortcuts system-wide — even when it's not in focus.
🧠 Set Up a Hotkey
use Native\Laravel\Facades\GlobalShortcut;
GlobalShortcut::register('CommandOrControl+Shift+Y', function () {
Notification::title('Hotkey Triggered!')
->message('You just pressed Ctrl+Shift+Y!')
->show();
});
⛔ Unregister a Hotkey
GlobalShortcut::unregister('CommandOrControl+Shift+Y');
📌 Best Practices:
-
Use non-conflicting key combinations.
-
Always allow users to customize shortcuts when possible.
🧪 Testing It All Together
Combine these features for a productivity tool like a clipboard manager, quick launcher, or note-taker with keyboard controls — all from Laravel!
With Clipboard, Tray Menus, and Global Hotkeys, you're no longer limited to building standard web interfaces. NativePHP opens the door to creating polished, performant, and interactive desktop apps — all with Laravel’s elegance.
0 Comments