summaryrefslogtreecommitdiff
path: root/octosentry/octosentryApp.swift
blob: d9f388e3f395a79859e4eb7abd725e6587c93e59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  octosentryApp.swift
//  octosentry
//
//  Created by cmc on 2026-07-17.
//

import SwiftUI

enum SecurityEventWindow {
    static let id = "security-events-window"
}

@main
struct octosentryApp: App {
    @State private var store = SecurityEventStore()
    @State private var authStore = AuthStore()
    @State private var updateStore = UpdateStore()

    var body: some Scene {
        MenuBarExtra {
            SecurityEventListView(store: store, authStore: authStore, updateStore: updateStore)
                .frame(width: 380, height: 420)
        } label: {
            MenuBarIconView(criticalCount: store.unseenCriticalCount)
        }
        .menuBarExtraStyle(.window)

        Window("Security Events", id: SecurityEventWindow.id) {
            SecurityEventListView(store: store, authStore: authStore, updateStore: updateStore, isStandaloneWindow: true)
                .frame(minWidth: 420, minHeight: 480)
        }
    }
}

private struct MenuBarIconView: View {
    let criticalCount: Int

    var body: some View {
        ZStack(alignment: .topTrailing) {
            Image(systemName: criticalCount > 0 ? "exclamationmark.shield.fill" : "shield.lefthalf.filled")

            if criticalCount > 0 {
                Text(criticalCount > 9 ? "9+" : "\(criticalCount)")
                    .font(.system(size: 8, weight: .bold))
                    .foregroundStyle(.white)
                    .padding(2)
                    .background(Circle().fill(.red))
                    .offset(x: 8, y: -6)
            }
        }
    }
}