@@ -22,7 +22,6 @@ def autolocate!
22
22
end
23
23
24
24
attr_accessor :installation
25
- attr_reader :prefs_cache
26
25
attr_reader :prefs_response_time
27
26
attr_reader :library_is_indexed
28
27
@@ -31,26 +30,47 @@ def initialize(installation)
31
30
@display_mgr = DisplayManager ::instance
32
31
@installation = installation
33
32
@prefs_response_time = nil
34
- @prefs_cache = prefs
33
+ @prefs_cache = nil
35
34
@library_is_indexed = false
36
35
end
37
36
37
+ def _parse_pref_string ( arduino_output )
38
+ lines = arduino_output . split ( "\n " ) . select { |l | l . include? "=" }
39
+ ret = lines . each_with_object ( { } ) do |e , acc |
40
+ parts = e . split ( "=" , 2 )
41
+ acc [ parts [ 0 ] ] = parts [ 1 ]
42
+ acc
43
+ end
44
+ ret
45
+ end
46
+
38
47
# fetch preferences to a hash
39
- def prefs
48
+ def _prefs
40
49
resp = nil
41
- @display_mgr . with_display do
50
+ if @installation . requires_x
51
+ @display_mgr . with_display do
52
+ start = Time . now
53
+ resp = run_and_capture ( "--get-pref" )
54
+ @prefs_response_time = Time . now - start
55
+ end
56
+ else
42
57
start = Time . now
43
58
resp = run_and_capture ( "--get-pref" )
44
59
@prefs_response_time = Time . now - start
45
60
end
46
61
return nil unless resp [ :success ]
47
- lines = resp [ :out ] . split ( "\n " ) . select { |l | l . include? "=" }
48
- ret = lines . each_with_object ( { } ) do |e , acc |
49
- parts = e . split ( "=" , 2 )
50
- acc [ parts [ 0 ] ] = parts [ 1 ]
51
- acc
52
- end
53
- ret
62
+ _parse_pref_string ( resp [ :out ] )
63
+ end
64
+
65
+ def prefs
66
+ @prefs_cache = _prefs if @prefs_cache . nil?
67
+ @prefs_cache . clone
68
+ end
69
+
70
+ # get a preference key
71
+ def get_pref ( key )
72
+ data = @prefs_cache . nil? ? prefs : @prefs_cache
73
+ data [ key ]
54
74
end
55
75
56
76
# set a preference key/value pair
@@ -66,12 +86,21 @@ def set_pref(key, value)
66
86
# run the arduino command
67
87
def run ( *args , **kwargs )
68
88
full_args = [ @installation . cmd_path ] + args
69
- @display_mgr . run ( *full_args , **kwargs )
89
+ if @installation . requires_x
90
+ @display_mgr . run ( *full_args , **kwargs )
91
+ else
92
+ Host . run ( *full_args , **kwargs )
93
+ end
70
94
end
71
95
72
96
def run_with_gui_guess ( message , *args , **kwargs )
73
97
# On Travis CI, we get an error message in the GUI instead of on STDERR
74
98
# so, assume that if we don't get a rapid reply that things are not installed
99
+
100
+ # if we don't need X, we can skip this whole thing
101
+ return run_and_capture ( *args , **kwargs ) unless @installation . requires_x
102
+
103
+ prefs if @prefs_response_time . nil?
75
104
x3 = @prefs_response_time * 3
76
105
Timeout . timeout ( x3 ) do
77
106
result = run_and_capture ( *args , **kwargs )
0 commit comments