remotedroid 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71e486b66042dfefbfff3717043ded61f7847043a4afc37f1bd7b215076e280b
4
- data.tar.gz: e7dee07206e7351a472fd9fb5c767979f7350f65630c7e1161dd7a14d1349347
3
+ metadata.gz: 3bc29943617484d1dd660a519cf38b3eb0658d69c8a2cadadc92f1f8fa7b036f
4
+ data.tar.gz: 9b529677442b0905636fddd8d0b985df57f0115d6b5861b958749917886bcdb3
5
5
  SHA512:
6
- metadata.gz: '08933909445d0ec11a57c9f3006ac9874db4a48d21602a56993505f6c5350acc566a4fb4171e9e2423bd41c2957f6ae5be8294c51f4551808d71f277b1aab2b1'
7
- data.tar.gz: 1b48179921c54abd6ad3d112c277133352a3496be7f092709f15463e5ced3418307d93b1aec0edc18167b16677541bea563c2116e8d0068a0becd2a365edc5dd
6
+ metadata.gz: efadc0c0d423e937603ade768551e8796d8d6061dbdc2cfaee3c2d4fa11befb711da2d9fc157a898969cfbe5c8b05106f4db212ee4d2f36e67f94d87f1345e2a
7
+ data.tar.gz: 43e65afff822006b49452d3633d2bc05e42c1cbdbe76fd3b264c8761426fad724085972be1b88376953d00ab0cd6d9bfccf2ae52e9f86f8ac55192f050f0d9e6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -30,16 +30,67 @@ require 'ruby-macrodroid'
30
30
  #
31
31
  # * Speak text
32
32
  # * Torch toggle
33
+ # * vibrate
33
34
  #
34
35
  # ## Location
35
36
  #
36
37
  # * Share Location
37
38
  #
39
+ # ## Media
40
+ #
41
+ # * Play sound (Doda)
42
+ #
38
43
  # ## Notification
39
44
  #
40
45
  # * Popup Message
41
46
  #
47
+ #
42
48
 
49
+ # Variables which can be queried
50
+ #
51
+ # Description Variable
52
+ # ------------------- ----------------
53
+ # Foreground app name :fg_app_name
54
+ # Foreground app package :fg_app_package
55
+ # Current Brightness :current_brightness
56
+ # Screen timeout (seconds) :screen_timeout
57
+ # Current battery % :battery
58
+ # Battery temp °C :battery_temp
59
+ # Power (On/Off) :power
60
+ # Clipboard text :clipboard
61
+ # Current IP address :ip
62
+ # Wifi SSID :ssid
63
+ # Wifi signal strength :wifi_strength
64
+ # System time :system_time
65
+ # IMEI :imei
66
+ # Cell Id :cell_id
67
+ # Last known location (lat,lon) :last_loc_latlong
68
+ # Last known location (altitude) :last_loc_alt
69
+ # Last known location (link) :last_loc_link
70
+ # Last known location (time) :last_loc_age_timestamp
71
+ # Last known location (kmh) :last_loc_speed_kmh
72
+ # Last known location (mph) :last_loc_speed_mph
73
+ # Current Volume (Alarm) :vol_alarm
74
+ # Current Volume (Media / Music) :vol_music
75
+ # Current Volume (Ringer) :vol_ring
76
+ # Current Volume (Notification) :vol_notif
77
+ # Current Volume (System Sounds) :vol_system
78
+ # Current Volume (Voice Call) :vol_call
79
+ # Current Volume (Bluetooth Voice) :vol_bt_voice
80
+ # Device name :device_name
81
+ # Device uptime :uptime_secs
82
+ # Device manufacturer :device_manufacturer
83
+ # Device model :device_model
84
+ # Android version :android_version
85
+ # Android version (SDK Level) :android_version_sdk
86
+ # Storage total (external) :storage_external_total
87
+ # Storage free (external) :storage_external_free
88
+ # Storage total (internal) :storage_internal_total
89
+ # Storage free (internal) :storage_internal_free
90
+
91
+
92
+ # The macros below are exported to JSON format as a file which is imported into
93
+ # the Android device running MacroDroid.
43
94
 
44
95
  RD_MACROS =<<EOF
45
96
  m: Camera flash light
@@ -66,6 +117,14 @@ v: text
66
117
  t: webhook
67
118
  a: speak text ([lv=text])
68
119
 
120
+ m: vibrate
121
+ t: webhook
122
+ a: vibrate
123
+
124
+ m: play doda
125
+ t: webhook
126
+ a: play: Doda
127
+
69
128
  m: Share location
70
129
  t:
71
130
  WebHook
@@ -80,6 +139,47 @@ a:
80
139
  coords: [lv=coords]
81
140
  type: query
82
141
 
142
+ m: query
143
+ t: WebHook
144
+ v: qvar
145
+ a:
146
+ Set Variable
147
+ var: [[lv=qvar]]
148
+ a:
149
+ HTTP GET
150
+ [lv=qvar]: [lv=var]
151
+
152
+ m: query setting system
153
+ t: WebHook
154
+ v: qvar
155
+ a:
156
+ Set Variable
157
+ var: [setting_system=[lv=qvar]]
158
+ a:
159
+ HTTP GET
160
+ [lv=qvar]: [lv=var]
161
+
162
+ m: query setting global
163
+ t: WebHook
164
+ v: qvar
165
+ a:
166
+ Set Variable
167
+ var: [setting_global=[lv=qvar]]
168
+ a:
169
+ HTTP GET
170
+ [lv=qvar]: [lv=var]
171
+
172
+ m: query setting secure
173
+ t: WebHook
174
+ v: qvar
175
+ a:
176
+ Set Variable
177
+ var: [setting_secure=[lv=qvar]]
178
+ a:
179
+ HTTP GET
180
+ [lv=qvar]: [lv=var]
181
+
182
+
83
183
  m: shake device
84
184
  t: shake device
85
185
  a: webhook
@@ -338,6 +438,7 @@ module RemoteDroid
338
438
  end
339
439
 
340
440
  @store = {}
441
+ @query = Query.new(self)
341
442
 
342
443
  end
343
444
 
@@ -346,7 +447,12 @@ module RemoteDroid
346
447
  end
347
448
 
348
449
  def invoke(name, options={})
349
- @control.method(name.to_sym).call(options)
450
+
451
+ if @control.respond_to? name.to_sym then
452
+ @control.method(name.to_sym).call(options)
453
+ else
454
+ @control.http_exec name.to_sym, options
455
+ end
350
456
  end
351
457
 
352
458
  # Object Property (op)
@@ -357,12 +463,33 @@ module RemoteDroid
357
463
  @model.op
358
464
  end
359
465
 
360
- def query(id)
466
+ def query(id=nil)
467
+
468
+ return @query unless id
361
469
 
362
470
  @store[id] = nil
471
+
472
+ sys = %i(accelerometer_rotation)
473
+
474
+ global = [:airplane_mode_on, :bluetooth_on, :cell_on, :device_name, \
475
+ :usb_mass_storage_enabled, :wifi_on]
476
+
477
+ secure = %i(bluetooth_name flashlight_enabled)
478
+
363
479
 
364
480
  # send http request via macrodroid.com API
365
- @control.http_exec id
481
+
482
+ if id.downcase.to_sym == :location then
483
+ @control.http_exec id
484
+ elsif sys.include? id
485
+ @control.http_exec :'query-setting-system', {qvar: id}
486
+ elsif global.include? id
487
+ @control.http_exec :'query-setting-global', {qvar: id}
488
+ elsif secure.include? id
489
+ @control.http_exec :'query-setting-secure', {qvar: id}
490
+ else
491
+ @control.http_exec :query, {qvar: id}
492
+ end
366
493
 
367
494
  # wait for the local variable to be updated
368
495
  # timeout after 5 seoncds
@@ -372,7 +499,8 @@ module RemoteDroid
372
499
  sleep 1
373
500
  end until @store[id] or Time.now > t + 5
374
501
 
375
-
502
+ return {warning: 'HTTP response timeout'} if Time.now > t+5
503
+
376
504
  return @store[id]
377
505
 
378
506
 
@@ -412,8 +540,9 @@ module RemoteDroid
412
540
 
413
541
  alias trigger_fired trigger
414
542
 
415
- def update(key, val)
416
- @store[key.to_sym] = val
543
+ def update(id, val)
544
+ key = id == :location ? id : val.keys.first.to_sym
545
+ @store[key] = val
417
546
  end
418
547
 
419
548
 
@@ -452,7 +581,7 @@ module RemoteDroid
452
581
 
453
582
  @deviceid, @remote_url, @debug = deviceid, remote_url, debug
454
583
  @torch = Torch.new(self)
455
- end
584
+ end
456
585
 
457
586
  def bluetooth()
458
587
  @bluetooth
@@ -490,10 +619,20 @@ module RemoteDroid
490
619
  http_exec 'share-location'
491
620
  end
492
621
 
493
- def speak_text(options={})
622
+ def speak_text(obj)
623
+
624
+ options = case obj
625
+ when String
626
+ {text: obj}
627
+ when Hash
628
+ obj
629
+ end
630
+
494
631
  http_exec 'speak-text', options
495
632
  end
496
633
 
634
+ alias say speak_text
635
+
497
636
  def toast(options={})
498
637
  http_exec :toast, options
499
638
  end
@@ -501,6 +640,10 @@ module RemoteDroid
501
640
  def torch(options={})
502
641
  http_exec :torch
503
642
  end
643
+
644
+ def vibrate(options={})
645
+ http_exec :vibrate
646
+ end
504
647
 
505
648
 
506
649
  def write(s)
@@ -512,12 +655,46 @@ module RemoteDroid
512
655
 
513
656
  alias export write
514
657
 
515
- def method_missing(method_name, *args)
658
+ def method_missing2(method_name, *args)
516
659
  http_exec(method_name, args.first)
517
660
  end
518
661
 
519
662
  end
520
663
 
664
+ class Query
665
+
666
+ def initialize(callback)
667
+ @callback = callback
668
+ end
669
+
670
+ def battery()
671
+ q(:battery).to_i
672
+ end
673
+
674
+ def current_brightness()
675
+ q(:current_brightness).to_i
676
+ end
677
+
678
+ alias brightness current_brightness
679
+
680
+ def cell_id()
681
+ q(:cell_id)
682
+ end
683
+
684
+ alias cell_tower cell_id
685
+
686
+ def ip()
687
+ q(:ip)
688
+ end
689
+
690
+ private
691
+
692
+ def q(id)
693
+ @callback.query(id)[id]
694
+ end
695
+
696
+ end
697
+
521
698
  class Server
522
699
 
523
700
  def initialize(s, drb_host: '127.0.0.1', deviceid: nil)
@@ -540,6 +717,10 @@ module RemoteDroid
540
717
  @drb = OneDrb::Client.new host: host, port: '5777'
541
718
  end
542
719
 
720
+ def control
721
+ @drb.control
722
+ end
723
+
543
724
  def export(s)
544
725
  @drb.export(s)
545
726
  end
@@ -548,8 +729,9 @@ module RemoteDroid
548
729
  @drb.invoke(s, *args)
549
730
  end
550
731
 
551
- def query(id)
732
+ def query(id=nil)
552
733
 
734
+ return @drb.query unless id
553
735
  t = Time.now
554
736
  h = @drb.query(id)
555
737
  h.merge({latency: (Time.now - t).round(3)})
@@ -620,8 +802,10 @@ module RemoteDroid
620
802
 
621
803
  super(topic: topic) do |msg|
622
804
 
623
- id, json = msg.split(/:\s+/,2)
624
- @remote.update id.to_sym, JSON.parse(json, symbolize_names: true)
805
+ json, id = msg.split(/:\s+/,2).reverse
806
+ h = JSON.parse(json, symbolize_names: true)
807
+ id ||= h.keys.first
808
+ @remote.update id.to_sym, h
625
809
 
626
810
  end
627
811
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotedroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  io3WPRDjULC924M5S8wbrus31v2AUjqFBPvmHr7caf/VHErWypV482xcDhWt1eif
36
36
  0G2k2ptozXcBS9odsqGUTb5N
37
37
  -----END CERTIFICATE-----
38
- date: 2020-10-06 00:00:00.000000000 Z
38
+ date: 2020-10-11 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: onedrb
@@ -106,7 +106,7 @@ dependencies:
106
106
  version: '0.9'
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 0.9.2
109
+ version: 0.9.5
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
@@ -116,7 +116,7 @@ dependencies:
116
116
  version: '0.9'
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 0.9.2
119
+ version: 0.9.5
120
120
  description:
121
121
  email: james@jamesrobertson.eu
122
122
  executables: []
metadata.gz.sig CHANGED
Binary file