Pārlūkot izejas kodu

Add Indeed sidebar shortcut to open Indeed in-app or native app.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 2 nedēļas atpakaļ
vecāks
revīzija
e2c14def55
1 mainītis faili ar 62 papildinājumiem un 0 dzēšanām
  1. 62 0
      App for Indeed/Views/DashboardView.swift

+ 62 - 0
App for Indeed/Views/DashboardView.swift

@@ -948,6 +948,22 @@ final class DashboardView: NSView, NSTextFieldDelegate, NSSharingServicePickerDe
948 948
         return host.contains(".indeed.")
949 949
     }
950 950
 
951
+    private static let indeedBrowseHomeURL = URL(string: "https://www.indeed.com/")!
952
+
953
+    private static let externalIndeedAppURLSchemes = ["indeed://", "indeedjobs://"]
954
+
955
+    /// Opens the installed Indeed app when a handler is registered; otherwise loads Indeed in the embedded browser.
956
+    private func openIndeedFromSidebar() {
957
+        for scheme in Self.externalIndeedAppURLSchemes {
958
+            guard let url = URL(string: scheme) else { continue }
959
+            if NSWorkspace.shared.urlForApplication(toOpen: url) != nil {
960
+                NSWorkspace.shared.open(url)
961
+                return
962
+            }
963
+        }
964
+        presentIndeedJobBrowser(url: Self.indeedBrowseHomeURL)
965
+    }
966
+
951 967
     private func presentIndeedJobBrowser(url: URL) {
952 968
         guard let parentVC = hostingViewController else { return }
953 969
 
@@ -2380,6 +2396,50 @@ final class DashboardView: NSView, NSTextFieldDelegate, NSSharingServicePickerDe
2380 2396
         trailingLoadMoreJobsButton?.alphaValue = enabled ? 1 : 0.65
2381 2397
     }
2382 2398
 
2399
+    private func addIndeedSidebarLaunchRow() {
2400
+        let rowHost = SidebarNavRowView { [weak self] in
2401
+            self?.openIndeedFromSidebar()
2402
+        }
2403
+        rowHost.translatesAutoresizingMaskIntoConstraints = false
2404
+        rowHost.wantsLayer = true
2405
+        rowHost.layer?.cornerRadius = 8
2406
+        rowHost.restingBackgroundColor = nil
2407
+        rowHost.hoverBackgroundColor = Theme.sidebarRowHoverFill
2408
+        rowHost.setAccessibilityLabel("Indeed")
2409
+        rowHost.setAccessibilityRole(.button)
2410
+        rowHost.setAccessibilityHelp("Open Indeed to search and apply for jobs")
2411
+
2412
+        let row = NSStackView()
2413
+        row.orientation = .horizontal
2414
+        row.spacing = 8
2415
+        row.alignment = .centerY
2416
+        row.translatesAutoresizingMaskIntoConstraints = false
2417
+
2418
+        let logo = IndeedLogoView(displayHeight: 18, variant: .compact)
2419
+        logo.translatesAutoresizingMaskIntoConstraints = false
2420
+
2421
+        let text = NSTextField(labelWithString: "Indeed")
2422
+        text.font = .systemFont(ofSize: 14, weight: .medium)
2423
+        text.textColor = Theme.secondaryText
2424
+        text.refusesFirstResponder = true
2425
+
2426
+        row.addArrangedSubview(logo)
2427
+        row.addArrangedSubview(text)
2428
+
2429
+        rowHost.addSubview(row)
2430
+        NSLayoutConstraint.activate([
2431
+            row.leadingAnchor.constraint(equalTo: rowHost.leadingAnchor, constant: 10),
2432
+            row.trailingAnchor.constraint(equalTo: rowHost.trailingAnchor, constant: -10),
2433
+            row.topAnchor.constraint(equalTo: rowHost.topAnchor, constant: 8),
2434
+            row.bottomAnchor.constraint(equalTo: rowHost.bottomAnchor, constant: -8)
2435
+        ])
2436
+        rowHost.setContentHuggingPriority(.defaultLow, for: .horizontal)
2437
+        sidebar.addArrangedSubview(rowHost)
2438
+        let sidebarHorizontalInset = sidebar.edgeInsets.left + sidebar.edgeInsets.right
2439
+        rowHost.widthAnchor.constraint(equalTo: sidebar.widthAnchor, constant: -sidebarHorizontalInset).isActive = true
2440
+        sidebar.setCustomSpacing(10, after: rowHost)
2441
+    }
2442
+
2383 2443
     private func configureSidebar() {
2384 2444
         let items = currentSidebarItems
2385 2445
         sidebar.arrangedSubviews.forEach {
@@ -2405,6 +2465,8 @@ final class DashboardView: NSView, NSTextFieldDelegate, NSSharingServicePickerDe
2405 2465
         sidebar.addArrangedSubview(brandHeader)
2406 2466
         sidebar.setCustomSpacing(22, after: brandHeader)
2407 2467
 
2468
+        addIndeedSidebarLaunchRow()
2469
+
2408 2470
         items.enumerated().forEach { index, item in
2409 2471
             let isSelected = index == selectedSidebarIndex
2410 2472