-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_scale.rb
69 lines (57 loc) · 1.63 KB
/
display_scale.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
require_relative 'packages'
require_relative 'ruby_utils'
require 'open3'
class DisplayScale
def self.name
'display_scale'
end
# Not all devices have these options in system settings, but no reason
# we can't mimic here
def self.scales
{
'small' => 0.85,
'default' => 1,
'large' => 1.1,
'larger' => 1.2,
'largest' => 1.30
}
end
def self.perform(*args)
scale = args[0]
return unless validate_scale_input(scale)
if scale == 'default'
puts 'Resetting density'
Open3.capture2('adb shell wm density reset')
return
end
compute_and_set_new_density(scale)
end
def self.compute_and_set_new_density(scale)
# must set absolute density. which we can compute from 'physical' density
scale_float = scales[scale]
std_out, _status = Open3.capture2('adb shell wm density')
# find row containing "Physical density: xxxxx"
match = 'Physical density: '
physical_density = std_out
.as_array
.find { |row| row.include?(match) }
.sub(match, '')
new_density = (physical_density.to_f * scale_float).to_i
puts "Setting new density to #{new_density}"
Open3.capture2("adb shell wm density #{new_density}")
end
def self.similar_sounding_commands
%w[size display density scale accessibility]
end
def self.validate_scale_input(scale)
if scale.nil? || !scales.key?(scale)
puts "Unknown scale: #{scale}. Choices are: "
scales.each_key do |key|
puts " #{key}"
end
return false
end
true
end
end