Skip to content

Commit

Permalink
Use implicit self after guard 🍂🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Apr 13, 2024
1 parent c79c4c6 commit 8655c29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
29 changes: 14 additions & 15 deletions Calendr/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,13 @@ class MainViewController: NSViewController, NSPopoverDelegate {
let clickHandler = mainStatusItemClickHandler

clickHandler.leftClick
.enumerated()
.flatMapFirst { [weak self] pass, _ -> Observable<Void> in
.flatMapFirst { [weak self] _ -> Observable<Void> in
guard let self else { return .empty() }

self.forceLayout()
forceLayout()

let popover = NSPopover()
self.setUpAndShow(popover, from: statusBarButton)
setUpAndShow(popover, from: statusBarButton)

return popover.rx.deallocated
}
Expand Down Expand Up @@ -626,13 +625,13 @@ class MainViewController: NSViewController, NSPopoverDelegate {
keyboard.handler = { [weak self] event -> NSEvent? in
guard
let self,
(try? self.isShowingDetails.value()) == false,
(try? isShowingDetails.value()) == false,
let key = Keyboard.Key.from(event)
else { return event }

if let vc = self.presentedViewControllers?.last {
if let vc = presentedViewControllers?.last {
guard key ~= .escape else { return event }
self.dismiss(vc)
dismiss(vc)
return .none
}

Expand All @@ -641,16 +640,16 @@ class MainViewController: NSViewController, NSPopoverDelegate {
NSApp.terminate(nil)

case .command("f"):
self.showSearchInput()
showSearchInput()

case .command(","):
self.openSettings()
openSettings()

case .escape where self.searchInput.hasFocus:
self.hideSearchInput()
case .escape where searchInput.hasFocus:
hideSearchInput()

case .arrow(let arrow) where !self.searchInput.hasFocus:
self.arrowSubject.onNext(arrow)
case .arrow(let arrow) where !searchInput.hasFocus:
arrowSubject.onNext(arrow)

default:
return event
Expand All @@ -662,11 +661,11 @@ class MainViewController: NSViewController, NSPopoverDelegate {
// Global shortcut
KeyboardShortcuts.onKeyUp(for: .showMainPopover) { [weak self] in
guard let self else { return }
if let window = self.view.window {
if let window = view.window {
window.performClose(nil)
return
}
self.mainStatusItemClickHandler.leftClick.onNext(())
mainStatusItemClickHandler.leftClick.onNext(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion Calendr/Providers/CalendarServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CalendarServiceProvider: CalendarServiceProviding {
Observable.create { [weak self] observer in

if let self {
observer.onNext(self.storeCalendars().map(CalendarModel.init(from:)))
observer.onNext(storeCalendars().map(CalendarModel.init(from:)))
}
observer.onCompleted()

Expand Down
4 changes: 2 additions & 2 deletions Calendr/Settings/CalendarPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class CalendarPickerViewController: NSViewController {
)
.observe(on: MainScheduler.instance)
.compactMap { [weak self] calendars, showNextEvent -> [NSView]? in
guard let self = self else { return nil }
guard let self else { return nil }

self.itemsDisposeBag = DisposeBag()
itemsDisposeBag = DisposeBag()

return Dictionary(grouping: calendars, by: { $0.account })
.sorted(by: \.key.localizedLowercase)
Expand Down

0 comments on commit 8655c29

Please sign in to comment.