Class: Pikuri::Thunderbird::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pikuri/thunderbird/launcher.rb

Overview

Detached launch of the user's Thunderbird — the shared mechanism behind both v2 outbound tools. Given an argument Thunderbird understands on its command line (a mailto: URI for MailCompose, an .ics path for CalendarCreate), it opens it in the running instance:

Launcher.new.launch('mailto:a@x.com?body=hi')   # compose window
Launcher.new.launch('/…/pikuri-outbox/x.ics')   # import wizard

It never sends or imports anything itself — the argument only opens a window/wizard the human reviews and commits, which is the no-send seam.

Why detached (+setsid --fork+)

The launch is setsid --fork thunderbird <arg>, putting Thunderbird in its own session. Load-bearing two ways, both silent under test: (1) closing the agent must never SIGTERM the user's running Thunderbird — the Subprocess exit-sweep would, but the detached grandchild is out of our process group; (2) when Thunderbird isn't already running, a foreground launch would block the calling tool on the GUI. Don't drop the detach.

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(thunderbird_bin: 'thunderbird', spawn: nil) ⇒ Launcher

Parameters:

  • thunderbird_bin (String) (defaults to: 'thunderbird')

    the Thunderbird executable — a PATH name (default "thunderbird") or an absolute path.

  • spawn (#call, nil) (defaults to: nil)

    test seam — a callable given the argument that returns a Subprocess result (responds to #status / #output). nil uses the real detached spawn.



35
36
37
38
# File 'lib/pikuri/thunderbird/launcher.rb', line 35

def initialize(thunderbird_bin: 'thunderbird', spawn: nil)
  @thunderbird_bin = thunderbird_bin
  @spawn = spawn || method(:detached_spawn)
end

Instance Method Details

#launch(arg) ⇒ void

This method returns an undefined value.

Launch Thunderbird on arg.

Parameters:

  • arg (String)

    a mailto: URI or a filesystem path.

Raises:

  • (Error)

    if the binary is missing or the spawn fails.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pikuri/thunderbird/launcher.rb', line 45

def launch(arg)
  unless resolvable?(@thunderbird_bin)
    raise Error, "Thunderbird executable #{@thunderbird_bin.inspect} not found — " \
                 'set thunderbird_bin: to its path.'
  end

  result = @spawn.call(arg)
  return if result.status.success?

  raise Error, "couldn't hand off to Thunderbird (#{result.output.strip.slice(0, 200)})."
end