You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
was broken because of the AppImage wrapper.
Also, instead of relying on a hacky `pgrep` output, this now works with a lockfile under /tmp. It would be even better to use `fcntl` but it's an annoying api
STDERR.puts "Warning: Could not determine previously running instance because pgrep is not installed. Using SingleInstance OFF."
277
-
return
278
-
end
279
-
already_running = result.to_s.chomp
280
-
.split('\n')
281
-
.select{|p| p!=Process.pid.to_s }
282
-
.first?.try &.to_i?
283
-
returnif! already_running
284
-
case@settings.single_instance
285
-
whenSingleInstance::Force
286
-
Process.signal(Signal::HUP, already_running)
287
-
whenSingleInstance::Ignore
288
-
STDERR.puts "Instance already running and #SingleInstance Ignore passed. Exiting."
289
-
::exit
290
-
whenSingleInstance::Prompt
291
-
response = display.gtk.msgbox "An older instance of this script is already running. Replace it with this instance?\nNote: To avoid this message, see #SingleInstance in the help file.", options:Gtk::MsgBoxOptions::Yes_No.value
292
-
::exit if response !=Gtk::MsgBoxButton::Yes
293
-
Process.signal(Signal::HUP, already_running)
277
+
lock.flock_exclusive(blocking:false)
278
+
rescue e
279
+
already_running_pid = lock.gets_to_end.to_i
280
+
end
281
+
if already_running_pid >-1
282
+
case@settings.single_instance
283
+
whenSingleInstance::Force
284
+
Process.signal(Signal::HUP, already_running_pid)
285
+
whenSingleInstance::Ignore
286
+
STDERR.puts "Instance already running and #SingleInstance Ignore passed. Exiting."
287
+
::exit
288
+
whenSingleInstance::Prompt
289
+
response = display.gtk.msgbox "An older instance of this script is already running. Replace it with this instance?\nNote: To avoid this message, see #SingleInstance in the help file.", options:Gtk::MsgBoxOptions::Yes_No.value
290
+
::exit if response !=Gtk::MsgBoxButton::Yes
291
+
Process.signal(Signal::HUP, already_running_pid)
292
+
end
293
+
start =Time.monotonic
294
+
whileProcess.exists?(already_running_pid)
295
+
ifTime.monotonic - start >1.second
296
+
raise"Failed to kill previous instance process with PID #{already_running_pid}"
0 commit comments