Add option to disable the exit button and action

This commit is contained in:
Julien Kirch 2013-05-13 13:27:06 +02:00
parent e19a2096b0
commit 6ce4dda354
4 changed files with 20 additions and 4 deletions

View File

@ -33,6 +33,10 @@ OptionParser.new do |parser|
options[:from] = from options[:from] = from
end end
parser.on('-x', '--no-exit', 'Can\'t exit from the application') do
options[:no_exit] = true
end
parser.on('-h', '--help', 'Display this help information') do parser.on('-h', '--help', 'Display this help information') do
puts parser puts parser
exit! exit!

View File

@ -55,6 +55,7 @@ module MailCatcher extend self
:daemon => !windows?, :daemon => !windows?,
:growl => growlnotify?, :growl => growlnotify?,
:browse => false, :browse => false,
:no_exit => false,
} }
def parse! arguments=ARGV, defaults=@defaults def parse! arguments=ARGV, defaults=@defaults
@ -83,6 +84,10 @@ module MailCatcher extend self
options[:http_port] = port options[:http_port] = port
end end
parser.on("--no-exit", "Can't exit from the application'") do
options[:no_exit] = true
end
if mac? if mac?
parser.on("--[no-]growl", "Growl to the local machine when a message arrives") do |growl| parser.on("--[no-]growl", "Growl to the local machine when a message arrives") do |growl|
if growl and not growlnotify? if growl and not growlnotify?
@ -128,6 +133,10 @@ module MailCatcher extend self
puts "Starting MailCatcher" puts "Starting MailCatcher"
define_method :no_exit do
options[:no_exit]
end
Thin::Logging.silent = true Thin::Logging.silent = true
# One EventMachine loop... # One EventMachine loop...

View File

@ -18,8 +18,10 @@ class MailCatcher::Web < Sinatra::Base
end end
delete '/' do delete '/' do
MailCatcher.quit! unless MailCatcher.no_exit
status 204 MailCatcher.quit!
status 204
end
end end
get '/messages' do get '/messages' do

View File

@ -21,8 +21,9 @@
%input{:type => 'search', :name => 'search', :placeholder => 'Search messages...', :incremental => true} %input{:type => 'search', :name => 'search', :placeholder => 'Search messages...', :incremental => true}
%li.clear %li.clear
%a{:href => '#', :title => 'Clear all messages'} Clear %a{:href => '#', :title => 'Clear all messages'} Clear
%li.quit - unless MailCatcher.no_exit
%a{:href => '#', :title => 'Quit MailCatcher'} Quit %li.quit
%a{:href => '#', :title => 'Quit MailCatcher'} Quit
%nav#messages %nav#messages
%table %table
%thead %thead