Install atom command asynchronously

This commit is contained in:
Kevin Sawicki
2013-04-23 11:03:55 -07:00
parent b27b0c7d4f
commit 2f5a99fac2
3 changed files with 27 additions and 8 deletions

View File

@@ -165,8 +165,12 @@ describe "Window", ->
it "copies atom.sh to the specified path", ->
expect(fsUtils.exists(commandPath)).toBeFalsy()
window.installAtomCommand(commandPath)
expect(fsUtils.exists(commandPath)).toBeTruthy()
expect(fsUtils.read(commandPath).length).toBeGreaterThan 1
waitsFor ->
fsUtils.exists(commandPath)
runs ->
expect(fsUtils.read(commandPath).length).toBeGreaterThan 1
describe ".deserialize(state)", ->
class Foo

View File

@@ -72,13 +72,21 @@ window.shutdown = ->
window.project = null
window.git = null
window.installAtomCommand = (commandPath) ->
return if fsUtils.exists(commandPath)
window.installAtomCommand = (commandPath, done) ->
fs.exists commandPath, (exists) ->
return if exists
bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh')
if bundledCommandPath?
fsUtils.write(commandPath, fsUtils.read(bundledCommandPath))
fs.chmod(commandPath, 0o755, commandPath)
bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh')
if bundledCommandPath?
fs.readFile bundledCommandPath, (error, data) ->
if error?
console.warn "Failed to install `atom` binary", error
else
fsUtils.writeAsync commandPath, data, (error) ->
if error?
console.warn "Failed to install `atom` binary", error
else
fs.chmod(commandPath, 0o755, commandPath)
window.handleWindowEvents = ->
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()

View File

@@ -155,6 +155,13 @@ module.exports =
mkdirp.sync(@directory(path))
fs.writeFileSync(path, content)
writeAsync: (path, content, callback) ->
mkdirp @directory(path), (error) ->
if error?
callback?(error)
else
fs.writeFile(path, content, callback)
makeDirectory: (path) ->
fs.mkdirSync(path)