ruby-macrodroid 0.9.12 → 0.9.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid/actions.rb +297 -22
- data/lib/ruby-macrodroid/actionsnlp.rb +66 -7
- data/lib/ruby-macrodroid/base.rb +7 -3
- data/lib/ruby-macrodroid/macro.rb +2 -2
- data/lib/ruby-macrodroid/triggers.rb +160 -18
- data/lib/ruby-macrodroid/triggersnlp.rb +73 -2
- metadata +2 -2
- 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: d2a2688ed5b9d38f47749aa2f3e2d08002d7250d2690189f6034dec81b5d2ee5
|
4
|
+
data.tar.gz: 95d917dc64a5322caeacd5abd64f2b1cb9013e34908536860424f9cc47de6d1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0765669d573b157239bdb0ecfde3f34f1717160976e38e870fa1d20b105af0e5919370812e16e81232cb627bf32b2b833a732cf8ec4647ab2445e9aba0767014'
|
7
|
+
data.tar.gz: e1317255ded299969e64fef30d7f67b8706c1163202b032e190969f275b23524fa5ad81a1481eefc3c786153cd00a04d409a414316d3022674ae6e9fa5b7514a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -32,6 +32,30 @@
|
|
32
32
|
#
|
33
33
|
|
34
34
|
|
35
|
+
APPS = {
|
36
|
+
'AutoBoy' => 'com.happyconz.blackbox',
|
37
|
+
'Amazon Alexa' => 'com.amazon.dee.app',
|
38
|
+
'Brave' => 'com.brave.browser',
|
39
|
+
'Camera' => 'com.google.android.camera',
|
40
|
+
'Cast to TV' => 'cast.video.screenmirroring.casttotv',
|
41
|
+
'File Manager' => 'com.alphainventor.filemanager',
|
42
|
+
'Firefox' => 'org.mozilla.firefox',
|
43
|
+
'Google Chrome' => 'com.google.android.chrome',
|
44
|
+
'Chrome' => 'com.google.android.chrome',
|
45
|
+
'Google Home' => 'com.google.android.apps.chromecast.app',
|
46
|
+
'Google Play Music' => 'com.google.android.music',
|
47
|
+
'MacroDroid' => 'com.arlosoft.macrodroid',
|
48
|
+
'QuickEdit Text Editor Pro' => 'com.rhmsoft.edit.pro',
|
49
|
+
'QR & Barcode Reader' => 'com.teacapps.barcodescanner',
|
50
|
+
'Settings' => 'com.google.android.settings',
|
51
|
+
'tinyCam PRO' => 'com.alexvas.dvr.pro',
|
52
|
+
'Tor Browser' => 'org.torproject.torbrowser',
|
53
|
+
'VLC' => 'org.videolan.vlc',
|
54
|
+
'WiFi FTP Server' => 'com.medhaapps.wififtpserver',
|
55
|
+
'YouTube' => 'com.google.android.youtube'
|
56
|
+
}
|
57
|
+
|
58
|
+
|
35
59
|
class Action < MacroObject
|
36
60
|
using ColouredText
|
37
61
|
using Params
|
@@ -76,19 +100,28 @@ class LaunchActivityAction < ApplicationAction
|
|
76
100
|
|
77
101
|
def initialize(h={})
|
78
102
|
|
103
|
+
# option 0 is by application name, 1 is launch by package name
|
104
|
+
#
|
79
105
|
options = {
|
80
106
|
application_name: 'Chrome',
|
81
107
|
package_to_launch: 'com.android.chrome',
|
82
108
|
exclude_from_recents: false,
|
83
|
-
start_new: false
|
109
|
+
start_new: false,
|
110
|
+
option: 0,
|
111
|
+
launch_by_package_name: ''
|
84
112
|
}
|
85
113
|
|
86
114
|
super(options.merge h)
|
115
|
+
|
116
|
+
@list = %w(option launchByPackageName)
|
87
117
|
|
88
118
|
end
|
89
119
|
|
90
120
|
def to_s(colour: false, indent: 0)
|
91
|
-
|
121
|
+
option = @h[:option] == 0 ? @h[:application_name] : \
|
122
|
+
@h[:launch_by_package_name]
|
123
|
+
@s = 'Launch ' + option
|
124
|
+
super()
|
92
125
|
end
|
93
126
|
|
94
127
|
end
|
@@ -150,17 +183,17 @@ class OpenWebPageAction < ApplicationAction
|
|
150
183
|
|
151
184
|
def initialize(obj={}, macro=nil)
|
152
185
|
|
153
|
-
$debug =
|
186
|
+
$debug = true
|
154
187
|
puts ('obj: ' + obj.inspect).debug if $debug
|
155
188
|
|
156
189
|
h = if obj.is_a? Hash then
|
157
190
|
|
158
|
-
obj.merge({macro: macro})
|
191
|
+
obj.merge({macro: macro}) #unless obj and obj[:macro]
|
159
192
|
|
160
193
|
elsif obj.is_a? Array
|
161
194
|
|
162
195
|
puts ('obj: ' + obj.inspect).debug if $debug
|
163
|
-
e, macro = obj
|
196
|
+
e, macro, h3 = obj
|
164
197
|
|
165
198
|
a = e.xpath('item/*')
|
166
199
|
|
@@ -181,7 +214,7 @@ class OpenWebPageAction < ApplicationAction
|
|
181
214
|
{url: (txt || e.text)}
|
182
215
|
end
|
183
216
|
|
184
|
-
h2.merge(macro: macro)
|
217
|
+
h2.merge(macro: macro).merge(h3)
|
185
218
|
|
186
219
|
end
|
187
220
|
|
@@ -219,6 +252,7 @@ class OpenWebPageAction < ApplicationAction
|
|
219
252
|
h[:macro].title.downcase.gsub(/ +/,'-')
|
220
253
|
|
221
254
|
end
|
255
|
+
puts 'url: ' + url.inspect if $debug
|
222
256
|
|
223
257
|
if h2 then
|
224
258
|
|
@@ -242,7 +276,8 @@ class OpenWebPageAction < ApplicationAction
|
|
242
276
|
end
|
243
277
|
|
244
278
|
def to_s(colour: false, indent: 0)
|
245
|
-
|
279
|
+
s = @h[:http_get] ? '' : 'Open Website / '
|
280
|
+
@s = s + "HTTP GET\nurl: " + @h[:url_to_open]
|
246
281
|
super()
|
247
282
|
end
|
248
283
|
|
@@ -378,6 +413,61 @@ class TakePictureAction < CameraAction
|
|
378
413
|
end
|
379
414
|
|
380
415
|
|
416
|
+
class TakeScreenshotAction < CameraAction
|
417
|
+
|
418
|
+
def initialize(obj=nil)
|
419
|
+
|
420
|
+
h = if obj.is_a? Hash then
|
421
|
+
obj
|
422
|
+
elsif obj.is_a? Array
|
423
|
+
|
424
|
+
e, macro = obj
|
425
|
+
|
426
|
+
a = [
|
427
|
+
'Save to device',
|
428
|
+
'Send via email',
|
429
|
+
'Share via intent'
|
430
|
+
]
|
431
|
+
|
432
|
+
s = e.text('item/description').to_s
|
433
|
+
index = a.map(&:downcase).index s.downcase
|
434
|
+
|
435
|
+
{option: index}
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
options = {
|
440
|
+
option: 0,
|
441
|
+
use_smtp_email: false,
|
442
|
+
mechanism_option: 0,
|
443
|
+
save_to_jpeg: false
|
444
|
+
}
|
445
|
+
|
446
|
+
super(options.merge h)
|
447
|
+
|
448
|
+
end
|
449
|
+
|
450
|
+
def to_s(colour: false, indent: 0)
|
451
|
+
|
452
|
+
@s = 'Take Screenshot' #+ @h.inspect
|
453
|
+
|
454
|
+
options = [
|
455
|
+
'Save to device',
|
456
|
+
'Send via email',
|
457
|
+
'Share via intent'
|
458
|
+
]
|
459
|
+
|
460
|
+
option = options[@h[:option]]
|
461
|
+
|
462
|
+
@s += "\n" + option
|
463
|
+
super()
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
alias to_summary to_s
|
468
|
+
end
|
469
|
+
|
470
|
+
|
381
471
|
# Conditions/Loops
|
382
472
|
#
|
383
473
|
class IfConfirmedThenAction < Action
|
@@ -888,8 +978,17 @@ end
|
|
888
978
|
#
|
889
979
|
class SayTimeAction < DateTimeAction
|
890
980
|
|
891
|
-
def initialize(
|
892
|
-
|
981
|
+
def initialize(obj=nil)
|
982
|
+
|
983
|
+
h = if obj.is_a? Hash then
|
984
|
+
obj
|
985
|
+
elsif obj.is_a? Array
|
986
|
+
|
987
|
+
e, macro = obj
|
988
|
+
{:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
|
989
|
+
|
990
|
+
end
|
991
|
+
|
893
992
|
options = {
|
894
993
|
:'12_hour' => true
|
895
994
|
}
|
@@ -910,7 +1009,9 @@ class SayTimeAction < DateTimeAction
|
|
910
1009
|
end
|
911
1010
|
|
912
1011
|
def to_s(colour: false, indent: 0)
|
913
|
-
'Say Current Time'
|
1012
|
+
@s = 'Say Current Time'
|
1013
|
+
@s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
|
1014
|
+
super()
|
914
1015
|
end
|
915
1016
|
|
916
1017
|
end
|
@@ -950,8 +1051,15 @@ end
|
|
950
1051
|
#
|
951
1052
|
class ClipboardAction < DeviceAction
|
952
1053
|
|
953
|
-
def initialize(
|
1054
|
+
def initialize(obj=nil)
|
954
1055
|
|
1056
|
+
h = if obj.is_a? Hash then
|
1057
|
+
obj
|
1058
|
+
elsif obj.is_a? Array
|
1059
|
+
e, macro = obj
|
1060
|
+
{clipboard_text: e.text('item/description').to_s}
|
1061
|
+
end
|
1062
|
+
|
955
1063
|
options = {
|
956
1064
|
clipboard_text: ''
|
957
1065
|
}
|
@@ -1031,14 +1139,60 @@ end
|
|
1031
1139
|
#
|
1032
1140
|
class UIInteractionAction < DeviceAction
|
1033
1141
|
|
1034
|
-
def initialize(
|
1142
|
+
def initialize(obj=nil)
|
1143
|
+
|
1144
|
+
if obj.is_a? Hash then
|
1145
|
+
h = obj
|
1146
|
+
elsif obj.is_a? Array
|
1147
|
+
|
1148
|
+
e, macro = obj
|
1149
|
+
s = e.text('item/description').to_s
|
1150
|
+
|
1151
|
+
r = s.match(/^(Click|Long Click) \[(.*)\]$/)
|
1152
|
+
|
1153
|
+
# [Current focus] # Current focus
|
1154
|
+
# [0,0] # x,y location
|
1155
|
+
# [274,186] # Identify in app
|
1156
|
+
# [fooo] # Text content
|
1157
|
+
|
1158
|
+
h = {
|
1159
|
+
ui_interaction_configuration: {
|
1160
|
+
:xy_point=>{:x=>0, :y=>0},
|
1161
|
+
:type=>"Click"}
|
1162
|
+
}
|
1163
|
+
h2 = h[:ui_interaction_configuration]
|
1164
|
+
|
1165
|
+
if r then
|
1166
|
+
|
1167
|
+
h[:action] = 0
|
1168
|
+
|
1169
|
+
click, detail = r.captures
|
1170
|
+
h2[:long_click] = false if click.downcase.to_sym == :click
|
1171
|
+
|
1172
|
+
if detail == 'Current focus' then
|
1173
|
+
h2[:click_option] = 0
|
1174
|
+
elsif detail =~ /\d+,\d+/
|
1175
|
+
# to-do
|
1176
|
+
else
|
1177
|
+
# text content
|
1178
|
+
h2[:click_option] = 1
|
1179
|
+
h2[:text_content] = detail
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
#h[:ui_interaction_configuration] = h2
|
1183
|
+
end
|
1035
1184
|
|
1185
|
+
end
|
1186
|
+
|
1036
1187
|
options = {
|
1037
1188
|
ui_interaction_configuration: {:type=>"Copy"},
|
1038
1189
|
action: 2
|
1039
1190
|
}
|
1040
1191
|
|
1041
|
-
|
1192
|
+
|
1193
|
+
super(options.merge h)
|
1194
|
+
|
1195
|
+
@list = %w(uiInteractionConfiguration action xyPoint textContent clickOption type longClick)
|
1042
1196
|
|
1043
1197
|
end
|
1044
1198
|
|
@@ -1078,7 +1232,8 @@ class UIInteractionAction < DeviceAction
|
|
1078
1232
|
"Gesture [%s]" % detail
|
1079
1233
|
end
|
1080
1234
|
|
1081
|
-
'UI Interaction' + "\n
|
1235
|
+
@s = 'UI Interaction' + "\n" + s #+ ' ' + @h.inspect
|
1236
|
+
super()
|
1082
1237
|
end
|
1083
1238
|
|
1084
1239
|
alias to_summary to_s
|
@@ -1098,7 +1253,10 @@ class VoiceSearchAction < DeviceAction
|
|
1098
1253
|
end
|
1099
1254
|
|
1100
1255
|
def to_s(colour: false, indent: 0)
|
1101
|
-
|
1256
|
+
|
1257
|
+
@s = 'Voice Search' # + @h.inspect
|
1258
|
+
super()
|
1259
|
+
|
1102
1260
|
end
|
1103
1261
|
|
1104
1262
|
alias to_summary to_s
|
@@ -1656,9 +1814,18 @@ class ClearLogAction < LoggingAction
|
|
1656
1814
|
end
|
1657
1815
|
|
1658
1816
|
|
1817
|
+
class MacroDroidAction < Action
|
1818
|
+
|
1819
|
+
def initialize(h={})
|
1820
|
+
super(h)
|
1821
|
+
@group = 'macrodroid'
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
end
|
1825
|
+
|
1659
1826
|
# MacroDroid Specific
|
1660
1827
|
#
|
1661
|
-
class CancelActiveMacroAction <
|
1828
|
+
class CancelActiveMacroAction < MacroDroidAction
|
1662
1829
|
|
1663
1830
|
def initialize(h={})
|
1664
1831
|
|
@@ -1682,7 +1849,7 @@ end
|
|
1682
1849
|
|
1683
1850
|
# MacroDroid Specific
|
1684
1851
|
#
|
1685
|
-
class ConfirmNextAction <
|
1852
|
+
class ConfirmNextAction < MacroDroidAction
|
1686
1853
|
|
1687
1854
|
def initialize(h={})
|
1688
1855
|
|
@@ -1706,7 +1873,7 @@ class ConfirmNextAction < Action
|
|
1706
1873
|
|
1707
1874
|
end
|
1708
1875
|
|
1709
|
-
class DisableMacroAction <
|
1876
|
+
class DisableMacroAction < MacroDroidAction
|
1710
1877
|
|
1711
1878
|
def initialize(obj=nil)
|
1712
1879
|
|
@@ -1753,7 +1920,7 @@ end
|
|
1753
1920
|
|
1754
1921
|
# MacroDroid Specific
|
1755
1922
|
#
|
1756
|
-
class ExportMacrosAction <
|
1923
|
+
class ExportMacrosAction < MacroDroidAction
|
1757
1924
|
|
1758
1925
|
def initialize(h={})
|
1759
1926
|
|
@@ -1775,9 +1942,61 @@ class ExportMacrosAction < Action
|
|
1775
1942
|
end
|
1776
1943
|
|
1777
1944
|
|
1945
|
+
|
1946
|
+
class ForceMacroRunAction < MacroDroidAction
|
1947
|
+
|
1948
|
+
def initialize(obj=nil)
|
1949
|
+
|
1950
|
+
h = if obj.is_a? Hash then
|
1951
|
+
|
1952
|
+
obj
|
1953
|
+
|
1954
|
+
elsif obj.is_a? Array
|
1955
|
+
|
1956
|
+
e, macro, h2 = obj
|
1957
|
+
|
1958
|
+
# find the macro guid for the given name
|
1959
|
+
name = e.text('item/description').to_s
|
1960
|
+
found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
|
1961
|
+
|
1962
|
+
h3 = if found then
|
1963
|
+
{macro_name: found.title, GUID: found.guid}
|
1964
|
+
else
|
1965
|
+
{macro_name: name}
|
1966
|
+
end
|
1967
|
+
|
1968
|
+
h3.merge h2
|
1969
|
+
|
1970
|
+
end
|
1971
|
+
|
1972
|
+
options = {
|
1973
|
+
guid: nil, ignore_constraints: true,
|
1974
|
+
macro_name: "", use_off_status: false,
|
1975
|
+
user_prompt_title: "Run Macro"
|
1976
|
+
}
|
1977
|
+
super(options.merge h)
|
1978
|
+
|
1979
|
+
end
|
1980
|
+
|
1981
|
+
def invoke()
|
1982
|
+
super(macro_name: @h[:macro_name])
|
1983
|
+
end
|
1984
|
+
|
1985
|
+
def to_s(colour: false, indent: 0)
|
1986
|
+
|
1987
|
+
@s = 'Macro Run'# + @h.inspect
|
1988
|
+
@s += "\n" + @h[:macro_name]
|
1989
|
+
super()
|
1990
|
+
|
1991
|
+
end
|
1992
|
+
|
1993
|
+
alias to_summary to_s
|
1994
|
+
|
1995
|
+
end
|
1996
|
+
|
1778
1997
|
# MacroDroid Specific
|
1779
1998
|
#
|
1780
|
-
class SetVariableAction <
|
1999
|
+
class SetVariableAction < MacroDroidAction
|
1781
2000
|
using ColouredText
|
1782
2001
|
|
1783
2002
|
def initialize(obj=nil)
|
@@ -1867,7 +2086,7 @@ end
|
|
1867
2086
|
|
1868
2087
|
# MacroDroid Specific
|
1869
2088
|
#
|
1870
|
-
class TextManipulationAction <
|
2089
|
+
class TextManipulationAction < MacroDroidAction
|
1871
2090
|
|
1872
2091
|
def initialize(h={})
|
1873
2092
|
|
@@ -1910,7 +2129,7 @@ end
|
|
1910
2129
|
|
1911
2130
|
|
1912
2131
|
|
1913
|
-
class PauseAction <
|
2132
|
+
class PauseAction < MacroDroidAction
|
1914
2133
|
|
1915
2134
|
def initialize(h={})
|
1916
2135
|
|
@@ -1950,6 +2169,62 @@ end
|
|
1950
2169
|
|
1951
2170
|
# Category: Media
|
1952
2171
|
#
|
2172
|
+
|
2173
|
+
|
2174
|
+
# note: to find a package id from an App name, try searching for the name on
|
2175
|
+
# the Google Play Store and the id will be returned in the URL once the
|
2176
|
+
# correct app has been clicked. e.g.
|
2177
|
+
# https://play.google.com/store/apps/details?id=com.google.android.music
|
2178
|
+
#
|
2179
|
+
class ControlMediaAction < MediaAction
|
2180
|
+
|
2181
|
+
def initialize(obj=nil)
|
2182
|
+
|
2183
|
+
h = if obj.is_a? Hash then
|
2184
|
+
obj
|
2185
|
+
elsif obj.is_a? Array
|
2186
|
+
|
2187
|
+
e, macro = obj
|
2188
|
+
s = e.text('item/description').to_s
|
2189
|
+
app = s[/Simulate Media Button \(([^\)]+)/,1]
|
2190
|
+
|
2191
|
+
if app then
|
2192
|
+
|
2193
|
+
{
|
2194
|
+
application_name: app, package_name: APPS[app],
|
2195
|
+
simulate_media_button: true
|
2196
|
+
}
|
2197
|
+
|
2198
|
+
else
|
2199
|
+
{}
|
2200
|
+
end
|
2201
|
+
end
|
2202
|
+
|
2203
|
+
options = {
|
2204
|
+
application_name: "Google Play Music", option: "Play/Pause",
|
2205
|
+
package_name: "com.google.android.music",
|
2206
|
+
send_media_player_commands: false,
|
2207
|
+
simulate_media_button: true,
|
2208
|
+
}
|
2209
|
+
|
2210
|
+
super(options.merge h)
|
2211
|
+
|
2212
|
+
end
|
2213
|
+
|
2214
|
+
def to_s(colour: false, indent: 0)
|
2215
|
+
|
2216
|
+
@s = 'Media ' + @h[:option] #+ @h.inspect
|
2217
|
+
|
2218
|
+
if @h[:simulate_media_button] then
|
2219
|
+
@s += "\nSimulate Media Button (%s)" % @h[:application_name]
|
2220
|
+
end
|
2221
|
+
|
2222
|
+
super()
|
2223
|
+
end
|
2224
|
+
|
2225
|
+
alias to_summary to_s
|
2226
|
+
end
|
2227
|
+
|
1953
2228
|
class RecordMicrophoneAction < MediaAction
|
1954
2229
|
|
1955
2230
|
def initialize(h={})
|
@@ -86,10 +86,15 @@ class ActionsNlp
|
|
86
86
|
|
87
87
|
get /^take_picture/i do
|
88
88
|
[TakePictureAction, {}]
|
89
|
-
end
|
89
|
+
end
|
90
|
+
|
91
|
+
get /^Take Screenshot/i do
|
92
|
+
[TakeScreenshotAction, {}]
|
93
|
+
end
|
90
94
|
|
91
95
|
# -- DEVICE ACTIONS ------------------------------------------------------
|
92
96
|
|
97
|
+
#
|
93
98
|
get /^Speak text \(([^\)]+)\)/i do |text|
|
94
99
|
[SpeakTextAction, {text: text}]
|
95
100
|
end
|
@@ -100,7 +105,11 @@ class ActionsNlp
|
|
100
105
|
|
101
106
|
get /^Speak text$/i do |text|
|
102
107
|
[SpeakTextAction, {}]
|
103
|
-
end
|
108
|
+
end
|
109
|
+
|
110
|
+
get /^UI Interaction$/i do
|
111
|
+
[UIInteractionAction, {}]
|
112
|
+
end
|
104
113
|
|
105
114
|
get /^Vibrate \(([^\)]+)/i do |pattern|
|
106
115
|
[VibrateAction, {pattern: pattern}]
|
@@ -109,6 +118,11 @@ class ActionsNlp
|
|
109
118
|
get /^Vibrate$/i do |pattern|
|
110
119
|
[VibrateAction, {pattern: 'short buzz'}]
|
111
120
|
end
|
121
|
+
|
122
|
+
get /^Voice Search$/i do
|
123
|
+
[VoiceSearchAction, {}]
|
124
|
+
end
|
125
|
+
|
112
126
|
|
113
127
|
# e.g. Display Notification: Hi there: This is the body of the message
|
114
128
|
get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
|
@@ -123,6 +137,10 @@ class ActionsNlp
|
|
123
137
|
[SetWifiAction, {state: state}]
|
124
138
|
|
125
139
|
end
|
140
|
+
|
141
|
+
get /^Fill Clipboard$/i do
|
142
|
+
[ClipboardAction, {}]
|
143
|
+
end
|
126
144
|
|
127
145
|
# e.g. Play: Altair
|
128
146
|
get /^Play: (.*)$/i do |name|
|
@@ -132,12 +150,24 @@ class ActionsNlp
|
|
132
150
|
end
|
133
151
|
|
134
152
|
# e.g. Launch Settings
|
135
|
-
get /^Launch (.*)$/i do |
|
153
|
+
get /^Launch (.*)$/i do |s|
|
136
154
|
|
137
|
-
h = {
|
138
|
-
|
139
|
-
|
140
|
-
|
155
|
+
h = {}
|
156
|
+
|
157
|
+
if s[0] == '[' then
|
158
|
+
|
159
|
+
h[:launch_by_package_name] = s
|
160
|
+
h[:option] = 1
|
161
|
+
|
162
|
+
else
|
163
|
+
application = s
|
164
|
+
h[:application_name] = application
|
165
|
+
h[:package_to_launch] = APPS[application] || 'com.android.' +
|
166
|
+
application.downcase.split().join('.')
|
167
|
+
h[:option] = 0
|
168
|
+
|
169
|
+
end
|
170
|
+
|
141
171
|
[LaunchActivityAction, h]
|
142
172
|
|
143
173
|
end
|
@@ -155,6 +185,19 @@ class ActionsNlp
|
|
155
185
|
|
156
186
|
end
|
157
187
|
|
188
|
+
|
189
|
+
get /^Open Website \/ HTTP GET$/i do
|
190
|
+
|
191
|
+
[OpenWebPageAction, {http_get: false}]
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
get /^(?:open|goto) ((?:https?:\/\/|\[lv=)[^$]+)$/i do |url|
|
196
|
+
|
197
|
+
[OpenWebPageAction, url_to_open: url, http_get: false]
|
198
|
+
|
199
|
+
end
|
200
|
+
|
158
201
|
# e.g. webhook entered_kitchen
|
159
202
|
#
|
160
203
|
get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
|
@@ -221,6 +264,14 @@ class ActionsNlp
|
|
221
264
|
state = %w(enable disable toggle).index(rawstate.downcase)
|
222
265
|
[DisableMacroAction, {state: state}]
|
223
266
|
end
|
267
|
+
|
268
|
+
get /^Macro Run$/i do
|
269
|
+
[ForceMacroRunAction, {}]
|
270
|
+
end
|
271
|
+
|
272
|
+
get /^Run Macro$/i do
|
273
|
+
[ForceMacroRunAction, {}]
|
274
|
+
end
|
224
275
|
|
225
276
|
get /^Set Variable$/i do
|
226
277
|
[SetVariableAction, {}]
|
@@ -230,6 +281,14 @@ class ActionsNlp
|
|
230
281
|
[PauseAction, {delay_in_seconds: seconds.to_i}]
|
231
282
|
end
|
232
283
|
|
284
|
+
## -- Media -----------------------------------------
|
285
|
+
#
|
286
|
+
# options: Play/Pause, Previous, Next, Play, Pause, Stop
|
287
|
+
#
|
288
|
+
get /^Media ([^$]+)$/i do |option|
|
289
|
+
[ControlMediaAction, {option: option}]
|
290
|
+
end
|
291
|
+
|
233
292
|
# -- Screen ------------------------------------------------
|
234
293
|
#
|
235
294
|
get /^Screen (On|Off)$/i do |state|
|
data/lib/ruby-macrodroid/base.rb
CHANGED
@@ -12,7 +12,7 @@ module ObjectX
|
|
12
12
|
|
13
13
|
def action_to_object(ap, e, item, macro)
|
14
14
|
|
15
|
-
debug =
|
15
|
+
debug = true
|
16
16
|
|
17
17
|
puts 'inside action_to_object: item.xml: ' + item.xml if debug
|
18
18
|
|
@@ -34,7 +34,8 @@ module ObjectX
|
|
34
34
|
r = ap.find_action action
|
35
35
|
puts 'r: ' + r.inspect if debug
|
36
36
|
|
37
|
-
nested = description.element('item
|
37
|
+
nested = description.element('item/*')
|
38
|
+
puts 'nested: ' + nested.inspect if debug
|
38
39
|
|
39
40
|
if r[1].any? and not nested then
|
40
41
|
|
@@ -132,7 +133,8 @@ class MacroObject
|
|
132
133
|
end
|
133
134
|
|
134
135
|
def to_h()
|
135
|
-
|
136
|
+
|
137
|
+
@h.delete :macro
|
136
138
|
hashify(@h)
|
137
139
|
|
138
140
|
end
|
@@ -193,6 +195,7 @@ class MacroObject
|
|
193
195
|
|
194
196
|
end
|
195
197
|
|
198
|
+
|
196
199
|
private
|
197
200
|
|
198
201
|
def hashify(h)
|
@@ -204,6 +207,7 @@ class MacroObject
|
|
204
207
|
new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
|
205
208
|
new_key = new_key.prepend 'm_' unless @list.include? new_key
|
206
209
|
new_key = 'm_SIGUID' if new_key == 'm_siguid'
|
210
|
+
new_key = 'm_SSIDList' if new_key == 'm_ssidList'
|
207
211
|
new_val = value.is_a?(Hash) ? hashify(value) : value
|
208
212
|
r.merge(new_key => new_val)
|
209
213
|
end
|
@@ -268,7 +268,7 @@ class Macro
|
|
268
268
|
r = tp.find_trigger trigger
|
269
269
|
puts 'r: ' + r.inspect if @debug
|
270
270
|
#o = r[0].new([description, self]) if r
|
271
|
-
o = object_create(r[0], [description, self]) if r
|
271
|
+
o = object_create(r[0], [description, self, r[1]]) if r
|
272
272
|
puts 'after o' if @debug
|
273
273
|
o
|
274
274
|
|
@@ -356,7 +356,7 @@ class Macro
|
|
356
356
|
|
357
357
|
end
|
358
358
|
|
359
|
-
def match?(triggerx, detail={
|
359
|
+
def match?(triggerx, detail={}, model=nil )
|
360
360
|
|
361
361
|
if @triggers.any? {|x| x.type == triggerx and x.match?(detail, model) } then
|
362
362
|
|
@@ -61,6 +61,7 @@ class Trigger < MacroObject
|
|
61
61
|
{|x| 'c: ' + x.to_summary(colour: colour, indent: 1)}.join(" %s " % operator)
|
62
62
|
|
63
63
|
@constraints.any? ? @s + "\n" + constraints : @s
|
64
|
+
super()
|
64
65
|
|
65
66
|
end
|
66
67
|
|
@@ -85,7 +86,7 @@ end
|
|
85
86
|
# ["Any Network"]
|
86
87
|
# ["some Wifi SSID"] - 1 or more SSID can be supplied
|
87
88
|
|
88
|
-
class
|
89
|
+
class WifiConnectionTrigger2 < Trigger
|
89
90
|
|
90
91
|
def initialize(h={})
|
91
92
|
|
@@ -216,7 +217,7 @@ class PowerButtonToggleTrigger < Trigger
|
|
216
217
|
end
|
217
218
|
|
218
219
|
def to_s(colour: false)
|
219
|
-
|
220
|
+
"Power Button Toggle (%s)" % @h[:num_toggles] #+ @h.inspect
|
220
221
|
end
|
221
222
|
|
222
223
|
alias to_summary to_s
|
@@ -457,7 +458,7 @@ class WebHookTrigger < Trigger
|
|
457
458
|
|
458
459
|
url = "https://trigger.macrodroid.com/%s/%s" % \
|
459
460
|
[@deviceid, @h[:identifier]]
|
460
|
-
@s = 'WebHook (Url)' + "\n
|
461
|
+
@s = 'WebHook (Url)' + "\n" + url
|
461
462
|
super()
|
462
463
|
|
463
464
|
end
|
@@ -469,8 +470,15 @@ end
|
|
469
470
|
#
|
470
471
|
class WifiConnectionTrigger < Trigger
|
471
472
|
|
472
|
-
def initialize(
|
473
|
+
def initialize(obj=nil)
|
473
474
|
|
475
|
+
h = if obj.is_a? Hash then
|
476
|
+
obj
|
477
|
+
elsif obj.is_a? Array
|
478
|
+
e, macro = obj
|
479
|
+
{ssid_list: [e.text('item/description').to_s], wifi_state: 2}
|
480
|
+
end
|
481
|
+
|
474
482
|
options = {
|
475
483
|
ssid_list: [],
|
476
484
|
wifi_state: 0
|
@@ -482,10 +490,15 @@ class WifiConnectionTrigger < Trigger
|
|
482
490
|
|
483
491
|
def to_s(colour: false)
|
484
492
|
access_point = @h[:ssid_list].first
|
485
|
-
'Connected to network
|
493
|
+
@s = 'Connected to network'
|
494
|
+
@s += "\n" + access_point
|
495
|
+
super()
|
486
496
|
end
|
487
497
|
|
488
|
-
|
498
|
+
def to_summary()
|
499
|
+
access_point = @h[:ssid_list].first
|
500
|
+
'Connected to network' + access_point
|
501
|
+
end
|
489
502
|
end
|
490
503
|
|
491
504
|
# Category: Connectivity
|
@@ -1010,7 +1023,7 @@ class MusicPlayingTrigger < DeviceEventsTrigger
|
|
1010
1023
|
def to_s(colour: false)
|
1011
1024
|
|
1012
1025
|
event = @h[:option] == 0 ? 'Started' : 'Stopped'
|
1013
|
-
@s = 'Music/Sound Playing' + "\n
|
1026
|
+
@s = 'Music/Sound Playing' + "\n%s" % event #+ @h.inspect
|
1014
1027
|
super()
|
1015
1028
|
|
1016
1029
|
end
|
@@ -1026,8 +1039,15 @@ end
|
|
1026
1039
|
#
|
1027
1040
|
class NFCTrigger < DeviceEventsTrigger
|
1028
1041
|
|
1029
|
-
def initialize(
|
1030
|
-
|
1042
|
+
def initialize(obj=nil)
|
1043
|
+
|
1044
|
+
h = if obj.is_a? Hash then
|
1045
|
+
obj
|
1046
|
+
elsif obj.is_a? Array
|
1047
|
+
e, macro = obj
|
1048
|
+
{tag_name: e.text('item/description').to_s}
|
1049
|
+
end
|
1050
|
+
|
1031
1051
|
options = {
|
1032
1052
|
}
|
1033
1053
|
|
@@ -1367,8 +1387,24 @@ end
|
|
1367
1387
|
#
|
1368
1388
|
class ActivityRecognitionTrigger < SensorsTrigger
|
1369
1389
|
|
1370
|
-
def initialize(
|
1371
|
-
|
1390
|
+
def initialize(obj=nil)
|
1391
|
+
|
1392
|
+
#puts 'obj: ' + obj.inspect
|
1393
|
+
|
1394
|
+
h = if obj.is_a? Hash then
|
1395
|
+
|
1396
|
+
obj
|
1397
|
+
|
1398
|
+
elsif obj.is_a? Array
|
1399
|
+
|
1400
|
+
e, macro, h2 = obj
|
1401
|
+
#puts 'h2: ' + h2.inspect
|
1402
|
+
#puts 'e: ' + e.xml
|
1403
|
+
s = e.text('item/description').to_s
|
1404
|
+
#puts 's: ' + s.inspect
|
1405
|
+
{confidence_level: s[/\d+%$/].to_i}.merge h2
|
1406
|
+
end
|
1407
|
+
|
1372
1408
|
options = {
|
1373
1409
|
confidence_level: 50,
|
1374
1410
|
selected_index: 1
|
@@ -1380,9 +1416,18 @@ class ActivityRecognitionTrigger < SensorsTrigger
|
|
1380
1416
|
|
1381
1417
|
end
|
1382
1418
|
|
1419
|
+
def match?(detail={})
|
1420
|
+
@h[:selected_index] == detail[:selected_index]
|
1421
|
+
end
|
1422
|
+
|
1383
1423
|
def to_s(colour: false)
|
1424
|
+
|
1384
1425
|
activity = @activity[@h[:selected_index]]
|
1385
|
-
'Activity - ' + activity
|
1426
|
+
@s = 'Activity - ' + activity #+ @h.inspect
|
1427
|
+
@s += "\nConfidence >= %s%%" % @h[:confidence_level]
|
1428
|
+
|
1429
|
+
super()
|
1430
|
+
|
1386
1431
|
end
|
1387
1432
|
|
1388
1433
|
def to_summary(colour: false)
|
@@ -1499,6 +1544,19 @@ class FlipDeviceTrigger < SensorsTrigger
|
|
1499
1544
|
|
1500
1545
|
end
|
1501
1546
|
|
1547
|
+
def match?(detail={})
|
1548
|
+
|
1549
|
+
fd = detail[:face_down]
|
1550
|
+
|
1551
|
+
b = if fd.is_a? String then
|
1552
|
+
fd.downcase == 'true'
|
1553
|
+
else
|
1554
|
+
fd
|
1555
|
+
end
|
1556
|
+
|
1557
|
+
@h[:face_down] == b
|
1558
|
+
end
|
1559
|
+
|
1502
1560
|
def to_pc()
|
1503
1561
|
@h[:face_down] ? 'flip_device_down?' : 'flip_device_up?'
|
1504
1562
|
end
|
@@ -1577,7 +1635,7 @@ class ShortcutTrigger < Trigger
|
|
1577
1635
|
end
|
1578
1636
|
|
1579
1637
|
def to_s(colour: false)
|
1580
|
-
'
|
1638
|
+
'Shortcut Launched' #+ @h.inspect
|
1581
1639
|
end
|
1582
1640
|
|
1583
1641
|
alias to_summary to_s
|
@@ -1633,8 +1691,15 @@ end
|
|
1633
1691
|
#
|
1634
1692
|
class MediaButtonPressedTrigger < Trigger
|
1635
1693
|
|
1636
|
-
def initialize(
|
1694
|
+
def initialize(obj=nil)
|
1637
1695
|
|
1696
|
+
h = if obj.is_a? Hash then
|
1697
|
+
obj
|
1698
|
+
elsif obj.is_a? Array
|
1699
|
+
e, macro = obj
|
1700
|
+
{option: e.text('item/description').to_s}
|
1701
|
+
end
|
1702
|
+
|
1638
1703
|
options = {
|
1639
1704
|
option: 'Single Press',
|
1640
1705
|
cancel_press: false
|
@@ -1645,7 +1710,50 @@ class MediaButtonPressedTrigger < Trigger
|
|
1645
1710
|
end
|
1646
1711
|
|
1647
1712
|
def to_s(colour: false)
|
1648
|
-
|
1713
|
+
|
1714
|
+
@s = 'Media Button Pressed ' #+ @h.inspect
|
1715
|
+
@s += "\n" + @h[:option]
|
1716
|
+
super()
|
1717
|
+
|
1718
|
+
end
|
1719
|
+
|
1720
|
+
alias to_summary to_s
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
class MediaButtonV2Trigger < Trigger
|
1724
|
+
|
1725
|
+
def initialize(obj=nil)
|
1726
|
+
|
1727
|
+
@a = %w(Play Play/Pause Pause Stop Previous Next Headset Hook)
|
1728
|
+
|
1729
|
+
h = if obj.is_a? Hash then
|
1730
|
+
obj
|
1731
|
+
elsif obj.is_a? Array
|
1732
|
+
e, macro = obj
|
1733
|
+
s = e.text('item/description').to_s
|
1734
|
+
a = s.split(/, /)
|
1735
|
+
{options_enabled_array: @a.map {|x| a.include? x } }
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
|
1739
|
+
|
1740
|
+
options = {
|
1741
|
+
options_enabled_array: [true, false, false, false, false, false, false]
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
super(options.merge h)
|
1745
|
+
|
1746
|
+
end
|
1747
|
+
|
1748
|
+
def to_s(colour: false)
|
1749
|
+
|
1750
|
+
|
1751
|
+
options = @a.zip(@h[:options_enabled_array]).select(&:last).map(&:first)
|
1752
|
+
|
1753
|
+
@s = 'Media Button V2 ' #+ @h.inspect
|
1754
|
+
@s += "\n" + options.join(', ')
|
1755
|
+
super()
|
1756
|
+
|
1649
1757
|
end
|
1650
1758
|
|
1651
1759
|
alias to_summary to_s
|
@@ -1655,8 +1763,22 @@ end
|
|
1655
1763
|
#
|
1656
1764
|
class SwipeTrigger < Trigger
|
1657
1765
|
|
1658
|
-
def initialize(
|
1659
|
-
|
1766
|
+
def initialize(obj=nil)
|
1767
|
+
|
1768
|
+
h = if obj.is_a? Hash then
|
1769
|
+
obj
|
1770
|
+
elsif obj.is_a? Array
|
1771
|
+
|
1772
|
+
e, macro = obj
|
1773
|
+
s = e.text('item/description').to_s
|
1774
|
+
start, motion = s.split(/ - /,2)
|
1775
|
+
|
1776
|
+
{
|
1777
|
+
swipe_start_area: ['Top Left', 'Top Right'].index(start),
|
1778
|
+
swipe_motion: %w(Across Diagonal Down).index(motion)
|
1779
|
+
}
|
1780
|
+
end
|
1781
|
+
|
1660
1782
|
options = {
|
1661
1783
|
swipe_start_area: 0,
|
1662
1784
|
swipe_motion: 0,
|
@@ -1666,9 +1788,29 @@ class SwipeTrigger < Trigger
|
|
1666
1788
|
super(options.merge h)
|
1667
1789
|
|
1668
1790
|
end
|
1791
|
+
|
1792
|
+
def match?(detail={}, model=nil)
|
1793
|
+
|
1794
|
+
puts 'detail : ' + detail.inspect
|
1795
|
+
|
1796
|
+
return false if detail.empty?
|
1797
|
+
|
1798
|
+
detail[:swipe_start_area] = detail[:start]
|
1799
|
+
detail[:swipe_motion] = detail[:motion]
|
1800
|
+
return unless detail[:swipe_start_area] and detail[:swipe_motion]
|
1801
|
+
|
1802
|
+
@h[:swipe_start_area] == detail[:swipe_start_area].to_i and \
|
1803
|
+
@h[:swipe_motion] == detail[:swipe_motion].to_i
|
1804
|
+
|
1805
|
+
end
|
1669
1806
|
|
1670
1807
|
def to_s(colour: false)
|
1671
|
-
|
1808
|
+
|
1809
|
+
direction = [['Top Left', 'Top Right'][@h[:swipe_start_area]],
|
1810
|
+
%w(Across Diagonal Down)[@h[:swipe_motion]]].join(' - ')
|
1811
|
+
@s = 'Swipe Screen'# + @h.inspect
|
1812
|
+
@s += "\n" + direction
|
1813
|
+
super()
|
1672
1814
|
end
|
1673
1815
|
|
1674
1816
|
alias to_summary to_s
|
@@ -19,6 +19,10 @@ class TriggersNlp
|
|
19
19
|
|
20
20
|
# -- Battery/Power ---------------------------------------------
|
21
21
|
|
22
|
+
get /Power Button Toggle \((\d)\)/i do |num|
|
23
|
+
[PowerButtonToggleTrigger, {num_toggles: num.to_i}]
|
24
|
+
end
|
25
|
+
|
22
26
|
get /^Power Connected: (Wired \([^\)]+\))/i do |s|
|
23
27
|
|
24
28
|
h = {
|
@@ -50,7 +54,26 @@ class TriggersNlp
|
|
50
54
|
[ExternalPowerTrigger, h]
|
51
55
|
end
|
52
56
|
|
57
|
+
# -- Connectivity ----------------------------------------------------
|
58
|
+
#
|
59
|
+
|
60
|
+
# Wifi State Change
|
61
|
+
|
62
|
+
get /^Connected to network (.*)$/i do |network|
|
63
|
+
[WifiConnectionTrigger, {ssid_list: [network], wifi_state: 2 }]
|
64
|
+
end
|
65
|
+
|
66
|
+
get /^Connected to network$/i do
|
67
|
+
[WifiConnectionTrigger, {}]
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
53
72
|
# -- Device Events ----------------------------------------------------
|
73
|
+
|
74
|
+
get /^NFC Tag$/i do |state|
|
75
|
+
[NFCTrigger, {}]
|
76
|
+
end
|
54
77
|
|
55
78
|
get /^Screen[ _](On|Off)/i do |state|
|
56
79
|
[ScreenOnOffTrigger, {screen_on: state.downcase == 'on'}]
|
@@ -132,11 +155,59 @@ class TriggersNlp
|
|
132
155
|
[WebHookTrigger, params]
|
133
156
|
end
|
134
157
|
|
135
|
-
|
158
|
+
#-- MacroDroid specific ---------------------------------------------------------------
|
136
159
|
|
137
160
|
get /^EmptyTrigger$/i do
|
138
161
|
[EmptyTrigger, params]
|
139
|
-
end
|
162
|
+
end
|
163
|
+
|
164
|
+
#-- Sensors ---------------------------------------------------------------
|
165
|
+
|
166
|
+
get /^Activity - (.*)$/i do |s|
|
167
|
+
|
168
|
+
a = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
|
169
|
+
r = a.find {|x| x.downcase == s.downcase}
|
170
|
+
h = r ? {selected_index: a.index(r)} : {}
|
171
|
+
[ActivityRecognitionTrigger , h]
|
172
|
+
end
|
173
|
+
|
174
|
+
# -- User Input ---------------------------------------------------------------
|
175
|
+
|
176
|
+
get /^Media Button Pressed$/i do
|
177
|
+
[MediaButtonPressedTrigger, {}]
|
178
|
+
end
|
179
|
+
|
180
|
+
get /^Media Button V2$/i do
|
181
|
+
[MediaButtonV2Trigger, {}]
|
182
|
+
end
|
183
|
+
|
184
|
+
get /^Shortcut Launched$/i do
|
185
|
+
[ShortcutTrigger, {}]
|
186
|
+
end
|
187
|
+
|
188
|
+
get /^Swipe Screen$/i do
|
189
|
+
[SwipeTrigger, {}]
|
190
|
+
end
|
191
|
+
|
192
|
+
get /^Swipe (top left) (across|diagonal|down)$/i do |start, motion|
|
193
|
+
|
194
|
+
swipe_motion = case motion.downcase.to_sym
|
195
|
+
when :across
|
196
|
+
0
|
197
|
+
when :diagonal
|
198
|
+
1
|
199
|
+
when :down
|
200
|
+
2
|
201
|
+
end
|
202
|
+
|
203
|
+
h = {
|
204
|
+
swipe_start_area: (start.downcase == 'top left' ? 0 : 1),
|
205
|
+
swipe_motion: swipe_motion
|
206
|
+
}
|
207
|
+
|
208
|
+
[SwipeTrigger, h]
|
209
|
+
|
210
|
+
end
|
140
211
|
|
141
212
|
end
|
142
213
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-macrodroid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
|
36
36
|
SBHno3GEuuD8ZWj24IMJpfbp
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-10-
|
38
|
+
date: 2020-10-24 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
metadata.gz.sig
CHANGED
Binary file
|