Class: SharedTools::Tools::Notification::LinuxDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- SharedTools::Tools::Notification::LinuxDriver
- Defined in:
- lib/shared_tools/tools/notification/linux_driver.rb
Overview
Linux notification driver.
notify — uses notify-send (libnotify); logs a warning if no display is available. alert — uses zenity when a display is present; falls back to a terminal prompt. speak — tries espeak-ng first, then espeak.
Instance Method Summary collapse
-
#alert(message:, title: nil, buttons: ['OK'], default_button: nil) ⇒ Hash
Includes :button with the label of the clicked button.
- #notify(message:, title: nil, subtitle: nil, sound: nil) ⇒ Hash
- #speak(text:, voice: nil, rate: nil) ⇒ Hash
Instance Method Details
#alert(message:, title: nil, buttons: ['OK'], default_button: nil) ⇒ Hash
Returns includes :button with the label of the clicked button.
40 41 42 43 44 45 46 |
# File 'lib/shared_tools/tools/notification/linux_driver.rb', line 40 def alert(message:, title: nil, buttons: ['OK'], default_button: nil) if display_available? && command_available?('zenity') alert_zenity(message:, title:, buttons:, default_button:) else alert_terminal(message:, buttons:, default_button:) end end |
#notify(message:, title: nil, subtitle: nil, sound: nil) ⇒ Hash
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/shared_tools/tools/notification/linux_driver.rb', line 19 def notify(message:, title: nil, subtitle: nil, sound: nil) unless display_available? RubyLLM.logger.warn('NotificationTool: No display server available, cannot show notification') return { success: false, error: 'No display server available' } end unless command_available?('notify-send') return { success: false, error: 'notify-send not found. Install libnotify-bin (Debian/Ubuntu) or libnotify (Fedora/Arch).' } end body = [, subtitle].compact.join("\n") cmd = ['notify-send', (title || 'Notification'), body] _, stderr, status = Open3.capture3(*cmd) status.success? ? { success: true, action: 'notify' } : { success: false, error: stderr.strip } end |
#speak(text:, voice: nil, rate: nil) ⇒ Hash
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/shared_tools/tools/notification/linux_driver.rb', line 52 def speak(text:, voice: nil, rate: nil) binary = espeak_binary unless binary return { success: false, error: 'espeak-ng or espeak not found. Install espeak-ng (recommended) or espeak.' } end cmd = [binary, text] cmd += ['-v', voice] if voice cmd += ['-s', rate.to_s] if rate _, stderr, status = Open3.capture3(*cmd) status.success? ? { success: true, action: 'speak' } : { success: false, error: stderr.strip } end |