Skip to content

Commit

Permalink
Changed variable name isManuallyShown to isPresented, and notificatio…
Browse files Browse the repository at this point in the history
…nOverlay to notificationPanel. Fixed SwiftLint errors.
  • Loading branch information
austincondiff committed Feb 19, 2025
1 parent c292c7d commit cd1bf2d
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 75 deletions.
16 changes: 8 additions & 8 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
B68DE5E02D5A61E5009A43EF /* NotificationBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68DE5D92D5A61E5009A43EF /* NotificationBannerView.swift */; };
B68DE5E22D5A61E5009A43EF /* NotificationToolbarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68DE5DB2D5A61E5009A43EF /* NotificationToolbarItem.swift */; };
B68DE5E32D5A61E5009A43EF /* NotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68DE5DD2D5A61E5009A43EF /* NotificationManager.swift */; };
B68DE5E52D5A7988009A43EF /* NotificationOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68DE5E42D5A7988009A43EF /* NotificationOverlayView.swift */; };
B68DE5E52D5A7988009A43EF /* NotificationPanelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68DE5E42D5A7988009A43EF /* NotificationPanelView.swift */; };
B6966A282C2F683300259C2D /* SourceControlPullView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6966A272C2F683300259C2D /* SourceControlPullView.swift */; };
B6966A2A2C2F687A00259C2D /* SourceControlFetchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6966A292C2F687A00259C2D /* SourceControlFetchView.swift */; };
B6966A2E2C3056AD00259C2D /* SourceControlCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6966A2D2C3056AD00259C2D /* SourceControlCommands.swift */; };
Expand All @@ -598,7 +598,7 @@
B6966A342C34996B00259C2D /* SourceControlManager+GitClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6966A332C34996B00259C2D /* SourceControlManager+GitClient.swift */; };
B696A7E62CFE20C40048CFE1 /* FeatureIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B696A7E52CFE20C40048CFE1 /* FeatureIcon.swift */; };
B697937A29FF5668002027EC /* AccountsSettingsAccountLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = B697937929FF5668002027EC /* AccountsSettingsAccountLink.swift */; };
B69970322D63E5C700BB132D /* NotificationOverlayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69970302D63E5C700BB132D /* NotificationOverlayViewModel.swift */; };
B69970322D63E5C700BB132D /* NotificationPanelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69970302D63E5C700BB132D /* NotificationPanelViewModel.swift */; };
B69BFDC72B0686910050D9A6 /* GitClient+Initiate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69BFDC62B0686910050D9A6 /* GitClient+Initiate.swift */; };
B69D3EDE2C5E85A2005CF43A /* StopTaskToolbarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69D3EDD2C5E85A2005CF43A /* StopTaskToolbarButton.swift */; };
B69D3EE12C5F5357005CF43A /* TaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69D3EE02C5F5357005CF43A /* TaskView.swift */; };
Expand Down Expand Up @@ -1290,7 +1290,7 @@
B68DE5D92D5A61E5009A43EF /* NotificationBannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationBannerView.swift; sourceTree = "<group>"; };
B68DE5DB2D5A61E5009A43EF /* NotificationToolbarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationToolbarItem.swift; sourceTree = "<group>"; };
B68DE5DD2D5A61E5009A43EF /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = "<group>"; };
B68DE5E42D5A7988009A43EF /* NotificationOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationOverlayView.swift; sourceTree = "<group>"; };
B68DE5E42D5A7988009A43EF /* NotificationPanelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPanelView.swift; sourceTree = "<group>"; };
B6966A272C2F683300259C2D /* SourceControlPullView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlPullView.swift; sourceTree = "<group>"; };
B6966A292C2F687A00259C2D /* SourceControlFetchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlFetchView.swift; sourceTree = "<group>"; };
B6966A2D2C3056AD00259C2D /* SourceControlCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlCommands.swift; sourceTree = "<group>"; };
Expand All @@ -1299,7 +1299,7 @@
B6966A332C34996B00259C2D /* SourceControlManager+GitClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SourceControlManager+GitClient.swift"; sourceTree = "<group>"; };
B696A7E52CFE20C40048CFE1 /* FeatureIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureIcon.swift; sourceTree = "<group>"; };
B697937929FF5668002027EC /* AccountsSettingsAccountLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsSettingsAccountLink.swift; sourceTree = "<group>"; };
B69970302D63E5C700BB132D /* NotificationOverlayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationOverlayViewModel.swift; sourceTree = "<group>"; };
B69970302D63E5C700BB132D /* NotificationPanelViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPanelViewModel.swift; sourceTree = "<group>"; };
B69BFDC62B0686910050D9A6 /* GitClient+Initiate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Initiate.swift"; sourceTree = "<group>"; };
B69D3EDD2C5E85A2005CF43A /* StopTaskToolbarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopTaskToolbarButton.swift; sourceTree = "<group>"; };
B69D3EE02C5F5357005CF43A /* TaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3601,8 +3601,8 @@
isa = PBXGroup;
children = (
B68DE5D92D5A61E5009A43EF /* NotificationBannerView.swift */,
B68DE5E42D5A7988009A43EF /* NotificationPanelView.swift */,
B68DE5DB2D5A61E5009A43EF /* NotificationToolbarItem.swift */,
B68DE5E42D5A7988009A43EF /* NotificationOverlayView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -3639,7 +3639,7 @@
B69970312D63E5C700BB132D /* ViewModels */ = {
isa = PBXGroup;
children = (
B69970302D63E5C700BB132D /* NotificationOverlayViewModel.swift */,
B69970302D63E5C700BB132D /* NotificationPanelViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -4269,8 +4269,8 @@
B6B2D7A12CE8797B00379967 /* GitConfigExtensions.swift in Sources */,
587B9E7329301D8F00AC7927 /* GitRouter.swift in Sources */,
6C2C156129B4F52F00EA60A5 /* SplitViewModifiers.swift in Sources */,
B69970322D63E5C700BB132D /* NotificationOverlayViewModel.swift in Sources */,
B68DE5E52D5A7988009A43EF /* NotificationOverlayView.swift in Sources */,
B69970322D63E5C700BB132D /* NotificationPanelViewModel.swift in Sources */,
B68DE5E52D5A7988009A43EF /* NotificationPanelView.swift in Sources */,
61A53A812B4449F00093BF8A /* WorkspaceDocument+Index.swift in Sources */,
66AF6CE22BF17CC300D83C9D /* StatusBarViewModel.swift in Sources */,
30CB648D2C12680F00CC8A9E /* LSPService+Events.swift in Sources */,
Expand Down
9 changes: 6 additions & 3 deletions CodeEdit/Features/CodeEditUI/Styles/OverlayButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import SwiftUI

/// A button style for overlay buttons (like close, action buttons in notifications)
struct OverlayButtonStyle: ButtonStyle {
@Environment(\.isEnabled) private var isEnabled
@Environment(\.controlActiveState) private var controlActive

@Environment(\.isEnabled)
private var isEnabled

@Environment(\.controlActiveState)
private var controlActive

func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
var workspaceSettingsManager: CEWorkspaceSettings?
var taskNotificationHandler: TaskNotificationHandler = TaskNotificationHandler()

@Published var notificationOverlay = NotificationOverlayViewModel()
private var notificationOverlaySubscription: AnyCancellable?
@Published var notificationPanel = NotificationPanelViewModel()
private var notificationPanelSubscription: AnyCancellable?

private var cancellables = Set<AnyCancellable>()

override init() {
super.init()

// Observe changes to notification overlay
notificationOverlaySubscription = notificationOverlay.objectWillChange
// Observe changes to notification panel
notificationPanelSubscription = notificationPanel.objectWillChange
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
self?.objectWillChange.send()
Expand All @@ -62,7 +62,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
deinit {
cancellables.forEach { $0.cancel() }
NotificationCenter.default.removeObserver(self)
notificationOverlaySubscription?.cancel()
notificationPanelSubscription?.cancel()
}

func getFromWorkspaceState(_ key: WorkspaceStateKey) -> Any? {
Expand Down
4 changes: 2 additions & 2 deletions CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ struct InspectorAreaView: View {

private func updateTabs() {
var tabs: [InspectorTab] = [.file, .gitHistory]

if showInternalDevelopmentInspector {
tabs.append(.internalDevelopment)
}

viewModel.tabItems = tabs + extensionManager
.extensions
.map { ext in
Expand Down
5 changes: 0 additions & 5 deletions CodeEdit/Features/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ final class NotificationManager: NSObject, ObservableObject {
notifications.filter { !$0.isRead }.count
}

/// Whether there are currently notifications being displayed in the overlay
var hasActiveNotification: Bool {
!notifications.isEmpty
}

/// Posts a new notification
/// - Parameters:
/// - iconSymbol: SF Symbol or CodeEditSymbol name for the notification icon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//
// NotificationOverlayViewModel.swift
// NotificationPanelViewModel.swift
// CodeEdit
//
// Created by Austin Condiff on 2/14/24.
//

import SwiftUI

final class NotificationOverlayViewModel: ObservableObject {
/// Currently displayed notifications in the overlay
final class NotificationPanelViewModel: ObservableObject {
/// Currently displayed notifications in the panel
@Published private(set) var activeNotifications: [CENotification] = []

/// Whether notifications were manually shown via toolbar
@Published private(set) var isManuallyShown: Bool = false
/// Whether notifications panel was manually shown via toolbar
@Published private(set) var isPresented: Bool = false

/// Set of hidden notification IDs
@Published private(set) var hiddenNotificationIds: Set<UUID> = []
Expand All @@ -30,37 +30,37 @@ final class NotificationOverlayViewModel: ObservableObject {

@Published var scrolledToTop: Bool = true

/// Whether a notification should be visible in the overlay
/// Whether a notification should be visible in the panel
func isNotificationVisible(_ notification: CENotification) -> Bool {
if notification.isBeingDismissed {
return true // Always show notifications being dismissed
}
if notification.isSticky {
return true // Always show sticky notifications
}
if isManuallyShown {
if isPresented {
return true // Show all notifications when manually shown
}
return !hiddenNotificationIds.contains(notification.id)
}

/// Handles focus changes for the notification overlay
/// Handles focus changes for the notification panel
func handleFocusChange(isFocused: Bool) {
if !isFocused {
// Only hide if manually shown and focus is completely lost
if isManuallyShown {
if isPresented {
toggleNotificationsVisibility()
}
}
}

/// Toggles visibility of notifications in the overlay
/// Toggles visibility of notifications in the panel
func toggleNotificationsVisibility() {
if isManuallyShown {
if isPresented {
if !scrolledToTop {
// Just set isManuallyShown to false to trigger the offset animation
// Just set isPresented to false to trigger the offset animation
withAnimation(.easeInOut(duration: 0.3)) {
isManuallyShown = false
isPresented = false
}

// After the slide-out animation, hide notifications
Expand All @@ -82,7 +82,7 @@ final class NotificationOverlayViewModel: ObservableObject {
}
} else {
withAnimation(.easeInOut(duration: 0.3)) {
isManuallyShown = true
isPresented = true
hiddenNotificationIds.removeAll()
objectWillChange.send()
}
Expand All @@ -91,7 +91,7 @@ final class NotificationOverlayViewModel: ObservableObject {

private func hideNotifications() {
withAnimation(.easeInOut(duration: 0.3)) {
self.isManuallyShown = false
self.isPresented = false
self.activeNotifications
.filter { !$0.isSticky }
.forEach { self.hiddenNotificationIds.insert($0.id) }
Expand All @@ -101,7 +101,7 @@ final class NotificationOverlayViewModel: ObservableObject {

/// Starts the timer to automatically hide a notification
func startHideTimer(for notification: CENotification) {
guard !notification.isSticky && !isManuallyShown else { return }
guard !notification.isSticky && !isPresented else { return }

timers[notification.id]?.invalidate()
timers[notification.id] = nil
Expand Down Expand Up @@ -174,7 +174,7 @@ final class NotificationOverlayViewModel: ObservableObject {
withAnimation(.easeInOut(duration: 0.3)) {
insertNotification(notification)
hiddenNotificationIds.remove(notification.id)
if !isManuallyShown && !notification.isSticky {
if !isPresented && !notification.isSticky {
startHideTimer(for: notification)
}
}
Expand Down Expand Up @@ -204,8 +204,8 @@ final class NotificationOverlayViewModel: ObservableObject {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
withAnimation(.easeOut(duration: 0.2)) {
self.activeNotifications.removeAll(where: { $0.id == notification.id })
if self.activeNotifications.isEmpty && self.isManuallyShown {
self.isManuallyShown = false
if self.activeNotifications.isEmpty && self.isPresented {
self.isPresented = false
}
}

Expand Down Expand Up @@ -257,8 +257,8 @@ final class NotificationOverlayViewModel: ObservableObject {
activeNotifications.removeAll(where: { $0.id == ceNotification.id })

// If this was the last notification and they were manually shown, hide the panel
if activeNotifications.isEmpty && isManuallyShown {
isManuallyShown = false
if activeNotifications.isEmpty && isPresented {
isPresented = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ struct NotificationBannerView: View {
}

if hovering {
workspace.notificationOverlay.pauseTimer()
workspace.notificationPanel.pauseTimer()
} else {
workspace.notificationOverlay.resumeTimer()
workspace.notificationPanel.resumeTimer()
}
}
}
Expand Down
Loading

0 comments on commit cd1bf2d

Please sign in to comment.