Skip to content

Commit 94bc056

Browse files
committed
Updated using BitBar v2 beta, including build dir
1 parent 6d7b682 commit 94bc056

File tree

9 files changed

+139
-26
lines changed

9 files changed

+139
-26
lines changed

build/build.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
DIR=~/github/ecobar
4+
BUILD_DIR=$DIR/build
5+
6+
ICON_SRC=$BUILD_DIR/icon/ecoBar.icns
7+
DMG_SRC=$BUILD_DIR/src/ecoBar.dmg DMG_DEST="$DIR/ecoBar.dmg"
8+
DMG_TMP=/tmp/tmp-ecoBar.dmg
9+
MNT_DIR="/Volumes/ecoBar Installer"
10+
BBD_DIR="$BUILD_DIR/src/BitBarDistro.app"
11+
APP_DIR="$MNT_DIR/ecoBar.app"
12+
INST_DIR="$APP_DIR/Contents/MacOS"
13+
14+
ECOBEE_DIR=~/github/ecobee/lib
15+
16+
echo Converting DMG
17+
hdiutil detach "$MNT_DIR"
18+
#hdiutil convert "$DMG_SRC" -format UDRW -ov -o "$DMG_TMP"
19+
cp "$DMG_SRC" "$DMG_TMP"
20+
hdiutil attach "$DMG_TMP"
21+
22+
#echo Removing old directories...
23+
#rm -rf "$INST_DIR/ecobee" "$INST_DIR/ecoBar.1m.rb" "$INST_DIR/eco_bar"
24+
25+
echo Copying BitBarDistro
26+
rm -rf "$APP_DIR"
27+
rsync -a "$BBD_DIR"/ "$APP_DIR"
28+
29+
echo Copying files in...
30+
rsync -a "$DIR/eco_bar" "$INST_DIR"
31+
cp "$DIR/ecoBar.rb" "$INST_DIR/ecoBar.1m.rb"
32+
rsync -a "$ECOBEE_DIR/" "$INST_DIR/ecobee"
33+
34+
echo Unsigning...
35+
xattr -rc "$APP_DIR"
36+
codesign --deep --force --verbose --sign - "$APP_DIR"
37+
#echo Signing...
38+
#codesign --deep --force --verbose --sign "Mac Developer: rob@zwissler.org (M3AY8937F4)" "$APP_DIR"
39+
40+
echo Applying icon
41+
# make icon it's own icon
42+
sips -i "$ICON_SRC"
43+
# extract to resource file
44+
DeRez -only icns "$ICON_SRC" > /tmp/icon.$$
45+
# append this resource to the file you want to icon-ize.
46+
Rez -append /tmp/icon.$$ -o "$APP_DIR"/$'Icon\r'
47+
# Use the resource to set the icon.
48+
#SetFile -a C "$APP_DIR"/Icon?
49+
SetFile -a C "$APP_DIR"/
50+
SetFile -a V "$APP_DIR"/$'Icon\r'
51+
rm /tmp/icon.$$
52+
53+
echo Verifying sign...
54+
codesign --verify --verbose "$APP_DIR"
55+
56+
sleep 3
57+
hdiutil detach "$MNT_DIR"
58+
#diskutil unmount "$MNT_DIR"
59+
sleep 2
60+
echo Converting...
61+
echo hdiutil convert "$DMG_TMP" -quiet -format UDZO -imagekey zlib-level=9 -ov -o "$DMG_DEST"
62+
hdiutil convert "$DMG_TMP" -format UDZO -imagekey zlib-level=9 -ov -o "$DMG_DEST"
63+
64+
#hdiutil create $DIR/ecoBar.dmg -volname "ecoBar Installer" -srcfolder $DIR/build/image
65+
66+
#Use hdiutil to attach the image
67+
#Use cp etc to copy the application into the mounted image
68+
#hdiutil detach
69+
#compress the image: hdiutil convert "in.dmg" -quiet -format UDZO -imagekey zlib-level=9 -o "MyApp-0.3.dmg"

build/icon/ecoBar.icns

356 KB
Binary file not shown.

build/icon/menubar-30.png

2.71 KB
Loading

build/icon/menubar.png

2.68 KB
Loading

ecoBar.dmg

36.9 KB
Binary file not shown.

ecoBar.rb

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,44 @@
1919
end
2020
require_relative 'eco_bar/eco_bar'
2121

22+
# ENV: {"BitBarDarkMode"=>"1", "BitBar"=>"1", "BitBarVersion"=>"2.0.0-beta10"}
23+
REFRESH = 10
24+
25+
def is_long_running?
26+
ENV['BitBarVersion'] =~ /^[2-9]\./ && $0.sub(/.*\//, '').count('.') < 2
27+
end
28+
29+
def write_single_output(ecobar)
30+
ecobar.header
31+
ecobar.setpoint_menu
32+
ecobar.weather
33+
ecobar.separator
34+
ecobar.name_menu
35+
ecobar.status
36+
ecobar.mode_menu
37+
ecobar.fan_mode
38+
ecobar.sensors
39+
ecobar.alerts
40+
ecobar.separator
41+
ecobar.website
42+
ecobar.separator
43+
ecobar.about
44+
end
45+
46+
def write_output(ecobar)
47+
if is_long_running?
48+
loop do
49+
write_single_output(ecobar)
50+
puts '~~~'
51+
STDOUT.flush
52+
sleep REFRESH
53+
ecobar = EcoBar::BarIO.new(index: @config['index'], token: @token)
54+
end
55+
else
56+
write_single_output(ecobar)
57+
end
58+
end
59+
2260
case arg = ARGV.shift
2361
when /^wipe_tokens/
2462
begin
@@ -106,18 +144,5 @@
106144
when /^set_fan_mode=/
107145
ecobar.thermostat.desired_fan_mode = arg.sub(/^.*=/, '')
108146
else
109-
ecobar.header
110-
ecobar.setpoint_menu
111-
ecobar.weather
112-
ecobar.separator
113-
ecobar.name_menu
114-
ecobar.status
115-
ecobar.mode_menu
116-
ecobar.fan_mode
117-
ecobar.sensors
118-
ecobar.alerts
119-
ecobar.separator
120-
ecobar.website
121-
ecobar.separator
122-
ecobar.about
147+
write_output ecobar
123148
end

eco_bar/eco_bar/bar_io.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ def fan_mode
7474
render "Fan Mode: #{Ecobee::FanMode(thermostat.desired_fan_mode)}"
7575
Ecobee::FAN_MODES.each do |mode|
7676
if mode == thermostat.desired_fan_mode
77-
render "--#{check true}#{Ecobee::FanMode(mode)}"
77+
render("--#{Ecobee::FanMode(mode)}", checked: true)
7878
else
79-
render("--#{check false}#{Ecobee::FanMode(mode)}",
79+
render("--#{Ecobee::FanMode(mode)}",
80+
checked: false,
8081
param1: "set_fan_mode=#{mode}",
8182
run_self: true)
8283
end
@@ -95,9 +96,10 @@ def mode_menu
9596
render "Mode: #{Ecobee::Mode(thermostat.mode)}"
9697
Ecobee::HVAC_MODES.each do |mode|
9798
if mode == thermostat.mode
98-
render "--#{check true}#{Ecobee::Mode(mode)}"
99+
render("--#{Ecobee::Mode(mode)}", checked: true)
99100
else
100-
render("--#{check false}#{Ecobee::Mode(mode)}",
101+
render("--#{Ecobee::Mode(mode)}",
102+
checked: false,
101103
param1: "set_mode=#{mode}",
102104
run_self: true)
103105
end
@@ -111,9 +113,10 @@ def name_menu
111113
thermostat = @thermostats[index]
112114

113115
if @index == index
114-
render "--#{check true}#{thermostat.name} (#{thermostat.model})"
116+
render("--#{thermostat.name} (#{thermostat.model})", checked: true)
115117
else
116-
render("--#{check false}#{thermostat.name} (#{thermostat.model})",
118+
render("--#{thermostat.name} (#{thermostat.model})",
119+
checked: false,
117120
param1: "set_index=#{index}",
118121
run_self: true)
119122
end
@@ -124,6 +127,13 @@ def name_menu
124127
def render(msg, arg = {})
125128
msg += '|'
126129
arg.merge!({:color => :dark}) unless arg[:color]
130+
if ENV['BitBarVersion'] =~ /^2\./ && arg[:checked] == true
131+
msg += " checked=true"
132+
elsif arg[:checked] == true
133+
msg.sub!(/^(-*)/, "\\1#{check true}")
134+
elsif ENV['BitBarVersion'] =~ /^1\./ && arg[:checked] == false
135+
msg.sub!(/^(-*)/, "\\1#{check false}")
136+
end
127137
msg += " #{arg[:attrib]}" if arg.key? :attrib
128138
msg += " bash=\"#{arg[:bash]}\"" if arg.key? :bash
129139
msg += " #{color(arg[:color])}" if arg.key? :color
@@ -170,9 +180,10 @@ def setpoint_menu
170180
def setpoint_menu_cool
171181
thermostat.cool_range(with_delta: true).reverse_each do |temp|
172182
if temp == thermostat.desired_cool
173-
render("--#{check true}#{temp}#{DEG}", color: :cold)
183+
render("--#{temp}#{DEG}", checked: true, color: :cold)
174184
else
175-
render("--#{check false}#{temp}#{DEG}",
185+
render("--#{temp}#{DEG}",
186+
checked: false,
176187
color: :cold,
177188
param1: "set_cool=#{temp}",
178189
run_self: true)
@@ -183,9 +194,10 @@ def setpoint_menu_cool
183194
def setpoint_menu_heat
184195
thermostat.heat_range(with_delta: true).reverse_each do |temp|
185196
if temp == thermostat.desired_heat
186-
render("--#{check true}#{temp}#{DEG}", color: :hot)
197+
render("--#{temp}#{DEG}", checked: true, color: :hot)
187198
else
188-
render("--#{check false}#{temp}#{DEG}",
199+
render("--#{temp}#{DEG}",
200+
checked: false,
189201
color: :hot,
190202
param1: "set_heat=#{temp}",
191203
run_self: true)

eco_bar/eco_bar/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module EcoBar
2-
VERSION = '0.1.11'
3-
DMG_VERSION = '0.1.11'
2+
VERSION = '0.2.00'
3+
DMG_VERSION = '0.2.00'
44
end

t.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'pp'
4+
5+
A = -> {|x| x + 1 }.freeze
6+
7+
pp A[2]

0 commit comments

Comments
 (0)