From d35c871e17aa02c42395a8563d4e3f7e1433e56c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Feb 2013 20:49:37 -0800 Subject: [PATCH] Install atom executable during window.startup() 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 #300 --- Rakefile | 38 -------------------------------- atom.sh | 24 ++++++++++++++++++++ native/atom_window_controller.mm | 11 +++++++++ script/copy-files-to-bundle | 2 +- spec/app/window-spec.coffee | 13 +++++++++++ src/app/window.coffee | 10 +++++++++ 6 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 atom.sh diff --git a/Rakefile b/Rakefile index 5ae1b6908..fa31711e1 100644 --- a/Rakefile +++ b/Rakefile @@ -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" @@ -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 diff --git a/atom.sh b/atom.sh new file mode 100644 index 000000000..c66ad2538 --- /dev/null +++ b/atom.sh @@ -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 diff --git a/native/atom_window_controller.mm b/native/atom_window_controller.mm index 359cdd210..84c02d21e 100644 --- a/native/atom_window_controller.mm +++ b/native/atom_window_controller.mm @@ -33,6 +33,17 @@ 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]; } diff --git a/script/copy-files-to-bundle b/script/copy-files-to-bundle index 60c72b02f..67dfed4c4 100755 --- a/script/copy-files-to-bundle +++ b/script/copy-files-to-bundle @@ -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" diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index f229e426e..32f9397f1 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -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 diff --git a/src/app/window.coffee b/src/app/window.coffee index 2895d68f3..b401bcb66 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -1,5 +1,6 @@ fs = require 'fs' $ = require 'jquery' +ChildProcess = require 'child-process' require 'jquery-extensions' require 'underscore-extensions' require 'space-pen-extensions' @@ -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() @@ -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()