summaryrefslogtreecommitdiff
path: root/Sources/BubombCore/Executors/URLLauncher.swift
diff options
context:
space:
mode:
authorgigagamerchaddhruv-spec <gigagamerchaddhruv-spec@users.noreply.github.com>2026-10-14 20:18:20 +0530
committergigagamerchaddhruv-spec <gigagamerchaddhruv-spec@users.noreply.github.com>2026-10-14 20:18:20 +0530
commitaceca8b5dfc8edd378ee9ff891bccb0f94c69f31 (patch)
tree08401ce8d050afbbe77514f479601a8e9535f4ec /Sources/BubombCore/Executors/URLLauncher.swift
feat: launch Bubomb - native macOS menu bar utility ('Configure the boom')HEADmain
Diffstat (limited to 'Sources/BubombCore/Executors/URLLauncher.swift')
-rw-r--r--Sources/BubombCore/Executors/URLLauncher.swift45
1 files changed, 45 insertions, 0 deletions
diff --git a/Sources/BubombCore/Executors/URLLauncher.swift b/Sources/BubombCore/Executors/URLLauncher.swift
new file mode 100644
index 0000000..c56e121
--- /dev/null
+++ b/Sources/BubombCore/Executors/URLLauncher.swift
@@ -0,0 +1,45 @@
+import Foundation
+#if canImport(AppKit)
+import AppKit
+#endif
+
+/// Validates and opens URLs in the user's default web browser.
+public final class URLLauncher: Sendable {
+ public init() {}
+
+ public func open(urlString: String) async throws -> ExecutionResult {
+ let startTime = Date()
+ let validatedURL = try PathValidator.validateURL(urlString).get()
+
+ var success = false
+
+ #if canImport(AppKit)
+ success = await MainActor.run {
+ NSWorkspace.shared.open(validatedURL)
+ }
+ #endif
+
+ if !success {
+ // Fallback to /usr/bin/open if NSWorkspace is not available or failed
+ let runner = ProcessRunner()
+ let result = try await runner.run(
+ executableURL: URL(fileURLWithPath: "/usr/bin/open"),
+ arguments: [validatedURL.absoluteString]
+ )
+ return ExecutionResult(
+ exitCode: result.exitCode,
+ stdout: "Opened \(validatedURL.absoluteString) via open tool",
+ stderr: result.stderr,
+ duration: Date().timeIntervalSince(startTime)
+ )
+ }
+
+ let duration = Date().timeIntervalSince(startTime)
+ return ExecutionResult(
+ exitCode: 0,
+ stdout: "Successfully opened URL: \(validatedURL.absoluteString)",
+ stderr: "",
+ duration: duration
+ )
+ }
+}