ruby-macrodroid 0.8.8 → 0.9.0
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 +2 -2
- data/lib/ruby-macrodroid.rb +65 -501
- data/lib/ruby-macrodroid/actions.rb +176 -60
- data/lib/ruby-macrodroid/base.rb +18 -4
- data/lib/ruby-macrodroid/constraints.rb +1338 -0
- data/lib/ruby-macrodroid/macro.rb +630 -0
- data/lib/ruby-macrodroid/triggers.rb +31 -6
- metadata +12 -10
- metadata.gz.sig +0 -0
@@ -42,29 +42,17 @@ class Action < MacroObject
|
|
42
42
|
macro = h[:macro]
|
43
43
|
h.delete :macro
|
44
44
|
super(h)
|
45
|
-
|
46
|
-
# fetch the constraints
|
45
|
+
|
47
46
|
@constraints = @h[:constraint_list].map do |constraint|
|
48
47
|
object(constraint.to_snake_case.merge(macro: macro))
|
49
|
-
end
|
48
|
+
end
|
49
|
+
|
50
50
|
end
|
51
51
|
|
52
|
-
def invoke(
|
53
|
-
"%s/%s: %s" % [@group, @type,
|
52
|
+
def invoke(h={})
|
53
|
+
"%s/%s: %s" % [@group, @type, h.to_json]
|
54
54
|
end
|
55
55
|
|
56
|
-
def to_s(colour: false, indent: 0)
|
57
|
-
|
58
|
-
h = @h.clone
|
59
|
-
h.delete :macro
|
60
|
-
@s ||= "#<%s %s>" % [self.class, h.inspect]
|
61
|
-
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
62
|
-
constraints = @constraints.map \
|
63
|
-
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
64
|
-
|
65
|
-
@s + constraints
|
66
|
-
|
67
|
-
end
|
68
56
|
|
69
57
|
end
|
70
58
|
|
@@ -140,7 +128,7 @@ class LaunchShortcutAction < ApplicationAction
|
|
140
128
|
end
|
141
129
|
|
142
130
|
def to_s(colour: false, indent: 0)
|
143
|
-
@s = "Launch Shortcut: " + @h[:app_name] + "\n
|
131
|
+
@s = "Launch Shortcut: " + @h[:app_name] + "\n" + @h[:name]
|
144
132
|
super()
|
145
133
|
end
|
146
134
|
|
@@ -148,28 +136,52 @@ class LaunchShortcutAction < ApplicationAction
|
|
148
136
|
|
149
137
|
end
|
150
138
|
|
139
|
+
class OpenWebPageActionError < Exception
|
140
|
+
end
|
141
|
+
|
151
142
|
# Category: Applications
|
152
143
|
#
|
153
144
|
class OpenWebPageAction < ApplicationAction
|
154
145
|
|
155
|
-
def initialize(
|
146
|
+
def initialize(obj={})
|
147
|
+
|
148
|
+
h = if obj.is_a? Hash then
|
149
|
+
obj
|
150
|
+
elsif obj.is_a? Array
|
151
|
+
e, macro = obj
|
152
|
+
txt = e.text('item/description')
|
153
|
+
{url: (txt || e.text)}
|
154
|
+
end
|
156
155
|
|
157
156
|
h[:url_to_open] = h[:url] if h[:url]
|
158
157
|
|
159
158
|
options = {
|
160
|
-
variable_to_save_response: {:m_stringValue=>"", :m_name=>"",
|
159
|
+
variable_to_save_response: {:m_stringValue=>"", :m_name=>"",
|
160
|
+
m_decimalValue: 0.0, isLocal: true, m_booleanValue: false,
|
161
|
+
excludeFromLog: false, m_intValue: 0, m_type: 2},
|
161
162
|
url_to_open: '',
|
162
163
|
http_get: true,
|
163
164
|
disable_url_encode: false,
|
164
165
|
block_next_action: false
|
165
166
|
}
|
166
|
-
|
167
|
-
|
167
|
+
|
168
|
+
if h[:macro].remote_url.nil? then
|
169
|
+
raise OpenWebPageActionError, 'remote_url not found'
|
170
|
+
end
|
171
|
+
|
172
|
+
if (h[:identifier].nil? or h[:identifier].empty?) and
|
173
|
+
(h[:url_to_open].nil? or h[:url_to_open].empty?) then
|
174
|
+
h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' +
|
175
|
+
h[:macro].title.downcase.gsub(/ +/,'-')
|
176
|
+
end
|
177
|
+
|
178
|
+
super(options.merge h)
|
168
179
|
|
169
180
|
end
|
170
181
|
|
171
182
|
def to_s(colour: false, indent: 0)
|
172
|
-
"HTTP GET\
|
183
|
+
@s = "HTTP GET\nurl: " + @h[:url_to_open]
|
184
|
+
super()
|
173
185
|
end
|
174
186
|
|
175
187
|
end
|
@@ -284,10 +296,20 @@ class LoopAction < Action
|
|
284
296
|
|
285
297
|
def to_s(colour: false, indent: 0)
|
286
298
|
|
299
|
+
h = @h.clone
|
300
|
+
h.delete :macro
|
287
301
|
@s = 'DO / WHILE '
|
288
|
-
|
302
|
+
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
303
|
+
constraints = @constraints.map \
|
304
|
+
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
289
305
|
|
290
|
-
|
306
|
+
out = []
|
307
|
+
out << "; %s" % @h[:comment] if @h[:comment]
|
308
|
+
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
309
|
+
out << s + constraints
|
310
|
+
out.join("\n")
|
311
|
+
|
312
|
+
end
|
291
313
|
end
|
292
314
|
|
293
315
|
# Conditions/Loops
|
@@ -318,25 +340,49 @@ end
|
|
318
340
|
# Conditions/Loops
|
319
341
|
#
|
320
342
|
class IfConditionAction < Action
|
321
|
-
|
343
|
+
|
322
344
|
def initialize(obj=nil)
|
345
|
+
|
346
|
+
options = {
|
347
|
+
a: true,
|
348
|
+
constraint_list: []
|
349
|
+
}
|
323
350
|
|
324
|
-
|
325
|
-
|
351
|
+
if obj.is_a? Hash then
|
352
|
+
|
353
|
+
h = obj
|
354
|
+
macro = h[:macro]
|
355
|
+
h2 = options.merge(filter(options,h).merge(macro: macro))
|
356
|
+
super(h2)
|
357
|
+
|
358
|
+
elsif obj.is_a? Rexle::Element
|
359
|
+
super()
|
360
|
+
raw_txt = obj.text('item/description') || obj.text.to_s
|
361
|
+
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
362
|
+
|
363
|
+
clause = raw_txt[/^if (.*)/i,1]
|
364
|
+
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
365
|
+
|
366
|
+
cp = ConstraintsNlp.new
|
367
|
+
|
368
|
+
@constraints = conditions.map do |c|
|
369
|
+
puts 'c: ' + c.inspect
|
370
|
+
r = cp.find_constraint c
|
371
|
+
puts 'found constraint ' + r.inspect if $debug
|
372
|
+
|
373
|
+
r[0].new(r[1]) if r
|
374
|
+
|
375
|
+
end
|
376
|
+
puts '@constraints: ' + @constraints.inspect if $debug
|
377
|
+
{}
|
326
378
|
else
|
327
379
|
# get the constraints
|
328
380
|
|
329
381
|
end
|
330
382
|
|
331
|
-
|
332
|
-
a: true,
|
333
|
-
constraint_list: ''
|
334
|
-
}
|
383
|
+
|
335
384
|
|
336
|
-
macro = h[:macro]
|
337
|
-
h2 = options.merge(filter(options,h).merge(macro: macro))
|
338
385
|
|
339
|
-
super(h2)
|
340
386
|
|
341
387
|
@label = 'If '
|
342
388
|
|
@@ -344,10 +390,20 @@ class IfConditionAction < Action
|
|
344
390
|
|
345
391
|
def to_s(colour: false, indent: 0)
|
346
392
|
|
347
|
-
|
348
|
-
|
393
|
+
h = @h.clone
|
394
|
+
h.delete :macro
|
395
|
+
@s = 'If '
|
396
|
+
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
397
|
+
constraints = @constraints.map \
|
398
|
+
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
349
399
|
|
350
|
-
|
400
|
+
out = []
|
401
|
+
out << "; %s" % @h[:comment] if @h[:comment]
|
402
|
+
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
403
|
+
out << s + constraints
|
404
|
+
out.join("\n")
|
405
|
+
|
406
|
+
end
|
351
407
|
end
|
352
408
|
|
353
409
|
class ElseAction < Action
|
@@ -383,8 +439,24 @@ class ElseIfConditionAction < Action
|
|
383
439
|
end
|
384
440
|
|
385
441
|
def to_s(colour: false, indent: 0)
|
442
|
+
|
443
|
+
h = @h.clone
|
444
|
+
h.delete :macro
|
386
445
|
@s = 'Else If '
|
387
|
-
|
446
|
+
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
447
|
+
constraints = @constraints.map \
|
448
|
+
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
449
|
+
|
450
|
+
out = []
|
451
|
+
out << "; %s" % @h[:comment] if @h[:comment]
|
452
|
+
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
453
|
+
out << s + constraints
|
454
|
+
out.join("\n")
|
455
|
+
|
456
|
+
end
|
457
|
+
|
458
|
+
def to_summary(colour: false)
|
459
|
+
'foo'
|
388
460
|
end
|
389
461
|
|
390
462
|
|
@@ -393,10 +465,17 @@ end
|
|
393
465
|
|
394
466
|
class EndIfAction < Action
|
395
467
|
|
396
|
-
def initialize(
|
397
|
-
|
468
|
+
def initialize(obj={})
|
469
|
+
|
470
|
+
h = if obj.is_a? Hash then
|
471
|
+
obj
|
472
|
+
elsif obj.is_a? Rexle::Element
|
473
|
+
{}
|
474
|
+
end
|
475
|
+
|
476
|
+
|
398
477
|
options = {
|
399
|
-
constraint_list:
|
478
|
+
constraint_list: []
|
400
479
|
}
|
401
480
|
|
402
481
|
super(options.merge h)
|
@@ -407,6 +486,8 @@ class EndIfAction < Action
|
|
407
486
|
'End If'
|
408
487
|
end
|
409
488
|
|
489
|
+
alias to_summary to_s
|
490
|
+
|
410
491
|
end
|
411
492
|
|
412
493
|
class ConnectivityAction < Action
|
@@ -436,7 +517,7 @@ class SetAirplaneModeAction < ConnectivityAction
|
|
436
517
|
def to_s(colour: false, indent: 0)
|
437
518
|
|
438
519
|
state = ['On', 'Off', 'Toggle'][@h[:state]]
|
439
|
-
@s = 'Airplane Mode ' + state
|
520
|
+
@s = 'Airplane Mode ' + state
|
440
521
|
super(colour: colour)
|
441
522
|
|
442
523
|
end
|
@@ -618,7 +699,10 @@ class StopWatchAction < DateTimeAction
|
|
618
699
|
end
|
619
700
|
|
620
701
|
def to_s(colour: false, indent: 0)
|
621
|
-
'
|
702
|
+
option = ['Start', 'Pause','Reset','Reset and Restart'][@h[:option]]
|
703
|
+
name = @h[:stopwatch_name]
|
704
|
+
@s = "StopWatch (%s)" % option + "\n" + name #+ ' ' + @h.inspect
|
705
|
+
super()
|
622
706
|
end
|
623
707
|
|
624
708
|
alias to_summary to_s
|
@@ -1125,7 +1209,7 @@ class FileOperationV21Action < FileAction
|
|
1125
1209
|
detail = @h[:from_name]
|
1126
1210
|
detail += ' to: ' + @h[:to_name] if @h[:option] == 1
|
1127
1211
|
@s = "%s %s" % [operation[@h[:option]], file[@h[:file_option]]] \
|
1128
|
-
+ "\n
|
1212
|
+
+ "\n" + detail #+ @h.inspect
|
1129
1213
|
super()
|
1130
1214
|
end
|
1131
1215
|
|
@@ -1244,7 +1328,7 @@ class ShareLocationAction < LocationAction
|
|
1244
1328
|
end
|
1245
1329
|
|
1246
1330
|
def to_s(colour: false, indent: 0)
|
1247
|
-
@s = 'Share Location' + "\
|
1331
|
+
@s = 'Share Location' + "\nGPS" # + @h.inspect
|
1248
1332
|
super()
|
1249
1333
|
end
|
1250
1334
|
|
@@ -1360,6 +1444,31 @@ class ClearLogAction < LoggingAction
|
|
1360
1444
|
alias to_summary to_s
|
1361
1445
|
end
|
1362
1446
|
|
1447
|
+
|
1448
|
+
# MacroDroid Specific
|
1449
|
+
#
|
1450
|
+
class CancelActiveMacroAction < Action
|
1451
|
+
|
1452
|
+
def initialize(h={})
|
1453
|
+
|
1454
|
+
options = {
|
1455
|
+
|
1456
|
+
}
|
1457
|
+
|
1458
|
+
super(h)
|
1459
|
+
|
1460
|
+
end
|
1461
|
+
|
1462
|
+
def to_s(colour: false, indent: 0)
|
1463
|
+
@s = 'Cancel Macro Actions' + "\n " + @h[:macro_name] #+ ' ' + @h.inspect
|
1464
|
+
super()
|
1465
|
+
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
alias to_summary to_s
|
1469
|
+
|
1470
|
+
end
|
1471
|
+
|
1363
1472
|
# MacroDroid Specific
|
1364
1473
|
#
|
1365
1474
|
class ConfirmNextAction < Action
|
@@ -1377,7 +1486,7 @@ class ConfirmNextAction < Action
|
|
1377
1486
|
|
1378
1487
|
def to_s(colour: false, indent: 0)
|
1379
1488
|
|
1380
|
-
@s = 'Confirm Next' + "\n
|
1489
|
+
@s = 'Confirm Next' + "\n%s: %s" % [@h[:title], @h[:message]]
|
1381
1490
|
super()
|
1382
1491
|
|
1383
1492
|
end
|
@@ -1461,7 +1570,7 @@ class SetVariableAction < Action
|
|
1461
1570
|
|
1462
1571
|
end
|
1463
1572
|
|
1464
|
-
@s = 'Set Variable' + ("\n
|
1573
|
+
@s = 'Set Variable' + ("\n%s: " % @h[:variable][:name]) + input #+ @h.inspect
|
1465
1574
|
super()
|
1466
1575
|
|
1467
1576
|
end
|
@@ -1632,7 +1741,7 @@ class SendEmailAction < MessagingAction
|
|
1632
1741
|
|
1633
1742
|
def to_s(colour: false, indent: 0)
|
1634
1743
|
recipient = @h[:email_address]
|
1635
|
-
@s = 'Send EmailAction' + "\
|
1744
|
+
@s = 'Send EmailAction' + "\nTo: " + recipient #+ ' ' + @h.inspect
|
1636
1745
|
super()
|
1637
1746
|
end
|
1638
1747
|
|
@@ -1707,7 +1816,7 @@ class ClearNotificationsAction < NotificationsAction
|
|
1707
1816
|
options = {
|
1708
1817
|
package_name_list: [],
|
1709
1818
|
match_text: '',
|
1710
|
-
application_name_list: [],
|
1819
|
+
application_name_list: [],
|
1711
1820
|
clear_persistent: false,
|
1712
1821
|
excludes: false,
|
1713
1822
|
match_option: 0,
|
@@ -1870,8 +1979,9 @@ class NotificationAction < NotificationsAction
|
|
1870
1979
|
end
|
1871
1980
|
|
1872
1981
|
def to_s(colour: false, indent: 0)
|
1873
|
-
"Display Notification\n
|
1982
|
+
@s = "Display Notification\n" + \
|
1874
1983
|
"%s: %s" % [@h[:notification_subject], @h[:notification_text]]
|
1984
|
+
super()
|
1875
1985
|
end
|
1876
1986
|
|
1877
1987
|
end
|
@@ -1884,8 +1994,10 @@ class ToastAction < NotificationsAction
|
|
1884
1994
|
|
1885
1995
|
h = if obj.is_a? Hash then
|
1886
1996
|
obj
|
1887
|
-
|
1888
|
-
|
1997
|
+
elsif obj.is_a? Array
|
1998
|
+
e, macro = obj
|
1999
|
+
txt = e.text('item/description')
|
2000
|
+
{msg: (txt || e.text)}
|
1889
2001
|
end
|
1890
2002
|
|
1891
2003
|
if h[:msg] then
|
@@ -1909,7 +2021,7 @@ class ToastAction < NotificationsAction
|
|
1909
2021
|
end
|
1910
2022
|
|
1911
2023
|
def invoke()
|
1912
|
-
super(@h[:message_text])
|
2024
|
+
super(msg: @h[:message_text])
|
1913
2025
|
end
|
1914
2026
|
|
1915
2027
|
def to_pc()
|
@@ -1917,7 +2029,8 @@ class ToastAction < NotificationsAction
|
|
1917
2029
|
end
|
1918
2030
|
|
1919
2031
|
def to_s(colour: false, indent: 0)
|
1920
|
-
@s = "Popup Message\n
|
2032
|
+
@s = "Popup Message\n%s" % @h[:message_text]
|
2033
|
+
super()
|
1921
2034
|
end
|
1922
2035
|
|
1923
2036
|
end
|
@@ -1947,7 +2060,7 @@ class AnswerCallAction < PhoneAction
|
|
1947
2060
|
end
|
1948
2061
|
|
1949
2062
|
def to_s(colour: false, indent: 0)
|
1950
|
-
@s = 'Answer Call'
|
2063
|
+
@s = 'Answer Call'
|
1951
2064
|
super()
|
1952
2065
|
end
|
1953
2066
|
end
|
@@ -2009,7 +2122,7 @@ class RejectCallAction < PhoneAction
|
|
2009
2122
|
end
|
2010
2123
|
|
2011
2124
|
def to_s(colour: false, indent: 0)
|
2012
|
-
@s = 'Call Reject'
|
2125
|
+
@s = 'Call Reject'
|
2013
2126
|
super()
|
2014
2127
|
end
|
2015
2128
|
|
@@ -2085,7 +2198,9 @@ class SetBrightnessAction < ScreenAction
|
|
2085
2198
|
end
|
2086
2199
|
|
2087
2200
|
def to_s(colour: false, indent: 0)
|
2088
|
-
|
2201
|
+
val = @h[:brightness_percent] > 100 ? 'Auto' : @h[:brightness_percent].to_s + '%'
|
2202
|
+
@s = 'Brightness' + "\n " + val #@h.inspect
|
2203
|
+
super()
|
2089
2204
|
end
|
2090
2205
|
|
2091
2206
|
alias to_summary to_s
|
@@ -2135,7 +2250,8 @@ class ScreenOnAction < ScreenAction
|
|
2135
2250
|
state += ' ' + 'No Lock (root only)' if @h[:screen_off_no_lock]
|
2136
2251
|
#state += ' ' + '(Alternative)' if @h[:screen_on_alternative]
|
2137
2252
|
|
2138
|
-
'Screen ' + state
|
2253
|
+
@s = 'Screen ' + state
|
2254
|
+
super()
|
2139
2255
|
|
2140
2256
|
end
|
2141
2257
|
|
@@ -2290,7 +2406,7 @@ class SetVibrateAction < VolumeAction
|
|
2290
2406
|
]
|
2291
2407
|
|
2292
2408
|
status = a[@h[:option_int]]
|
2293
|
-
@s = 'Vibrate Enable/Disable ' + "\n
|
2409
|
+
@s = 'Vibrate Enable/Disable ' + "\n" + status
|
2294
2410
|
super()
|
2295
2411
|
|
2296
2412
|
end
|
data/lib/ruby-macrodroid/base.rb
CHANGED
@@ -54,16 +54,30 @@ class MacroObject
|
|
54
54
|
@h[:siguid]
|
55
55
|
end
|
56
56
|
|
57
|
-
def to_s(colour: false)
|
58
|
-
|
57
|
+
def to_s(colour: false, indent: 0)
|
58
|
+
|
59
59
|
h = @h.clone
|
60
60
|
h.delete :macro
|
61
61
|
@s ||= "#<%s %s>" % [self.class, h.inspect]
|
62
62
|
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
63
63
|
constraints = @constraints.map \
|
64
|
-
{|x| x.to_summary(colour: colour)}
|
64
|
+
{|x| 'c: ' + x.to_summary(colour: colour)}
|
65
|
+
|
66
|
+
out = []
|
67
|
+
out << "; %s" % @h[:comment] if @h[:comment] and @h[:comment].length > 1
|
68
|
+
#s = @s.lines.map {|x| 'x' + x}.join
|
69
|
+
|
70
|
+
lines = @s.lines
|
71
|
+
|
72
|
+
if lines.length > 1 then
|
73
|
+
s = lines[0] + lines[1..-1].map {|x| x.prepend (' ' * (indent+1)) }.join
|
74
|
+
else
|
75
|
+
s = @s
|
76
|
+
end
|
65
77
|
|
66
|
-
|
78
|
+
out << s
|
79
|
+
out += constraints
|
80
|
+
out.join("\n")
|
67
81
|
|
68
82
|
end
|
69
83
|
|