Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revised Shoes launcher app
  • Loading branch information
jasonrclark committed Nov 28, 2017
1 parent cdabd2d commit 6e69ed8
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -48,6 +48,7 @@ docs-*
spec/test_app/pkg
testing
tmp/*
app/tmp/*
bin/shoes-backend
shoes-core/bin/shoes-backend

Expand Down
5 changes: 0 additions & 5 deletions app/app.yaml

This file was deleted.

42 changes: 42 additions & 0 deletions app/build-mac
@@ -0,0 +1,42 @@
#!/usr/bin/env sh

JRUBY_VERSION=$(cat ../.ruby-version | sed 's/jruby-//')
SHOES_VERSION=$(cat ../VERSION)

echo "Building for JRuby $JRUBY_VERSION and Shoes $SHOES_VERSION"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Make a place to work in...
mkdir -p $DIR/tmp

BUILD_DIR=$DIR/tmp/Shoes4.app
rm -rf $BUILD_DIR

cp -r $DIR/mac-template $BUILD_DIR
pushd $BUILD_DIR

# Put the Shoes app in there
mkdir -p ./Contents/PlugIns/Shoes
cp ../../*.rb ./Contents/Plugins/Shoes
cp ../../*.png ./Contents/Plugins/Shoes

# Get our app script templated out right
sed "s/@@JRUBY_VERSION@@/jruby-$JRUBY_VERSION/g" ./Contents/MacOS/app.template > ./Contents/MacOS/app
chmod +x ./Contents/MacOS/app

# Get me a JRuby
curl -s https://repo1.maven.org/maven2/org/jruby/jruby-dist/$JRUBY_VERSION/jruby-dist-$JRUBY_VERSION-bin.tar.gz > ./Contents/PlugIns/jruby.tar.gz
tar -C ./Contents/PlugIns -xvf ./Contents/PlugIns/jruby.tar.gz

# Get me some Shoes!
./Contents/PlugIns/jruby-$JRUBY_VERSION/bin/jruby -S gem install shoes -v $SHOES_VERSION

# Clean up after ourselves
rm ./Contents/PlugIns/jruby.tar.gz
rm ./Contents/MacOS/*.template

cd ..
tar -czf Shoes4-mac.tar.gz Shoes4.app

popd
32 changes: 32 additions & 0 deletions app/mac-template/Contents/Info.plist
@@ -0,0 +1,32 @@
<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>app</string>
<key>CFBundleIconFile</key>
<string>Shoes.icns</string>
<key>CFBundleIdentifier</key>
<string>com.hackety.shoes.exampleapp</string>
<key>CFBundleDisplayName</key>
<string>Shoes App</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Shoes App</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.entertainment</string>
</dict>
</plist>
33 changes: 33 additions & 0 deletions app/mac-template/Contents/MacOS/app.template
@@ -0,0 +1,33 @@
#! /usr/bin/env bash

JRUBY_VERSION="@@JRUBY_VERSION@@"
JRE_VERSION="jre1.8.0_131"

JRUBY_COMMAND="jruby -J-XstartOnFirstThread"
SHOES_COMMAND="$JRUBY_COMMAND -S shoes-swt"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PLUGIN_DIR="$DIR/../PlugIns"

export PATH="$PLUGIN_DIR/$JRUBY_VERSION/bin:$PATH"

# Check if we've got java available, download if not
java -version > /dev/null
if [ $? != 0 ]; then

# See if we already have a downloaded JRE we can use
if [ ! -d ~/.shoes/jre ]; then
mkdir -p ~/.shoes

# Download a JRE
pushd ~/.shoes
curl -L https://github.com/shoes/mac-app-templates/releases/download/$JRE_VERSION/$JRE_VERSION.tar.gz > jre.tar.gz
tar -zxvf jre.tar.gz
mv ~/.shoes/$JRE_VERSION.jre ~/.shoes/jre
popd
fi

export JAVA_HOME=~/.shoes/jre/Contents/Home/
fi

$SHOES_COMMAND $DIR/../PlugIns/Shoes/shoes_app.rb
1 change: 1 addition & 0 deletions app/mac-template/Contents/PkgInfo
@@ -0,0 +1 @@
APPL????
Binary file added app/mac-template/Contents/Resources/Shoes.icns
Binary file not shown.
@@ -0,0 +1,3 @@
"JRELoadError" = "Unable to load Java Runtime Environment.";
"MainClassNameRequired" = "Main class name is required.";
"JavaDirectoryNotFound" = "Unable to enumerate Java directory contents.";
24 changes: 16 additions & 8 deletions app/shoes_app.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'thread'
require 'bundler'
require 'English'

class ShoesApp < Shoes
Expand All @@ -19,6 +20,8 @@ def self.packaging_app
end

def self.notice_packaging_error(message)
Shoes.logger.error message

@packaging_error = message
ShoesApp.navigation.push "/error_packaging"
end
Expand All @@ -45,7 +48,6 @@ def home
tagline link("Open an app") { open_app }, align: "center"
tagline link("Read the manual") { manual }, align: "center"
tagline link("Package an app") { visit "/start_packaging" }, align: "center"
para "(requires shoes gem for now)\n", align: "center"
para ""
para Shoes::VERSION, align: "center"
para "Press Alt+/ for Console", align: "center"
Expand All @@ -62,11 +64,8 @@ def home
end

def start_packaging
`which shoes`
unless $CHILD_STATUS.success?
ShoesApp.notice_packaging_error("We couldn't find shoes command installed.\n Check https://github.com/shoes/shoes4 for install instructions.")
app.visit "/error_packaging"
end
jruby_command = ENV["JRUBY_COMMAND"] || "jruby"
shoes_command = ENV["SHOES_COMMAND"] || "#{jruby_command} -S shoes-swt"

pictures
stack width: 600, margin_left: 200, margin_top: 170 do
Expand All @@ -90,9 +89,18 @@ def start_packaging
# Be careful, and plumb things through ShoesApp.navigation, etc.
Thread.new do
begin
# TODO: Get this to work in process...
output = ""

app_dir = File.dirname(ShoesApp.packaging_app)
output = `cd '#{app_dir}' && shoes #{args.join(" ")}`
Bundler.with_clean_env do
if File.exist?(File.join(app_dir, "Gemfile"))
puts "cd '#{app_dir}' && #{jruby_command} -S bundle install && bundle exec #{shoes_command} #{args.join(" ")} 2>&1"
output = `cd '#{app_dir}' && #{jruby_command} -S bundle install && bundle exec #{shoes_command} #{args.join(" ")} 2>&1`
else
puts "cd '#{app_dir}' && #{shoes_command} #{args.join(" ")} 2>&1"
output = `cd '#{app_dir}' && #{shoes_command} #{args.join(" ")} 2>&1`
end
end

if $CHILD_STATUS.success?
ShoesApp.navigation.push "/done_packaging"
Expand Down

0 comments on commit 6e69ed8

Please sign in to comment.