Remove User::automation_access?.

This commit is contained in:
Markus Reiter 2019-10-22 05:34:39 +02:00
parent 0a175c4feb
commit 7a5e4d1269
3 changed files with 13 additions and 46 deletions

View File

@ -124,6 +124,11 @@ module Cask
end
end
def automation_access_instructions
"Enable Automation Access for “Terminal > System Events” in " \
"“System Preferences > Security > Privacy > Automation” if you haven't already."
end
# :quit/:signal must come before :kext so the kext will not be in use by a running process
def uninstall_quit(*bundle_ids, command: nil, **_)
bundle_ids.each do |bundle_id|
@ -134,11 +139,6 @@ module Cask
next
end
unless User.automation_access?
opoo "Skipping quitting application ID '#{bundle_id}'. #{User.automation_access_instructions}"
next
end
ohai "Quitting application '#{bundle_id}'..."
begin
@ -153,8 +153,7 @@ module Cask
end
end
rescue Timeout::Error
opoo "Application '#{bundle_id}' did not quit."
next
opoo "Application '#{bundle_id}' did not quit. #{automation_access_instructions}"
end
end
end
@ -242,19 +241,18 @@ module Cask
["name", item]
end
unless User.automation_access?
opoo "Skipping removal of login item #{id}. #{User.automation_access_instructions}"
next
end
ohai "Removing login item #{id}"
system_command!(
result = system_command(
"osascript",
args: [
"-e",
%Q(tell application "System Events" to delete every login item whose #{type} is #{id.to_s.inspect}),
],
)
opoo "Removal of login item #{id} failed. #{automation_access_instructions}" unless result.success?
sleep 1
end
end

View File

@ -116,16 +116,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-quit")) }
let(:bundle_id) { "my.fancy.package.app" }
it "is skipped when the user does not have automation access" do
allow(User).to receive(:automation_access?).and_return false
allow(User.current).to receive(:gui?).and_return true
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
expect {
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
}.to output(/Skipping quitting application ID 'my.fancy.package.app'\./).to_stderr
end
it "is skipped when the user is not a GUI user" do
allow(User.current).to receive(:gui?).and_return false
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
@ -136,7 +126,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
end
it "quits a running application" do
allow(User).to receive(:automation_access?).and_return true
allow(User.current).to receive(:gui?).and_return true
expect(subject).to receive(:running?).with(bundle_id).ordered.and_return(true)
@ -150,7 +139,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
end
it "tries to quit the application for 10 seconds" do
allow(User).to receive(:automation_access?).and_return true
allow(User.current).to receive(:gui?).and_return true
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
@ -257,14 +245,12 @@ shared_examples "#uninstall_phase or #zap_phase" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-login-item")) }
it "is supported" do
allow(User).to receive(:automation_access?).and_return true
expect(subject).to receive(:system_command!)
expect(subject).to receive(:system_command)
.with(
"osascript",
args: ["-e", 'tell application "System Events" to delete every login item whose name is "Fancy"'],
)
.and_return(instance_double("SystemCommand::Result"))
.and_return(instance_double("SystemCommand::Result", success?: true))
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
end

View File

@ -6,23 +6,6 @@ require "etc"
require "system_command"
class User < DelegateClass(String)
def self.automation_access?
return @automation_access if defined?(@automation_access)
*_, status = system_command "osascript", args: [
"-e", "with timeout of 0.5 seconds",
"-e", 'tell application "System Events" to get volume settings',
"-e", "end timeout"
], print_stderr: false
@automation_access = status.success?
end
def self.automation_access_instructions
"Enable Automation Access for “Terminal > System Events” in " \
"“System Preferences > Security > Privacy > Automation”."
end
def gui?
out, _, status = system_command "who"
return false unless status.success?