Class: RemoteDroid::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/remotedroid/control.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dev = nil, deviceid: dev, remote_url: nil, debug: false) ⇒ Control

Returns a new instance of Control.



5
6
7
8
9
# File 'lib/remotedroid/control.rb', line 5

def initialize(dev=nil, deviceid: dev, remote_url: nil, debug: false)
  
  @deviceid, @remote_url, @debug = deviceid, remote_url, debug

end

Class Method Details

.disableObject



21
22
23
# File 'lib/remotedroid/control.rb', line 21

def self.disable()
  http_exec 'set-airplane-mode', {state: 1}
end

.enableObject



13
14
15
# File 'lib/remotedroid/control.rb', line 13

def self.enable()
  http_exec 'set-airplane-mode', {state: 0}
end

.offObject



25
26
27
# File 'lib/remotedroid/control.rb', line 25

def self.off()
  self.disable
end

.onObject



17
18
19
# File 'lib/remotedroid/control.rb', line 17

def self.on()
  self.enable
end

.toggleObject



29
30
31
# File 'lib/remotedroid/control.rb', line 29

def self.toggle()
  http_exec 'set-airplane-mode', {state: 2}
end

Instance Method Details

#airplane_modeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/remotedroid/control.rb', line 11

def airplane_mode()
  
  def self.enable()
    http_exec 'set-airplane-mode', {state: 0}
  end                
  
  def self.on()
    self.enable
  end                
  
  def self.disable()
    http_exec 'set-airplane-mode', {state: 1}
  end
  
  def self.off()
    self.disable
  end         
  
  def self.toggle()
    http_exec 'set-airplane-mode', {state: 2}
  end      
  
  self
end

#ask_alexa(options = {}) ⇒ Object



36
37
38
# File 'lib/remotedroid/control.rb', line 36

def ask_alexa(options={})
  http_exec 'ask-alexa', options
end

#autorotateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/remotedroid/control.rb', line 40

def autorotate()
  
  def self.enable()
    http_exec 'set-auto-rotate', {state: 0}
  end                
  
  def self.on()
    self.enable
  end
  
  def self.disable()
    http_exec 'set-auto-rotate', {state: 1}
  end
  
  def self.off()
    self.disable
  end         
  
  def self.toggle()
    http_exec 'set-auto-rotate', {state: 2}
  end      
  
  self
end

#bluetoothObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/remotedroid/control.rb', line 65

def bluetooth()
  
  def self.enable()
    http_exec 'set-bluetooth', {state: 0}
  end                
  
  def self.on()
    self.enable
  end                
  
  def self.disable()
    http_exec 'set-bluetooth', {state: 1}
  end
  
  def self.off()
    self.disable
  end         
  
  def self.toggle()
    http_exec 'set-bluetooth', {state: 2}
  end      
  
  self
end

#camera_flash_light(options = {}) ⇒ Object



90
91
92
# File 'lib/remotedroid/control.rb', line 90

def camera_flash_light(options={})
  http_exec 'camera-flash-light', options
end

#click(options = {content: ''}) ⇒ Object



94
95
96
# File 'lib/remotedroid/control.rb', line 94

def click(options={content: ''})
  http_exec 'click-text-content', options
end

#control_media(options = {}) ⇒ Object



98
99
100
# File 'lib/remotedroid/control.rb', line 98

def control_media(options={})      
  http_exec 'media-' + options[:option].downcase.gsub(/\W/,'-')
end

#disable_airplane_modeObject



102
103
104
# File 'lib/remotedroid/control.rb', line 102

def disable_airplane_mode()
  http_exec 'set-airplane-mode', {state: 1}
end

#disable_bluetoothObject



106
107
108
# File 'lib/remotedroid/control.rb', line 106

def disable_bluetooth()
  http_exec 'set-bluetooth', {state: 1}
end

#disable_macro(macro) ⇒ Object



110
111
112
# File 'lib/remotedroid/control.rb', line 110

def disable_macro(macro)
  http_exec 'disable-macro', {name: macro}
end

#disable_wifiObject



114
115
116
# File 'lib/remotedroid/control.rb', line 114

def disable_wifi()
  http_exec 'set-wifi', {state: 1}
end

#enable_airplane_modeObject



118
119
120
# File 'lib/remotedroid/control.rb', line 118

def enable_airplane_mode()
  http_exec 'set-airplane-mode', {state: 0}
end

#enable_bluetoothObject



122
123
124
# File 'lib/remotedroid/control.rb', line 122

def enable_bluetooth()
  http_exec 'set-bluetooth', {state: 0}
end

#enable_macro(macro) ⇒ Object



126
127
128
# File 'lib/remotedroid/control.rb', line 126

def enable_macro(macro)
  http_exec 'enable-macro', {name: macro}
end

#enable_wifiObject



130
131
132
# File 'lib/remotedroid/control.rb', line 130

def enable_wifi()
  http_exec 'set-wifi', {state: 0}
end

#fill_clipboard(options = {}) ⇒ Object



134
135
136
# File 'lib/remotedroid/control.rb', line 134

def fill_clipboard(options={})
  http_exec 'fill-clipboard', options
end

#force_macro_run(options = {}) ⇒ Object



138
139
140
# File 'lib/remotedroid/control.rb', line 138

def force_macro_run(options={})
  http_exec option[:macro_name].downcase.gsub(/ /,'-')
end

#hotspot(state = nil) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/remotedroid/control.rb', line 142

def hotspot(state=nil)      
  
  if state then
    http_exec 'hotspot', {enable: state == :enable} 
  else        

    def self.enable()
      http_exec 'hotspot', {enable: true}
    end                
    
    def self.on()
      self.enable
    end                
    
    def self.disable()
      http_exec 'hotspot', {enable: false} 
    end
    
    def self.off()
      self.disable
    end         
    
    self
    
  end
end

#http_exec(command, options = {}) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/remotedroid/control.rb', line 169

def http_exec(command, options={})
  
  url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
  
  if options and options.any? then
    h = options
    url += '?' + \
        URI.escape(h.map {|key,value| "%s=%s" % [key, value]}.join('&'))
  end
  
  s = open(url).read
  
end

#launch_activity(options = {app: ''}) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/remotedroid/control.rb', line 183

def launch_activity(options={app: ''})
  
  return if options[:app].empty?
  
  app = options[:app]
  
  package = APPS[app]
  
  if package then
    launch_package package: package
  else       
    r = APPS.find {|k,v| k =~ /#{app}/i}
    launch_package(package: r[1]) if r
  end      
  
end

#launch_package(options = {package: 'com.google.android.chrome'}) ⇒ Object



200
201
202
# File 'lib/remotedroid/control.rb', line 200

def launch_package(options={package: 'com.google.android.chrome'})
  http_exec 'launch-by-package', options
end

#location(options = {}) ⇒ Object



204
205
206
# File 'lib/remotedroid/control.rb', line 204

def location(options={})
  http_exec 'location'
end

#method_missing2(method_name, *args) ⇒ Object



387
388
389
# File 'lib/remotedroid/control.rb', line 387

def method_missing2(method_name, *args)
  http_exec(method_name, args.first)
end

#open_web_page(options = {url: ''}) ⇒ Object Also known as: open_website, goto, visit



208
209
210
# File 'lib/remotedroid/control.rb', line 208

def open_web_page(options={url: ''})
  http_exec 'open-web-page', options
end

#say_current_time(options = {}) ⇒ Object Also known as: say_time



216
217
218
# File 'lib/remotedroid/control.rb', line 216

def say_current_time(options={})
  http_exec 'say-current-time'
end

#screen(state = nil) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/remotedroid/control.rb', line 222

def screen(state=nil)      
  
  if state then
    http_exec 'screen', {on: state == :on} 
  else        
    
    def self.on()
      http_exec 'screen', {on: true}
    end
    
    def self.off()
      http_exec 'screen', {on: false} 
    end
    
    self
    
  end
end

#set_auto_rotate(state = nil) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/remotedroid/control.rb', line 241

def set_auto_rotate(state=nil)
  
  if state then
    http_exec 'set-auto-rotate', {state: state} 
  else        
    
    def self.on()
      http_exec 'set-auto-rotate', {state: 0}
    end
    
    def self.off()
      http_exec 'set-auto-rotate', {state: 1} 
    end
    
    def self.toggle()
      http_exec 'set-auto-rotate', {state: 2} 
    end        
    
    self
    
  end      
end

#share_location(options = {}) ⇒ Object



264
265
266
# File 'lib/remotedroid/control.rb', line 264

def share_location(options={})
  http_exec 'share-location'
end

#speak_text(obj) ⇒ Object Also known as: say



268
269
270
271
272
273
274
275
276
277
278
# File 'lib/remotedroid/control.rb', line 268

def speak_text(obj)
  
  options = case obj
  when String
    {text: obj}
  when Hash
    obj
  end

  http_exec 'speak-text', options
end

#stay_awake(options = {}) ⇒ Object



282
283
284
# File 'lib/remotedroid/control.rb', line 282

def stay_awake(options={})
  http_exec 'stay-awake', options
end

#stay_awake_off(options = {}) ⇒ Object



286
287
288
# File 'lib/remotedroid/control.rb', line 286

def stay_awake_off(options={})
  http_exec 'stay-awake-off', options
end

#take_picture(options = {}) ⇒ Object Also known as: take_photo



290
291
292
# File 'lib/remotedroid/control.rb', line 290

def take_picture(options={})
  http_exec 'take-picture', options
end

#take_screenshot(options = {}) ⇒ Object



296
297
298
# File 'lib/remotedroid/control.rb', line 296

def take_screenshot(options={})
  http_exec 'take-screenshot', options
end

#toast(options = {}) ⇒ Object



300
301
302
# File 'lib/remotedroid/control.rb', line 300

def toast(options={})
  http_exec :toast, options
end

#torch(options = {}) ⇒ Object



304
305
306
# File 'lib/remotedroid/control.rb', line 304

def torch(options={})
  http_exec :torch 
end

#vibrate(options = {}) ⇒ Object



308
309
310
# File 'lib/remotedroid/control.rb', line 308

def vibrate(options={})
  http_exec :vibrate
end

#voice_search(options = {}) ⇒ Object



312
313
314
# File 'lib/remotedroid/control.rb', line 312

def voice_search(options={})
  http_exec 'voice-search'
end

#wifiObject



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/remotedroid/control.rb', line 316

def wifi()
  
  def self.enable()
    http_exec 'set-wifi', {state: 0}
  end                
  
  def self.on()
    self.enable
  end                
  
  def self.disable()
    http_exec 'set-wifi', {state: 1}
  end
  
  def self.off()
    self.disable
  end         
  
  def self.toggle()
    http_exec 'set-wifi', {state: 2}
  end      
  
  self
end

#write(s) ⇒ Object Also known as: export



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/remotedroid/control.rb', line 341

def write(s)
        
  d = MacroDroid.new(RD_MACROS, deviceid: @deviceid, 
                 remote_url: @remote_url, debug: false)
  
  a = d.macros.select do |macro|
    
    macro.triggers.find {|trigger| trigger.is_a? WebHookTrigger }.nil?
    
  end
  puts 'a: ' + a.length.inspect
  
  aux_macros = %w(Disable Enable).map do |state|
    
    rows = a[1..-1].map do |macro|
    
"  Else If name = #{macro.title}
#{state} macro
  #{macro.title}"
    end

    "
m: #{state} macro
v: name
t: webhook
a:
  If name = #{a[0].title}
#{state} macro
  #{a[0].title}
#{rows.join("\n")}
  End If
"     end

  puts aux_macros.join
  d.import aux_macros.join
  
  # disable the non-webhook triggers by default
  a.each(&:disable)
  
  d.export s
  puts 'exported to ' + s
  
end