diff --git a/PACore/Source/PlayAlways.swift b/PACore/Source/PlayAlways.swift index 8c3653a..67f82c0 100644 --- a/PACore/Source/PlayAlways.swift +++ b/PACore/Source/PlayAlways.swift @@ -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 @@ -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 diff --git a/PlayAways/AppRouter.swift b/PlayAways/AppRouter.swift index 8c43d04..d16d01a 100644 --- a/PlayAways/AppRouter.swift +++ b/PlayAways/AppRouter.swift @@ -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) } @@ -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) { diff --git a/PlayAways/PlayAlwaysMaker.swift b/PlayAways/PlayAlwaysMaker.swift index 9a1413b..3278c95 100644 --- a/PlayAways/PlayAlwaysMaker.swift +++ b/PlayAways/PlayAlwaysMaker.swift @@ -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) } } diff --git a/PlayAways/PlaygroundMaker.swift b/PlayAways/PlaygroundMaker.swift index 6e9e72b..30fb371 100644 --- a/PlayAways/PlaygroundMaker.swift +++ b/PlayAways/PlaygroundMaker.swift @@ -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 }