Improve application quitting.
This commit is contained in:
parent
d7c174daa6
commit
f61b963744
@ -94,8 +94,10 @@ module Cask
|
|||||||
command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
|
command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
|
||||||
sleep 1
|
sleep 1
|
||||||
end
|
end
|
||||||
paths = ["/Library/LaunchAgents/#{service}.plist",
|
paths = [
|
||||||
"/Library/LaunchDaemons/#{service}.plist"]
|
"/Library/LaunchAgents/#{service}.plist",
|
||||||
|
"/Library/LaunchDaemons/#{service}.plist",
|
||||||
|
]
|
||||||
paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo
|
paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo
|
||||||
paths = paths.map { |elt| Pathname(elt) }.select(&:exist?)
|
paths = paths.map { |elt| Pathname(elt) }.select(&:exist?)
|
||||||
paths.each do |path|
|
paths.each do |path|
|
||||||
@ -130,21 +132,52 @@ module Cask
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Quitting application ID '#{bundle_id}'."
|
ohai "Quitting application '#{bundle_id}'..."
|
||||||
command.run!("/usr/bin/osascript", args: ["-e", %Q(tell application id "#{bundle_id}" to quit)], sudo: true)
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Timeout.timeout(3) do
|
Timeout.timeout(10) do
|
||||||
Kernel.loop do
|
Kernel.loop do
|
||||||
break if running_processes(bundle_id, command: command).empty?
|
next unless quit(bundle_id).success?
|
||||||
|
if running_processes(bundle_id, command: command).empty?
|
||||||
|
puts "Application '#{bundle_id}' quit successfully."
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
opoo "Application '#{bundle_id}' did not quit."
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quit(bundle_id)
|
||||||
|
script = <<~JAVASCRIPT
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
ObjC.import('stdlib')
|
||||||
|
|
||||||
|
function run(argv) {
|
||||||
|
var app = Application(argv[0])
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.quit()
|
||||||
|
} catch (err) {
|
||||||
|
if (app.running()) {
|
||||||
|
$.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.exit(0)
|
||||||
|
}
|
||||||
|
JAVASCRIPT
|
||||||
|
|
||||||
|
system_command "osascript", args: ["-l", "JavaScript", "-e", script, bundle_id],
|
||||||
|
print_stderr: false,
|
||||||
|
sudo: true
|
||||||
|
end
|
||||||
|
private :quit
|
||||||
|
|
||||||
# :signal should come after :quit so it can be used as a backup when :quit fails
|
# :signal should come after :quit so it can be used as a backup when :quit fails
|
||||||
def uninstall_signal(*signals, command: nil, **_)
|
def uninstall_signal(*signals, command: nil, **_)
|
||||||
signals.each do |pair|
|
signals.each do |pair|
|
||||||
@ -175,7 +208,7 @@ module Cask
|
|||||||
login_items.each do |name|
|
login_items.each do |name|
|
||||||
ohai "Removing login item #{name}"
|
ohai "Removing login item #{name}"
|
||||||
command.run!(
|
command.run!(
|
||||||
"/usr/bin/osascript",
|
"osascript",
|
||||||
args: [
|
args: [
|
||||||
"-e",
|
"-e",
|
||||||
%Q(tell application "System Events" to delete every login item whose name is "#{name}"),
|
%Q(tell application "System Events" to delete every login item whose name is "#{name}"),
|
||||||
@ -287,7 +320,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
def trash_paths(*paths, command: nil, **_)
|
def trash_paths(*paths, command: nil, **_)
|
||||||
result = command.run!("/usr/bin/osascript", args: ["-e", <<~APPLESCRIPT, *paths])
|
result = command.run!("osascript", args: ["-e", <<~APPLESCRIPT, *paths])
|
||||||
on run argv
|
on run argv
|
||||||
repeat with i from 1 to (count argv)
|
repeat with i from 1 to (count argv)
|
||||||
set item i of argv to (item i of argv as POSIX file)
|
set item i of argv to (item i of argv as POSIX file)
|
||||||
|
|||||||
@ -253,8 +253,7 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
|||||||
|
|
||||||
it "is supported" do
|
it "is supported" do
|
||||||
FakeSystemCommand.expects_command(
|
FakeSystemCommand.expects_command(
|
||||||
["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \
|
["osascript", "-e", 'tell application "System Events" to delete every login item whose name is "Fancy"'],
|
||||||
'item whose name is "Fancy"'],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user