Module: DockDriver

Extended by:
Configurability, Loggability
Defined in:
lib/dock_driver.rb,
lib/dock_driver/i3.rb,
lib/dock_driver/dock.rb,
lib/dock_driver/template.rb,
lib/dock_driver/constants.rb,
lib/dock_driver/dock_item.rb,
lib/dock_driver/workspace_pager.rb

Overview

A namespace for the project & singleton for driving the dock.

Defined Under Namespace

Classes: Dock, DockItem, I3, Template, WorkspacePager

Constant Summary collapse

VERSION =

Project version.

'0.3.4'
REVISION =

Project revision.

%$Revision: 842a417fe636 $
USER_CONFIG_FILE =

The default location of a user’s config file.

Pathname( '~/.dock_driver.yml' ).expand_path
USER_PID_FILE =

The default location for the PID file.

Pathname( '~/.dock_driver.pid' ).expand_path
DATADIR =

The path to the data directory for the musl gem.

begin
    dir = Gem.datadir('dock_driver') ||
          Pathname( __FILE__ ).dirname.parent.parent + 'data/dock_driver'
    Pathname( dir )
end
EXAMPLE_CONFIG_FILE =

The location of the example config.

Pathname( 
DATADIR + 'example.dock_driver.yml' ).expand_path

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dockObject (readonly)

The DockDriver::Dock instance for the app.



31
32
33
# File 'lib/dock_driver.rb', line 31

def dock
  @dock
end

.loaded_configObject

The loaded config.



37
38
39
# File 'lib/dock_driver.rb', line 37

def loaded_config
  @loaded_config
end

.pagerObject (readonly)

The DockDriver::WorkspacePager instance for the app.



34
35
36
# File 'lib/dock_driver.rb', line 34

def pager
  @pager
end

.pid_fileObject

The user’s PID file.



40
41
42
# File 'lib/dock_driver.rb', line 40

def pid_file
  @pid_file
end

Class Method Details

.killObject

Gracefully shut down the dock.



101
102
103
104
105
# File 'lib/dock_driver.rb', line 101

def self::kill
    self.pager.thread.kill
    self.dock.kill
    FileUtils.rm_f self.pid_file
end

.restartObject

Restart the dock.



91
92
93
94
95
96
97
98
# File 'lib/dock_driver.rb', line 91

def self::restart
    return unless self.loaded_config
    self.log.debug "Restarting."
    self.loaded_config.reload
    self.dock.restart
rescue Exception => e
    self.log.warn "There was a problem with your config: %s" % [e.message]
end

.run(opts) ⇒ Object

Watch the config; initate a restart if it has been touched.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dock_driver.rb', line 44

def self::run( opts )

    # Manage a PID file.
    self.pid_file = opts[:pid_file] || USER_PID_FILE
    begin
        found_pid = File.read( self.pid_file ).to_i
        self.log.error "The dock appears to be running. Please " + 
            "remove the PID file and kill the process if necessary."
        self.log.error "PID: %s File: %s" %
            [found_pid == 0 ? "Not found." : found_pid, self.pid_file]
        exit
    rescue Errno::ENOENT
    end
    File.write( self.pid_file, Process.pid )
    
    # Load up the config.
    begin
        self.loaded_config = Configurability::Config.load( opts[:config] )
        self.loaded_config.install
    rescue Exception => e
        self.log.error "I couldn't load your config: %s" % [e.message]
        return
    end

    # Start up the dock for the first time.
    self.dock.run
    self.pager.thread.run
    self.pager.add_observer dock

    loop do

        # Check for config updates
        if self.loaded_config.changed?
            self.log.debug "Config changed."
            self.restart
        end

        # Update the dock at once per second so that if the template
        # includes a time with seconds it gets updated as expected.
        sleep 1
        self.dock.update

    end

end