Merge pull request #6628 from reitermarkus/automation-access
Remove `User::automation_access?`.
This commit is contained in:
commit
299bb1c25f
@ -124,6 +124,11 @@ module Cask
|
|||||||
end
|
end
|
||||||
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
|
# :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, **_)
|
def uninstall_quit(*bundle_ids, command: nil, **_)
|
||||||
bundle_ids.each do |bundle_id|
|
bundle_ids.each do |bundle_id|
|
||||||
@ -134,11 +139,6 @@ module Cask
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
unless User.automation_access?
|
|
||||||
opoo "Skipping quitting application ID '#{bundle_id}'. #{User.automation_access_instructions}"
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
ohai "Quitting application '#{bundle_id}'..."
|
ohai "Quitting application '#{bundle_id}'..."
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -153,8 +153,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
opoo "Application '#{bundle_id}' did not quit."
|
opoo "Application '#{bundle_id}' did not quit. #{automation_access_instructions}"
|
||||||
next
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -242,19 +241,18 @@ module Cask
|
|||||||
["name", item]
|
["name", item]
|
||||||
end
|
end
|
||||||
|
|
||||||
unless User.automation_access?
|
|
||||||
opoo "Skipping removal of login item #{id}. #{User.automation_access_instructions}"
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
ohai "Removing login item #{id}"
|
ohai "Removing login item #{id}"
|
||||||
system_command!(
|
|
||||||
|
result = system_command(
|
||||||
"osascript",
|
"osascript",
|
||||||
args: [
|
args: [
|
||||||
"-e",
|
"-e",
|
||||||
%Q(tell application "System Events" to delete every login item whose #{type} is #{id.to_s.inspect}),
|
%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
|
sleep 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-quit")) }
|
||||||
let(:bundle_id) { "my.fancy.package.app" }
|
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
|
it "is skipped when the user is not a GUI user" do
|
||||||
allow(User.current).to receive(:gui?).and_return false
|
allow(User.current).to receive(:gui?).and_return false
|
||||||
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
|
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
|
||||||
@ -136,7 +126,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "quits a running application" do
|
it "quits a running application" do
|
||||||
allow(User).to receive(:automation_access?).and_return true
|
|
||||||
allow(User.current).to receive(:gui?).and_return true
|
allow(User.current).to receive(:gui?).and_return true
|
||||||
|
|
||||||
expect(subject).to receive(:running?).with(bundle_id).ordered.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
|
end
|
||||||
|
|
||||||
it "tries to quit the application for 10 seconds" do
|
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(User.current).to receive(:gui?).and_return true
|
||||||
|
|
||||||
allow(subject).to receive(:running?).with(bundle_id).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")) }
|
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-login-item")) }
|
||||||
|
|
||||||
it "is supported" do
|
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(
|
.with(
|
||||||
"osascript",
|
"osascript",
|
||||||
args: ["-e", 'tell application "System Events" to delete every login item whose name is "Fancy"'],
|
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)
|
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,23 +6,6 @@ require "etc"
|
|||||||
require "system_command"
|
require "system_command"
|
||||||
|
|
||||||
class User < DelegateClass(String)
|
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?
|
def gui?
|
||||||
out, _, status = system_command "who"
|
out, _, status = system_command "who"
|
||||||
return false unless status.success?
|
return false unless status.success?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user