ruby-macrodroid 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +131 -28
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d741e63df502364d934438221160e20d967303ec5c79923924e7c978175f44d
|
4
|
+
data.tar.gz: 9b0e372bb0cfc60ddcd553355bc30dbb90cdd303904c93556a8f16ef87fb2432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c3507258eade1847ea92c63912f930db4c3843e36beec011e9b9fbaf5fbbc47ea9d8778aaaf7b43be9486ce63875116433065a007dd6956112128c1d96aa0f
|
7
|
+
data.tar.gz: dff690f4ce9ebb274cc22f99c95f18981ab05136597a2b0c0eabdf9fa6848c004d2003b653b280da147302aec651731952b8d3c5077222bfc625d4e3819b0008
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
require 'pp'
|
6
6
|
require 'json'
|
7
7
|
require 'uuid'
|
8
|
+
require 'date'
|
8
9
|
require 'rxfhelper'
|
9
10
|
|
10
11
|
|
@@ -66,10 +67,11 @@ class Macro
|
|
66
67
|
using Params
|
67
68
|
|
68
69
|
attr_reader :local_variables, :triggers, :actions, :guid
|
70
|
+
attr_accessor :name
|
69
71
|
|
70
|
-
def initialize(debug: false)
|
72
|
+
def initialize(name=nil, debug: false)
|
71
73
|
|
72
|
-
@debug = debug
|
74
|
+
@name, @debug = name, debug
|
73
75
|
lv=[], triggers=[], actions=[]
|
74
76
|
@local_variables, @triggers, @actions = lv, triggers, actions
|
75
77
|
|
@@ -105,7 +107,15 @@ class Macro
|
|
105
107
|
local_variables: @local_variables,
|
106
108
|
m_trigger_list: @triggers.map(&:to_h),
|
107
109
|
m_action_list: @actions.map(&:to_h),
|
108
|
-
m_constraint_list: []
|
110
|
+
m_constraint_list: [],
|
111
|
+
m_description: '',
|
112
|
+
m_name: @name,
|
113
|
+
m_excludeLog: false,
|
114
|
+
m_GUID: guid(),
|
115
|
+
m_isOrCondition: false,
|
116
|
+
m_enabled: false,
|
117
|
+
m_descriptionOpen: false,
|
118
|
+
m_headingColor: 0
|
109
119
|
}
|
110
120
|
|
111
121
|
puts 'h: ' + h.inspect if @debug
|
@@ -140,8 +150,43 @@ class Macro
|
|
140
150
|
@h
|
141
151
|
|
142
152
|
end
|
153
|
+
|
154
|
+
def import_xml(node)
|
155
|
+
|
156
|
+
@name = node.attributes[:name]
|
157
|
+
|
158
|
+
# get all the triggers
|
159
|
+
@triggers = node.xpath('triggers/*').map do |e|
|
160
|
+
|
161
|
+
puts 'e.name: ' + e.name.inspect if @debug
|
162
|
+
{timer: TimerTrigger}[e.name.to_sym].new(e.attributes.to_h)
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
# get all the actions
|
167
|
+
@actions = node.xpath('actions/*').map do |e|
|
168
|
+
|
169
|
+
if e.name == 'notification' then
|
170
|
+
|
171
|
+
case e.attributes[:type].to_sym
|
172
|
+
when :popup
|
173
|
+
e.attributes.delete :type
|
174
|
+
ToastAction.new e.attributes.to_h
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
self
|
182
|
+
|
183
|
+
end
|
143
184
|
|
144
185
|
private
|
186
|
+
|
187
|
+
def guid()
|
188
|
+
'-' + rand(1..9).to_s + 18.times.map { rand 9 }.join
|
189
|
+
end
|
145
190
|
|
146
191
|
def object(h={})
|
147
192
|
|
@@ -166,33 +211,18 @@ class MacroDroid
|
|
166
211
|
if obj then
|
167
212
|
|
168
213
|
s, _ = RXFHelper.read(obj)
|
169
|
-
|
214
|
+
|
215
|
+
if s[0] == '{' then
|
216
|
+
import_json(s)
|
217
|
+
else
|
218
|
+
s[0] == '<'
|
219
|
+
import_xml(s)
|
220
|
+
@h = build_h
|
221
|
+
end
|
170
222
|
|
171
223
|
else
|
172
224
|
|
173
|
-
@h =
|
174
|
-
cell_tower_groups: [],
|
175
|
-
cell_towers_ignore: [],
|
176
|
-
drawer_configuration: {
|
177
|
-
drawer_items: [],
|
178
|
-
background_color: -1,
|
179
|
-
header_color: 12692882,
|
180
|
-
left_side: false,
|
181
|
-
swipe_area_color: -7829368,
|
182
|
-
swipe_area_height: 20,
|
183
|
-
swipe_area_offset: 40,
|
184
|
-
swipe_area_opacity: 80,
|
185
|
-
swipe_area_width: 14,
|
186
|
-
visible_swipe_area_width: 0
|
187
|
-
},
|
188
|
-
variables: [],
|
189
|
-
user_icons: [],
|
190
|
-
geofence_data: {
|
191
|
-
geofence_map: {}
|
192
|
-
},
|
193
|
-
macro_list: []
|
194
|
-
|
195
|
-
}
|
225
|
+
@h = build_h()
|
196
226
|
|
197
227
|
@macros = []
|
198
228
|
|
@@ -203,6 +233,33 @@ class MacroDroid
|
|
203
233
|
@macros << macro
|
204
234
|
end
|
205
235
|
|
236
|
+
def build_h()
|
237
|
+
|
238
|
+
{
|
239
|
+
cell_tower_groups: [],
|
240
|
+
cell_towers_ignore: [],
|
241
|
+
drawer_configuration: {
|
242
|
+
drawer_items: [],
|
243
|
+
background_color: -1,
|
244
|
+
header_color: 12692882,
|
245
|
+
left_side: false,
|
246
|
+
swipe_area_color: -7829368,
|
247
|
+
swipe_area_height: 20,
|
248
|
+
swipe_area_offset: 40,
|
249
|
+
swipe_area_opacity: 80,
|
250
|
+
swipe_area_width: 14,
|
251
|
+
visible_swipe_area_width: 0
|
252
|
+
},
|
253
|
+
variables: [],
|
254
|
+
user_icons: [],
|
255
|
+
geofence_data: {
|
256
|
+
geofence_map: {}
|
257
|
+
},
|
258
|
+
macro_list: []
|
259
|
+
|
260
|
+
}
|
261
|
+
end
|
262
|
+
|
206
263
|
def export_json()
|
207
264
|
|
208
265
|
to_h.to_json
|
@@ -226,6 +283,23 @@ class MacroDroid
|
|
226
283
|
end
|
227
284
|
|
228
285
|
@h[:macro_list] = []
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
def import_xml(raws)
|
290
|
+
|
291
|
+
s = RXFHelper.read(raws).first
|
292
|
+
puts 's: ' + s.inspect if @debug
|
293
|
+
doc = Rexle.new(s)
|
294
|
+
puts 'after doc' if @debug
|
295
|
+
|
296
|
+
@macros = doc.root.xpath('macro').map do |node|
|
297
|
+
|
298
|
+
macro = Macro.new @name
|
299
|
+
macro.import_xml(node)
|
300
|
+
macro
|
301
|
+
|
302
|
+
end
|
229
303
|
end
|
230
304
|
|
231
305
|
def to_h()
|
@@ -647,6 +721,31 @@ end
|
|
647
721
|
class TimerTrigger < Trigger
|
648
722
|
|
649
723
|
def initialize(h={})
|
724
|
+
|
725
|
+
if h[:days] then
|
726
|
+
|
727
|
+
days = [false] * 7
|
728
|
+
|
729
|
+
h[:days].split(/, +/).each do |x|
|
730
|
+
|
731
|
+
r = Date::DAYNAMES.grep /#{x}/i
|
732
|
+
i = Date::DAYNAMES.index(r.first)
|
733
|
+
days[i-1] = true
|
734
|
+
|
735
|
+
end
|
736
|
+
|
737
|
+
h[:days_of_week] = days
|
738
|
+
h.delete :days
|
739
|
+
|
740
|
+
end
|
741
|
+
|
742
|
+
if h[:time] then
|
743
|
+
|
744
|
+
t = Time.parse(h[:time])
|
745
|
+
h[:hour], h[:minute] = t.hour, t.min
|
746
|
+
h.delete :time
|
747
|
+
|
748
|
+
end
|
650
749
|
|
651
750
|
options = {
|
652
751
|
alarm_id: uuid(),
|
@@ -2041,6 +2140,11 @@ class ToastAction < Action
|
|
2041
2140
|
|
2042
2141
|
def initialize(h={})
|
2043
2142
|
|
2143
|
+
if h[:msg] then
|
2144
|
+
h[:message_text] = h[:msg]
|
2145
|
+
h.delete :msg
|
2146
|
+
end
|
2147
|
+
|
2044
2148
|
options = {
|
2045
2149
|
message_text: '',
|
2046
2150
|
image_resource_name: 'launcher_no_border',
|
@@ -2299,7 +2403,6 @@ class SpeakerPhoneAction < Action
|
|
2299
2403
|
end
|
2300
2404
|
|
2301
2405
|
|
2302
|
-
|
2303
2406
|
class SetVolumeAction < Action
|
2304
2407
|
|
2305
2408
|
def initialize(h={})
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|