From 157a9d8c03baa8d19528fc9e57a0df61798c365e Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Wed, 10 Jul 2024 06:47:18 -0700 Subject: [PATCH] New item for develop menu: Open in iTerm --- .../Views/Sidebar/MyPlanetSidebarItem.swift | 22 +++++++++++++++++++ Planet/versioning.xcconfig | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift index 7ac4f931..a8f03fb4 100644 --- a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift +++ b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift @@ -243,6 +243,10 @@ struct MyPlanetSidebarItem: View { } } + private func hasiTerm() -> Bool { + NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.googlecode.iterm2") != nil + } + private func hasWorldWideWeb() -> Bool { NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.iconfactory.WorldWideWeb") != nil @@ -328,6 +332,15 @@ struct MyPlanetSidebarItem: View { ) } + private func openiTerm(_ template: Template) { + guard + let appUrl = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.googlecode.iterm2") + else { return } + + let url = URL(fileURLWithPath: template.path.path) + NSWorkspace.shared.open([url], withApplicationAt: appUrl, configuration: self.openConfiguration(), completionHandler: nil) + } + @ViewBuilder private func copyMenu() -> some View { Button { @@ -415,6 +428,15 @@ struct MyPlanetSidebarItem: View { } } + if hasiTerm(), let template = planet.template { + Button { + openiTerm(template) + } label: { + Image(systemName: "apple.terminal") + Text("Open in iTerm") + } + } + if let enabled = planet.pinnableEnabled, enabled { Button { Task(priority: .background) { diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 559cade4..ca1a48d1 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2127 +CURRENT_PROJECT_VERSION = 2128