Skip to content

Commit

Permalink
Scripts to build "native" apps
Browse files Browse the repository at this point in the history
Use nativefier to wrap the beehive binary and build a desktop app.
  • Loading branch information
rubiojr committed Sep 28, 2017
1 parent 7f1664f commit b065e8d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
26 changes: 26 additions & 0 deletions script/build-app
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Build "native" desktop app using nativefier
# https://github.com/jiahaog/nativefier
set -e

if !which nativefier >/dev/null 2>&1; then
echo "nativefier not found!" >&2
echo "npm install -g nativifier" >&2
exit 1
fi

export BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd )"
export OS_NAME=$(node -e "console.log(os.platform())")
export OS_ARCH=$(node -e "console.log(os.arch())")

if [ ! -f $BASE_PATH/script/build-app-$OS_NAME ]; then
echo "$OS_NAME is not currently supported." >&2
exit 1
fi

if [ ! -f beehive ]; then
echo "Run 'make embed' first." >&2
exit 1
fi

$BASE_PATH/script/build-app-$OS_NAME
70 changes: 70 additions & 0 deletions script/build-app-darwin
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
set -e

cleanup_macos() {
if [ -f "$icns_file" ]; then
rm -f $icns_file
fi
}

trap cleanup_macos EXIT

ELECTRON_VERSION=${ELECTRON_VERSION:-1.6.14}
BIN_PATH=build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/MacOS
RES_PATH=build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/Resources
icns_file=$($BASE_PATH/script/build-icns)
nativefier -e $ELECTRON_VERSION --icon $icns_file --name Beehive http://localhost:8181 $BASE_PATH/build/app
mkdir -p $RES_PATH
cp beehive $BIN_PATH/beehived
chmod +x $BIN_PATH/beehived
mv $BIN_PATH/Beehive $BIN_PATH/Beehive.bin

cat > $BIN_PATH/Beehive << "EOF"
#!/bin/bash
set -e
BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )"
RES_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../Resources" && pwd )"
LIBRARY_PATH=$HOME/Library/Application\ Support/Beehive
LA_PLIST=$HOME/Library/LaunchAgents/com.github.muesli.beehive.plist
mkdir -p "$LIBRARY_PATH"
cp $RES_PATH/launchagent.plist $LA_PLIST
sed -i '' s/@@user@@/$USER/ $LA_PLIST
sed -i '' s,@@bin_path@@,$BASE_PATH/beehived, $LA_PLIST
launchctl load $LA_PLIST
# Wait a bit for beehived to be ready
for i in $(seq 20); do
s=$(curl -s -o /dev/null -w "%{http_code}" localhost:8181)
[ "$s" = 200 ] && break
sleep 0.1
done
$BASE_PATH/Beehive.bin
EOF
chmod +x build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/MacOS/Beehive

cat > $RES_PATH/launchagent.plist << "EOF"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.muesli.beehive</string>
<key>ProgramArguments</key>
<array>
<string>@@bin_path@@</string>
<string>--config</string>
<string>/Users/@@user@@/Library/Application Support/Beehive/beehive.conf</string>
</array>
<key>KeepAlive</key>
<true/>
<key>LowPriorityIO</key>
<true/>
<key>ProcessType</key>
<string>Background</string>
</dict>
</plist>
EOF
30 changes: 30 additions & 0 deletions script/build-icns
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

tmpd=$TMPDIR/beehive.iconset
icns=$TMPDIR/beehive.icns
logfile=$TMPDIR/build-icns.log

cleanup() {
rm -rf $tmpd
rm -f $logfile
}

trap cleanup EXIT

{
mkdir $tmpd
sips -z 16 16 assets/logo.png --out $tmpd/icon_16x16.png
sips -z 32 32 assets/logo.png --out $tmpd/[email protected]
sips -z 32 32 assets/logo.png --out $tmpd/icon_32x32.png
sips -z 64 64 assets/logo.png --out $tmpd/[email protected]
sips -z 128 128 assets/logo.png --out $tmpd/icon_128x128.png
sips -z 256 256 assets/logo.png --out $tmpd/[email protected]
sips -z 256 256 assets/logo.png --out $tmpd/icon_256x256.png
sips -z 512 512 assets/logo.png --out $tmpd/[email protected]
sips -z 512 512 assets/logo.png --out $tmpd/icon_512x512.png
cp assets/logo.png $tmpd/[email protected]
iconutil -c icns $tmpd
} > $logfile 2>&1

echo $icns

0 comments on commit b065e8d

Please sign in to comment.