AXElements 1.0.0.alpha4 → 1.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,6 @@ module Accessibility::Enumerators
25
25
  kids.each do |x| yield x end
26
26
  queue.concat kids
27
27
  end
28
- []
29
28
  end
30
29
 
31
30
  ##
@@ -4,7 +4,7 @@
4
4
  # The main AXElements namespace.
5
5
  module Accessibility
6
6
  # @return [String]
7
- VERSION = '1.0.0.alpha4'
7
+ VERSION = '1.0.0.alpha5'
8
8
 
9
9
  # @return [String]
10
10
  CODE_NAME = 'ルナトーン'
data/lib/accessibility.rb CHANGED
@@ -102,7 +102,7 @@ class << Accessibility
102
102
  # @return [AX::Application]
103
103
  def try_wrapping bundle
104
104
  AX::Application.new bundle
105
- rescue RuntimeError => e
105
+ rescue RuntimeError
106
106
  nil
107
107
  end
108
108
 
@@ -11,12 +11,53 @@ require 'accessibility/string'
11
11
  class AX::Application < AX::Element
12
12
  include Accessibility::String
13
13
 
14
+ class << self
15
+ ##
16
+ # Asynchronously launch an application with given the bundle identifier
17
+ #
18
+ # @param bundle [String] bundle identifier for the app
19
+ # @return [Boolean]
20
+ def launch bundle
21
+ NSWorkspace.sharedWorkspace.launchAppWithBundleIdentifier bundle,
22
+ options: NSWorkspaceLaunchAsync,
23
+ additionalEventParamDescriptor: nil,
24
+ launchIdentifier: nil
25
+ end
26
+ end
27
+
14
28
  ##
29
+ # Standard way of creating a new application object
30
+ #
15
31
  # You can initialize an application object with either the process
16
32
  # identifier (pid) of the application, the name of the application,
17
33
  # an `NSRunningApplication` instance for the application, or an
18
34
  # accessibility (`AXUIElementRef`) token.
19
35
  #
36
+ # Given a PID, we try to lookup the application and wrap it.
37
+ #
38
+ # Given an `NSRunningApplication` instance, we simply wrap it.
39
+ #
40
+ # Given a string we do some complicated magic to try and figure out if
41
+ # the string is a bundle identifier or the localized name of the
42
+ # application. Given a bundle identifier we try to launch the app if
43
+ # it is not already running, given a localized name we search the running
44
+ # applications for the app. We wrap what we get back if we get anything
45
+ # back.
46
+ #
47
+ # Note however, given a bundle identifier to launch the application our
48
+ # implementation is a bit of a hack; I've tried to register for
49
+ # notifications, launch synchronously, etc., but there is always a problem
50
+ # with accessibility not being ready right away, so we will poll the app
51
+ # to see when it is ready with a timeout of ~10 seconds.
52
+ #
53
+ # If this method fails to find an app then an exception will be raised.
54
+ #
55
+ # @example
56
+ #
57
+ # AX::Application.new 'com.apple.mail'
58
+ # AX::Application.new 'Mail'
59
+ # AX::Application.new 43567
60
+ #
20
61
  # @param arg [Number,String,NSRunningApplication]
21
62
  def initialize arg
22
63
  case arg
@@ -24,14 +65,29 @@ class AX::Application < AX::Element
24
65
  super Accessibility::Element.application_for arg
25
66
  @app = NSRunningApplication.runningApplicationWithProcessIdentifier arg
26
67
  when String
27
- @app =
28
- NSRunningApplication.runningApplicationsWithBundleIdentifier(arg).first ||
29
- (
30
- spin_run_loop
31
- NSWorkspace.sharedWorkspace.runningApplications.find { |app|
32
- app.localizedName == arg
33
- }
68
+ until @app
69
+ @app =
70
+ (
71
+ app = NSRunningApplication.runningApplicationsWithBundleIdentifier arg
72
+ app.first
73
+
74
+ ) || (
75
+ spin_run_loop
76
+ NSWorkspace.sharedWorkspace.runningApplications.find { |app|
77
+ app.localizedName == arg
78
+ }
79
+
80
+ ) || (
81
+ count ||= 0
82
+ if AX::Application.launch arg
83
+ sleep 1
84
+ count += 1
85
+ raise "#{arg} failed to launch in time" if count == 10
86
+ else
87
+ raise "#{arg} is not a registered bundle identifier for the system"
88
+ end
34
89
  )
90
+ end
35
91
  super Accessibility::Element.application_for @app.processIdentifier
36
92
  when NSRunningApplication
37
93
  super Accessibility::Element.application_for arg.processIdentifier
@@ -199,6 +199,19 @@ class TestAccessibilityDSL < MiniTest::Unit::TestCase
199
199
  app.main_window.set :position, orig_window_position if orig_window_position
200
200
  end
201
201
 
202
+ def dummy_text
203
+ 'Lorem ipsum dolor. Sit amet orci feugiat facilisis quis neque con quisque vestibulum condimentum nec velit laoreet eget. Dolor felis quis. Nulla mi urna ligula porta blandit tenetur et velit habitant rerum numquam. Erat ut eget.'
204
+ end
205
+
206
+ def test_triple_click
207
+ text_area.set :value, dummy_text
208
+ dsl.click text_area
209
+ dsl.triple_click text_area
210
+ assert_equal dummy_text, text_area.selected_text
211
+ ensure
212
+ app.main_window.text_area.set :value, ''
213
+ end
214
+
202
215
  def test_highlight
203
216
  highlighter = dsl.highlight app.main_window, colour: NSColor.blueColor
204
217
  assert_kind_of Accessibility::Highlighter, highlighter
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: AXElements
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.alpha4
5
+ version: 1.0.0.alpha5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Rada
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-27 00:00:00 Z
12
+ date: 2012-11-28 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest