Skip to content

Commit

Permalink
fix(settings): only patch window if new settings style active
Browse files Browse the repository at this point in the history
force-unwrapping an optional to find the underlying Settings NSWindow caused a crash on macOS 12

fixes #144
  • Loading branch information
cryptoAlgorithm committed May 9, 2023
1 parent 5d9b7f3 commit 1da1b06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 0 additions & 11 deletions Swiftcord/SwiftcordApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ struct SwiftcordApp: App {
? .dark
: (selectedTheme == "light" ? .light : .none)
)
.task {
// print("run")
let window = NSApp.windows.first { $0.identifier?.rawValue == "com_apple_SwiftUI_Settings_window" }!
window.toolbarStyle = .unified

let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar"
let index = window.toolbar?.items.firstIndex { $0.itemIdentifier.rawValue == sidebaritem }
if let index {
window.toolbar?.removeItem(at: index)
}
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Swiftcord/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ struct SettingsView: View {
if let user = gateway.cache.user {
if #available(macOS 13.0, *), newUI {
ModernSettings(user: user)
.task {
guard let window = NSApp.windows.first(where: { $0.identifier?.rawValue == "com_apple_SwiftUI_Settings_window" }) else { return }
window.toolbarStyle = .unified

let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar"
if let index = window.toolbar?.items.firstIndex(where: { $0.itemIdentifier.rawValue == sidebaritem }) {
window.toolbar?.removeItem(at: index)
}
}
} else {
LegacySettings(user: user)
}
Expand Down

0 comments on commit 1da1b06

Please sign in to comment.