Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ jobs:
- name: Swift test
working-directory: apps/macos/SequinsData
run: xcrun swift test -Xswiftc -DSPM_BUILD

- name: Swift app build and unit tests
working-directory: apps/macos
run: xcrun swift test -Xswiftc -DSPM_BUILD
6 changes: 6 additions & 0 deletions apps/macos/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ let package = Package(
path: "Sequins",
exclude: ["Assets.xcassets"],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(
name: "SequinsTests",
dependencies: ["Sequins"],
path: "SequinsTests",
swiftSettings: [.swiftLanguageMode(.v5)]
)
]
)
26 changes: 26 additions & 0 deletions apps/macos/Sequins/Models/AppPreferences.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import Observation

/// App-wide UI preferences, independent of connection environments.
@Observable
final class AppPreferences {
@ObservationIgnored private let defaults: UserDefaults

var showMainWindowOnLaunch: Bool {
didSet { defaults.set(showMainWindowOnLaunch, forKey: "showMainWindowOnLaunch") }
}
var hasAcknowledgedWelcome: Bool {
didSet { defaults.set(hasAcknowledgedWelcome, forKey: "hasAcknowledgedWelcome") }
}

init(defaults: UserDefaults = .standard) {
self.defaults = defaults
showMainWindowOnLaunch = defaults.object(forKey: "showMainWindowOnLaunch") == nil
? true : defaults.bool(forKey: "showMainWindowOnLaunch")
hasAcknowledgedWelcome = defaults.bool(forKey: "hasAcknowledgedWelcome")
}

func shouldOpenMainWindow(environment: [String: String]) -> Bool {
showMainWindowOnLaunch || environment["SEQUINS_AUTO_OPEN_WINDOW"] != nil
}
}
43 changes: 32 additions & 11 deletions apps/macos/Sequins/SequinsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SequinsData

@main
struct SequinsApp: App {
@NSApplicationDelegateAdaptor(SequinsAppDelegate.self) private var appDelegate
@State private var appState: AppStateViewModel
private let modelContainer: ModelContainer

Expand Down Expand Up @@ -36,20 +37,10 @@ struct SequinsApp: App {
// print("🚀 SequinsApp: OTLP server starting on app launch")

self._appState = State(initialValue: state)
appDelegate.appState = state

// Set up notification service
setupNotifications(appState: state)

// Demo/QA hook: auto-open the main window on launch when requested, so the
// menu-bar app can be driven headlessly. No-op unless the env var is set.
if let tabName = ProcessInfo.processInfo.environment["SEQUINS_AUTO_OPEN_WINDOW"] {
let tab = NavigationItem(rawValue: tabName) ?? .assistant
let launchState = state
DispatchQueue.main.async {
MainWindowController.shared.showWindow(appState: launchState, selectedTab: tab)
NSApp.activate(ignoringOtherApps: true)
}
}
}

private func setupNotifications(appState: AppStateViewModel) {
Expand Down Expand Up @@ -86,6 +77,7 @@ struct SequinsApp: App {
.environment(appState)
} label: {
MenuBarIconLabel()
.accessibilityLabel("Sequins")
}
.menuBarExtraStyle(.window)

Expand All @@ -98,6 +90,35 @@ struct SequinsApp: App {
}
}

@MainActor
final class SequinsAppDelegate: NSObject, NSApplicationDelegate {
weak var appState: AppStateViewModel?

func applicationDidFinishLaunching(_ notification: Notification) {
openWindowIfRequested()
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
openWindowIfRequested()
return false
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
false // Collection continues through the permanent menu bar app.
}

private func openWindowIfRequested() {
guard let appState else { return }
let environment = ProcessInfo.processInfo.environment
guard appState.preferences.shouldOpenMainWindow(environment: environment) else { return }
// Preserve the QA hook's tab selection and precedence over background mode.
let tab = environment["SEQUINS_AUTO_OPEN_WINDOW"].map {
NavigationItem(rawValue: $0) ?? .assistant
} ?? .health
MainWindowController.shared.showWindow(appState: appState, selectedTab: tab)
}
}

private struct MenuBarIconLabel: View {
private static let icon: NSImage? = Bundle.main.url(forResource: "MenuBarIcon", withExtension: "tiff")
.flatMap { NSImage(contentsOf: $0) }
Expand Down
15 changes: 15 additions & 0 deletions apps/macos/Sequins/ViewModels/AppStateViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import SequinsData
@MainActor
@Observable
final class AppStateViewModel {
let preferences = AppPreferences()
var serviceDiscoveryState: ServiceDiscoveryState = .loading
var selectedSettingsTab: SettingsTab = .general
// Environment management
let environmentManager = EnvironmentManager()

Expand Down Expand Up @@ -107,6 +110,8 @@ final class AppStateViewModel {
}

func connectToEnvironment(_ environment: ConnectionEnvironment) {
selectedService = nil
serviceDiscoveryState = .loading
dataSourceError = nil
serverStatus = .starting

Expand Down Expand Up @@ -188,6 +193,16 @@ final class AppStateViewModel {
}
}

enum ServiceDiscoveryState: Equatable {
case loading
case ready(hasServices: Bool)
case failed(String)
}

enum SettingsTab: Hashable {
case general, environments, healthRules
}

enum ServerStatus: Equatable {
case stopped
case starting
Expand Down
124 changes: 85 additions & 39 deletions apps/macos/Sequins/Views/Main/MainWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct MainWindow: View {
.navigationSplitViewColumnWidth(min: 160, ideal: 220, max: 300)
} detail: {
VStack(spacing: 0) {
WelcomeBanner()
// Expandable resource attributes panel (service tabs only)
if let service = appState.selectedService, appState.isServiceAttributesExpanded {
ResourceAttributesPanel(service: service)
Expand Down Expand Up @@ -221,55 +222,100 @@ struct DetailContentView: View {
/// Empty state when no service is selected
struct NoServiceSelectedView: View {
@Environment(AppStateViewModel.self) private var appState
@Environment(\.openSettings) private var openSettings

var body: some View {
VStack(spacing: 20) {
Image(systemName: "sidebar.left")
.font(.system(size: 64))
.foregroundStyle(.secondary)

Text("Select a Service")
.font(.title2)
.foregroundStyle(.secondary)

Text("Choose a service from the sidebar to view its telemetry data")
.font(.body)
.foregroundStyle(.tertiary)
.multilineTextAlignment(.center)
.frame(maxWidth: 300)
switch appState.serverStatus {
case .starting:
ProgressView("Starting Sequins…")
case .stopped:
statusMessage("Connect an Environment", icon: "network", message: "Open Settings to connect a local or remote environment.")
Button("Open Environment Settings", action: openEnvironmentSettings)
case .error(let message):
failure(message)
case .running, .connected:
switch appState.serviceDiscoveryState {
case .loading:
ProgressView("Loading services…")
case .failed(let message):
failure(message)
case .ready(hasServices: true):
statusMessage("Select a Service", icon: "sidebar.left", message: "Choose a service from the sidebar to view its telemetry data.")
case .ready(hasServices: false):
gettingStarted
}
}
}
.padding(32)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

private var gettingStarted: some View {
VStack(spacing: 20) {
if case .running(let grpcPort, let httpPort) = appState.serverStatus {
VStack(alignment: .leading, spacing: 8) {
Text("Waiting for telemetry data...")
.font(.caption)
.foregroundStyle(.secondary)

HStack(spacing: 16) {
VStack(alignment: .leading, spacing: 4) {
Text("gRPC")
.font(.caption2)
.foregroundStyle(.tertiary)
Text("localhost:\(String(grpcPort))")
.font(.system(.caption, design: .monospaced))
.foregroundStyle(.secondary)
}

VStack(alignment: .leading, spacing: 4) {
Text("HTTP")
.font(.caption2)
.foregroundStyle(.tertiary)
Text("localhost:\(String(httpPort))")
.font(.system(.caption, design: .monospaced))
.foregroundStyle(.secondary)
}
}
statusMessage("Send your first telemetry", icon: "antenna.radiowaves.left.and.right", message: "Sequins is ready to receive OpenTelemetry data. Point your application's exporter at one of these local endpoints. Services appear automatically when data arrives.")
VStack(alignment: .leading, spacing: 12) {
endpoint("HTTP", value: "http://localhost:\(httpPort)")
endpoint("gRPC", value: "http://localhost:\(grpcPort)")
Divider()
Text("For an OTLP HTTP/protobuf exporter:")
.font(.caption).foregroundStyle(.secondary)
let configuration = "export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:\(httpPort)\nexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf"
Text(configuration)
.font(.system(.caption, design: .monospaced))
.fixedSize(horizontal: false, vertical: true)
.textSelection(.enabled)
Button("Copy exporter configuration") { copy(configuration) }
}
.padding()
.padding(16)
.background(Color(nsColor: .controlBackgroundColor))
.clipShape(RoundedRectangle(cornerRadius: 8))
} else {
statusMessage("Waiting for remote telemetry", icon: "network", message: "No services are available in this environment. Send telemetry to your remote Sequins daemon and verify its connection settings.")
Button("Open Environment Settings", action: openEnvironmentSettings)
}
Link("OpenTelemetry instrumentation guide", destination: URL(string: "https://opentelemetry.io/docs/languages/")!)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.frame(maxWidth: 560)
}

private func statusMessage(_ title: String, icon: String, message: String) -> some View {
VStack(spacing: 16) {
Image(systemName: icon).font(.system(size: 48)).foregroundStyle(.secondary)
Text(title).font(.title2)
Text(message).foregroundStyle(.secondary).multilineTextAlignment(.center)
}
}

private func failure(_ message: String) -> some View {
VStack(spacing: 16) {
statusMessage("Couldn’t Load Telemetry", icon: "exclamationmark.triangle", message: message)
HStack {
Button("Retry") { appState.reconnect() }
Button("Open Environment Settings", action: openEnvironmentSettings)
}
}
.frame(maxWidth: 560)
}

private func endpoint(_ label: String, value: String) -> some View {
HStack {
Text(label).frame(width: 45, alignment: .leading)
Text(value).font(.system(.body, design: .monospaced)).textSelection(.enabled)
Spacer()
Button("Copy \(label) endpoint") { copy(value) }
}
}

private func copy(_ value: String) {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(value, forType: .string)
}

private func openEnvironmentSettings() {
appState.selectedSettingsTab = .environments
openSettings()
}
}

Expand Down
3 changes: 3 additions & 0 deletions apps/macos/Sequins/Views/Main/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ final class MainWindowController {
private init() {}

func showWindow(appState: AppStateViewModel, selectedTab: NavigationItem = .health) {
if let window, window.isMiniaturized {
window.deminiaturize(nil)
}
if let existingWindow = window, existingWindow.isVisible {
existingWindow.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
Expand Down
34 changes: 34 additions & 0 deletions apps/macos/Sequins/Views/Main/WelcomeBanner.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

struct WelcomeBanner: View {
@Environment(AppStateViewModel.self) private var appState
@Environment(\.openSettings) private var openSettings

var body: some View {
if !appState.preferences.hasAcknowledgedWelcome {
HStack(alignment: .top, spacing: 16) {
Image(systemName: "menubar.rectangle")
.font(.title2)
.foregroundStyle(.tint)
VStack(alignment: .leading, spacing: 6) {
Text("Welcome to Sequins").font(.headline)
Text("Sequins keeps collecting telemetry when you close this window. Reopen it from the Sequins menu bar icon. You can change startup behavior in Settings.")
.font(.callout)
.foregroundStyle(.secondary)
HStack {
Button("Open Settings") {
appState.selectedSettingsTab = .general
openSettings()
}
Button("Got it") { appState.preferences.hasAcknowledgedWelcome = true }
}
}
Spacer(minLength: 0)
}
.padding(20)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.accentColor.opacity(0.06))
Divider()
}
}
}
Loading
Loading