Files
SonarDesk/SonarDesk/App/SonarDeskApp.swift
T

74 lines
2.3 KiB
Swift

import SwiftUI
import AppKit
final class SonarDeskAppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// Do not replace applicationIconImage at runtime. macOS obtains the Dock
// icon from the compiled AppIcon asset in the application bundle.
}
}
@main
struct SonarDeskApp: App {
@NSApplicationDelegateAdaptor(SonarDeskAppDelegate.self) private var appDelegate
@StateObject private var appState = AppState()
@StateObject private var reportStore = ReportStore()
@State private var launchPhase: LaunchPhase = .splash
private enum LaunchPhase {
case splash
case application
}
var body: some Scene {
WindowGroup {
Group {
switch launchPhase {
case .splash:
LaunchView()
.task { await startApplication() }
case .application:
RootView()
.environmentObject(appState)
.environmentObject(reportStore)
.transition(.opacity)
}
}
.frame(minWidth: 1040, minHeight: 680)
.background(Color(nsColor: .windowBackgroundColor))
}
.windowStyle(.hiddenTitleBar)
.commands {
SidebarCommands()
CommandGroup(replacing: .appInfo) {
Button("About SonarDesk") {
SonarDeskAboutPanel.show()
}
}
}
Settings {
SettingsView()
.environmentObject(appState)
.environmentObject(reportStore)
.frame(width: 620, height: 430)
}
}
@MainActor
private func startApplication() async {
// Keep the branded launch experience visible long enough to be perceptible,
// while using the time to perform the first SonarQube refresh.
async let minimumSplash: Void = Task.sleep(for: .seconds(1.6))
if appState.projects.isEmpty, appState.selectedServer != nil {
await appState.refresh()
}
_ = try? await minimumSplash
withAnimation(.easeInOut(duration: 0.32)) {
launchPhase = .application
}
}
}