Skip to content

Commit

Permalink
Install atom executable during window.startup()
Browse files Browse the repository at this point in the history
Previously this was done during `rake install`.

Also default to `~/github/atom` as the default resource path
when no `--resource-path` argument is specified.  This argument
will now be required when running in dev mode if the repository
is not at the default location.

Closes atom#300
  • Loading branch information
kevinsawicki committed Feb 23, 2013
1 parent c7ff431 commit d35c871
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 39 deletions.
38 changes: 0 additions & 38 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ task :install => [:clean, :build] do
`rm -rf #{dest}`
`cp -r #{path} #{File.expand_path(dest)}`

# Install cli atom
usr_bin_path = "/opt/github/bin"
cli_path = "#{usr_bin_path}/atom"

template = ERB.new CLI_SCRIPT
namespace = OpenStruct.new(:application_path => dest, :resource_path => ATOM_SRC_PATH)
File.open(cli_path, "w") do |f|
f.write template.result(namespace.instance_eval { binding })
f.chmod(0755)
end

Rake::Task["clone-default-bundles"].invoke()

puts "\033[32mType `atom` to start Atom! In Atom press `cmd-,` to edit your `~/.atom` directory\033[0m"
Expand Down Expand Up @@ -130,30 +119,3 @@ def application_path

return nil
end

CLI_SCRIPT = <<-EOF
#!/bin/sh
open -a Atom -n --args --resource-path="<%= resource_path %>" --executed-from="$(pwd)" --pid=$$ $@
# Used to exit process when atom is used as $EDITOR
on_die() {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
# Don't exit process if we were told to wait.
while [ "$#" -gt "0" ]; do
case $1 in
-W|--wait)
WAIT=1
;;
esac
shift
done
if [ $WAIT ]; then
while true; do
sleep 1
done
fi
EOF
24 changes: 24 additions & 0 deletions atom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
open -a Atom -n --args --executed-from="$(pwd)" --pid=$$ $@

# Used to exit process when atom is used as $EDITOR
on_die() {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM

# Don't exit process if we were told to wait.
while [ "$#" -gt "0" ]; do
case $1 in
-W|--wait)
WAIT=1
;;
esac
shift
done

if [ $WAIT ]; then
while true; do
sleep 1
done
fi
11 changes: 11 additions & 0 deletions native/atom_window_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ - (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)backg
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];

_resourcePath = [atomApplication.arguments objectForKey:@"resource-path"];
if (!alwaysUseBundleResourcePath && !_resourcePath) {
NSString *defaultRepositoryPath = @"~/github/atom";
defaultRepositoryPath = [defaultRepositoryPath stringByStandardizingPath];
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
BOOL isDir = false;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
if (isDir && exists)
_resourcePath = defaultRepositoryPath;
}
}

if (alwaysUseBundleResourcePath || !_resourcePath) {
_resourcePath = [[NSBundle mainBundle] resourcePath];
}
Expand Down
2 changes: 1 addition & 1 deletion script/copy-files-to-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ for CSON_FILE in $CSON_FILES; do
done;

# Copy non-coffee files into bundle
rsync --archive --recursive --exclude="src/**/*.coffee" --exclude="src/**/*.cson" src static vendor spec benchmark themes dot-atom "$RESOUCES_PATH"
rsync --archive --recursive --exclude="src/**/*.coffee" --exclude="src/**/*.cson" src static vendor spec benchmark themes dot-atom atom.sh "$RESOUCES_PATH"
13 changes: 13 additions & 0 deletions spec/app/window-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,16 @@ describe "Window", ->
window.shutdown()
window.shutdown()
expect(atom.setRootViewStateForPath.callCount).toBe 1

describe ".installAtomCommand(commandPath)", ->
commandPath = '/tmp/installed-atom-command/atom'

afterEach ->
fs.remove(commandPath) if fs.exists(commandPath)

describe "when the command path doesn't exist", ->
it "copies atom.sh to the specified path", ->
expect(fs.exists(commandPath)).toBeFalsy()
window.installAtomCommand(commandPath)
expect(fs.exists(commandPath)).toBeTruthy()
expect(fs.read(commandPath).length).toBeGreaterThan 1
10 changes: 10 additions & 0 deletions src/app/window.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fs = require 'fs'
$ = require 'jquery'
ChildProcess = require 'child-process'
require 'jquery-extensions'
require 'underscore-extensions'
require 'space-pen-extensions'
Expand Down Expand Up @@ -39,6 +40,7 @@ window.setUpEnvironment = ->

# This method is only called when opening a real application window
window.startup = ->
installAtomCommand('/opt/github/bin/atom')
handleWindowEvents()
config.load()
atom.loadTextPackage()
Expand All @@ -65,6 +67,14 @@ window.shutdown = ->
window.rootView = null
window.project = null

window.installAtomCommand = (commandPath) ->
return if fs.exists(commandPath)

bundledCommandPath = fs.resolve(window.resourcePath, 'atom.sh')
if bundledCommandPath?
fs.write(commandPath, fs.read(bundledCommandPath))
ChildProcess.exec("chmod u+x '#{commandPath}'")

window.handleWindowEvents = ->
$(window).on 'core:close', => window.close()
$(window).command 'window:close', => window.close()
Expand Down

0 comments on commit d35c871

Please sign in to comment.