Working notification

This commit is contained in:
Hariharan Mudaliar 2025-11-10 01:55:29 +05:30
commit bb2284bafc
10 changed files with 367 additions and 372 deletions

View file

@ -0,0 +1,119 @@
//
// DoNotDisturbLiveActivity.swift
// DynamicIsland
//
// Renders the closed-notch Focus indicator with a purple moon badge.
//
import SwiftUI
struct DoNotDisturbLiveActivity: View {
@EnvironmentObject var vm: DynamicIslandViewModel
@ObservedObject var manager = DoNotDisturbManager.shared
@State private var isExpanded = false
private let focusColor = Color.purple
var body: some View {
HStack(spacing: 0) {
leadingWing
.frame(width: leadingWingWidth, height: wingHeight)
Rectangle()
.fill(Color.black)
.frame(width: vm.closedNotchSize.width)
trailingWing
.frame(width: trailingWingWidth, height: wingHeight)
}
.frame(height: vm.effectiveClosedNotchHeight)
.accessibilityElement(children: .ignore)
.accessibilityLabel(accessibilityDescription)
.onAppear {
withAnimation(.smooth(duration: 0.35)) {
isExpanded = true
}
}
.onChange(of: manager.isDoNotDisturbActive) { _, isActive in
withAnimation(.smooth(duration: 0.35)) {
isExpanded = isActive
}
}
}
private var wingHeight: CGFloat {
max(vm.effectiveClosedNotchHeight - 10, 20)
}
private var leadingWingWidth: CGFloat {
isExpanded ? max(vm.effectiveClosedNotchHeight - 10, 20) : 0
}
private var trailingWingWidth: CGFloat {
guard isExpanded else { return 0 }
return max(vm.closedNotchSize.width * 0.65, 120)
}
private var focusSymbol: String {
if let symbol = FocusModeType(rawValue: manager.currentFocusModeIdentifier)?.sfSymbol {
return symbol
}
return FocusModeType.doNotDisturb.sfSymbol
}
private var focusLabel: String {
if !manager.currentFocusModeName.isEmpty {
return manager.currentFocusModeName
}
return FocusModeType(rawValue: manager.currentFocusModeIdentifier)?.displayName ?? "Do Not Disturb"
}
private var accessibilityDescription: String {
"Focus mode active: \(focusLabel)"
}
private var leadingWing: some View {
Color.clear
.background {
if isExpanded {
ZStack {
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(focusColor.opacity(0.18))
Image(systemName: focusSymbol)
.font(.system(size: 12, weight: .semibold))
.foregroundColor(focusColor)
}
.frame(width: leadingWingWidth, height: wingHeight)
}
}
}
private var trailingWing: some View {
Color.clear
.background {
if isExpanded {
HStack {
Text(focusLabel)
.font(.system(size: 12, weight: .semibold, design: .rounded))
.foregroundColor(focusColor)
.lineLimit(1)
.padding(.horizontal, 12)
.padding(.vertical, 6)
}
.frame(maxWidth: .infinity, alignment: .trailing)
.background(
Capsule(style: .continuous)
.fill(focusColor.opacity(0.18))
)
}
}
}
}
#Preview {
DoNotDisturbLiveActivity()
.environmentObject(DynamicIslandViewModel())
.frame(width: 320, height: 54)
.background(Color.black)
}

View file

@ -16,6 +16,7 @@ struct DynamicIslandHeader: View {
@ObservedObject var clipboardManager = ClipboardManager.shared
@ObservedObject var tvm = TrayDrop.shared
@ObservedObject var timerManager = TimerManager.shared
@ObservedObject var doNotDisturbManager = DoNotDisturbManager.shared
@State private var showClipboardPopover = false
@State private var showColorPickerPopover = false
@State private var showTimerPopover = false
@ -196,6 +197,12 @@ struct DynamicIslandHeader: View {
RecordingIndicator()
.frame(width: 30, height: 30) // Same size as other header elements
}
if Defaults[.enableDoNotDisturbDetection] && Defaults[.showDoNotDisturbIndicator] && doNotDisturbManager.isDoNotDisturbActive {
FocusIndicator()
.frame(width: 30, height: 30)
.transition(.opacity)
}
if Defaults[.showBatteryIndicator] {
DynamicIslandBatteryView(

View file

@ -157,6 +157,7 @@ struct GeneralSettings: View {
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
@ObservedObject var recordingManager = ScreenRecordingManager.shared
@ObservedObject var privacyManager = PrivacyIndicatorManager.shared
@ObservedObject var doNotDisturbManager = DoNotDisturbManager.shared
@Default(.mirrorShape) var mirrorShape
@Default(.showEmojis) var showEmojis
@ -172,6 +173,8 @@ struct GeneralSettings: View {
@Default(.openNotchOnHover) var openNotchOnHover
@Default(.enableScreenRecordingDetection) var enableScreenRecordingDetection
@Default(.showRecordingIndicator) var showRecordingIndicator
@Default(.enableDoNotDisturbDetection) var enableDoNotDisturbDetection
@Default(.showDoNotDisturbIndicator) var showDoNotDisturbIndicator
@Default(.enableMinimalisticUI) var enableMinimalisticUI
@Default(.lockScreenGlassStyle) var lockScreenGlassStyle
@Default(.lockScreenShowAppIcon) var lockScreenShowAppIcon
@ -235,12 +238,12 @@ struct GeneralSettings: View {
Section {
Defaults.Toggle("Enable Screen Recording Detection", key: .enableScreenRecordingDetection)
Defaults.Toggle("Show Recording Indicator", key: .showRecordingIndicator)
.disabled(!enableScreenRecordingDetection)
// Note: Polling removed - now uses event-driven private API detection
if recordingManager.isMonitoring {
HStack {
Text("Detection Status")
@ -260,11 +263,48 @@ struct GeneralSettings: View {
}
}
} header: {
Text("Screen Recording Detection")
Text("Screen Recording")
} footer: {
Text("Uses event-driven private API for real-time screen recording detection")
}
Section {
Defaults.Toggle("Enable Focus Detection", key: .enableDoNotDisturbDetection)
Defaults.Toggle("Show Focus Indicator", key: .showDoNotDisturbIndicator)
.disabled(!enableDoNotDisturbDetection)
if doNotDisturbManager.isMonitoring {
HStack {
Text("Focus Status")
Spacer()
if doNotDisturbManager.isDoNotDisturbActive {
HStack(spacing: 4) {
Circle()
.fill(Color.purple)
.frame(width: 8, height: 8)
Text(doNotDisturbManager.currentFocusModeName.isEmpty ? "Focus Enabled" : doNotDisturbManager.currentFocusModeName)
.foregroundColor(.purple)
}
} else {
Text("Active - No Focus")
.foregroundColor(.green)
}
}
} else {
HStack {
Text("Focus Status")
Spacer()
Text("Disabled")
.foregroundColor(.secondary)
}
}
} header: {
Text("Do Not Disturb")
} footer: {
Text("Listens for Focus session changes via distributed notifications")
}
Section {
Defaults.Toggle("Enable Camera Detection", key: .enableCameraDetection)
Defaults.Toggle("Enable Microphone Detection", key: .enableMicrophoneDetection)

View file

@ -0,0 +1,45 @@
//
// FocusIndicator.swift
// DynamicIsland
//
// Small purple moon badge shown while Focus mode is active.
//
import SwiftUI
struct FocusIndicator: View {
@ObservedObject var manager = DoNotDisturbManager.shared
private let focusColor = Color.purple
var body: some View {
Capsule()
.fill(Color.black)
.overlay {
ZStack {
Circle()
.fill(focusColor.opacity(0.2))
.frame(width: 20, height: 20)
Image(systemName: focusSymbol)
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(focusColor)
}
}
.accessibilityElement(children: .ignore)
.accessibilityLabel("Focus mode active")
}
private var focusSymbol: String {
if let symbol = FocusModeType(rawValue: manager.currentFocusModeIdentifier)?.sfSymbol {
return symbol
}
return FocusModeType.doNotDisturb.sfSymbol
}
}
#Preview {
FocusIndicator()
.frame(width: 30, height: 30)
.background(Color.gray.opacity(0.2))
}