Skip to content

Commit

Permalink
Using NSWorkspace to open playgrounds after creation (Closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Dec 9, 2016
1 parent 2fdb081 commit 0512b11
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions PACore/Source/PlayAlways.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct PlayAlways {
return false
}

public func createPlayground(fileName: String? = nil, atDestination: String? = nil) throws {
public func createPlayground(fileName: String? = nil, atDestination: String? = nil) throws -> URL {

// essencial Playground structure:
// |- folder with name.playground
Expand All @@ -100,7 +100,7 @@ public struct PlayAlways {
writeFile("contents.xcplayground", at: playgroundDir.path, content: contentHeader) &&
writeFile("Contents.swift", at: playgroundDir.path, content: importHeader) {

return
return playgroundDir
}

throw PlaygroundError.creation
Expand Down
10 changes: 8 additions & 2 deletions PlayAways/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ final class AppRouter {
}

private func createPlayground(for platform: PlaygroundPlatform, at location: URL?) {
var playgroundUrl: URL?

if let location = location {
let directory = location.deletingLastPathComponent().path
let name = location.deletingPathExtension().lastPathComponent

do {
try playgroundMaker.createPlayground(named: name, at: directory, platform: platform)
playgroundUrl = try playgroundMaker.createPlayground(named: name, at: directory, platform: platform)
} catch {
handle(error)
}
Expand All @@ -78,11 +80,15 @@ final class AppRouter {
let directory = FinderHelper.getFrontmostFinderWindowLocation(fallback: desktopDir)

do {
try playgroundMaker.createPlayground(named: nil, at: directory, platform: platform)
playgroundUrl = try playgroundMaker.createPlayground(named: nil, at: directory, platform: platform)
} catch {
handle(error)
}
}

if let url = playgroundUrl {
NSWorkspace.shared().open(url)
}
}

private func handle(_ error: Error) {
Expand Down
4 changes: 2 additions & 2 deletions PlayAways/PlayAlwaysMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import PACore

final class PlayAlwaysMaker: PlaygroundMaker {

func createPlayground(named name: String?, at destination: String, platform: PlaygroundPlatform) throws {
func createPlayground(named name: String?, at destination: String, platform: PlaygroundPlatform) throws -> URL {
let maker = PlayAlways(platform: platform.rawValue)
try maker.createPlayground(fileName: name, atDestination: destination)
return try maker.createPlayground(fileName: name, atDestination: destination)
}

}
2 changes: 1 addition & 1 deletion PlayAways/PlaygroundMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public enum PlaygroundPlatform: String {
}

protocol PlaygroundMaker {
func createPlayground(named name: String?, at destination: String, platform: PlaygroundPlatform) throws
func createPlayground(named name: String?, at destination: String, platform: PlaygroundPlatform) throws -> URL
}

0 comments on commit 0512b11

Please sign in to comment.