Skip to content

Commit

Permalink
Leaving session when clicking SharePlay button during session
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Jun 11, 2021
1 parent 76c2092 commit 91b4935
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions WWDC/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,20 @@ final class AppCoordinator {
func startSharePlay() {
guard #available(macOS 12.0, *) else { return }

if case .session = SharePlayManager.shared.state {
let alert = NSAlert()
alert.messageText = "Leave SharePlay?"
alert.informativeText = "Are you sure you'd like to leave this SharePlay session?"
alert.addButton(withTitle: "Cancel")
alert.addButton(withTitle: "Leave")

if alert.runModal() == .alertSecondButtonReturn {
SharePlayManager.shared.leaveActivity()
}

return
}

guard let viewModel = selectedSessionValue else {
let alert = NSAlert()
alert.messageText = "Select a Session"
Expand Down
6 changes: 6 additions & 0 deletions WWDC/SharePlayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@ final class SharePlayManager: ObservableObject {
}
}
}

func leaveActivity() {
guard case .session(let session) = state else { return }

session.leave()
}

}
2 changes: 0 additions & 2 deletions WWDC/SharePlayStatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ struct SharePlayStatusView: View {
}
}
.disabled(viewModel.state == .loading)
} else {
EmptyView()
}
}
}
Expand Down

0 comments on commit 91b4935

Please sign in to comment.