Single instance lock is now functional.
This commit is contained in:
parent
d3d12be208
commit
4df09954fa
1 changed files with 14 additions and 16 deletions
|
@ -144,13 +144,13 @@ module Qasim
|
|||
@context_menu = Qt::Menu.new
|
||||
|
||||
act_pref = Qt::Action.new _('&Preferences'), @context_menu
|
||||
act_pref.setIcon( Qt::Icon::fromTheme("configure") )
|
||||
act_pref.setIcon( Qt::Icon::fromTheme("configure") ) rescue nil
|
||||
act_pref.setIconVisibleInMenu true
|
||||
act_pref.setEnabled false
|
||||
@context_menu.addAction act_pref;
|
||||
|
||||
act_about = Qt::Action.new '&About', @context_menu
|
||||
act_about.setIcon( Qt::Icon::fromTheme("help-about") )
|
||||
act_about.setIcon( Qt::Icon::fromTheme("help-about") ) rescue nil
|
||||
act_about.setIconVisibleInMenu true
|
||||
act_about.setEnabled false
|
||||
@context_menu.addAction act_about;
|
||||
|
@ -158,7 +158,7 @@ module Qasim
|
|||
@context_menu.addSeparator
|
||||
|
||||
act_quit = Qt::Action.new _('Quit'), @context_menu
|
||||
act_quit.setIcon( Qt::Icon::fromTheme("application-exit") )
|
||||
act_quit.setIcon( Qt::Icon::fromTheme("application-exit") ) rescue nil
|
||||
act_quit.setIconVisibleInMenu true
|
||||
act_quit.connect(SIGNAL(:triggered)) { @app.quit }
|
||||
@context_menu.addAction act_quit
|
||||
|
@ -213,24 +213,22 @@ module Qasim
|
|||
# create lock
|
||||
have_lock = true
|
||||
|
||||
lockfname = APP_CONFIG_DIR, "lock"
|
||||
File.open lockfname, "w" do
|
||||
unless f.flock File::LOCK_EX | File::LOCK_NB
|
||||
warn "Another instance of %s is already running." % APP_NAME
|
||||
exit 1
|
||||
end
|
||||
f.flock File::LOCK_EX
|
||||
end
|
||||
|
||||
fd = IO::sysopen('/tmp/tempfile',
|
||||
FileUtils.mkdir_p APP_CONFIG_DIR unless File.exist? APP_CONFIG_DIR
|
||||
lockfname = File.join APP_CONFIG_DIR, "lock"
|
||||
fd = IO::sysopen( lockfname,
|
||||
Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT)
|
||||
f = IO.open(fd)
|
||||
f.syswrite("TEMP DATA")
|
||||
f.syswrite( "Process.pid\n" )
|
||||
f.close
|
||||
masterpid = fh.gets
|
||||
@app.exec
|
||||
rescue Errno::EEXIST => e
|
||||
warn "error: Another instance of %s is already running."
|
||||
exit 1
|
||||
ensure
|
||||
fh.close
|
||||
masterpid = File.read(lockfname).strip
|
||||
if masterpid == Process.pid then
|
||||
FileUtils.rm lockfname
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue