Repository navigation
feat: add multi-account couch co-op with independent stream windows #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anderson-oki
merged 36 commits into
OpenCloudGaming:main
from
sheldon:sheldon/dual-instance-couch-coop
Oct 29, 2026
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
077a586
feat: enable controllers per stream in the controller panel
anderson-oki 2701600
refactor: tighten the per-stream controller model and monitor seams
anderson-oki b46eed7
Merge commit 'a6c662480f2c4fcbd83353acc4941311fe35cc0e' into sheldon/…
sheldon 84f1a40
feat: tile stream windows and add borderless full screen behind the c…
sheldon b48f6b7
feat: give each stream window its own controllers and let pads play o…
sheldon 1e2513d
feat: add Stream > Detach New Session to stream a second account in i…
sheldon a8a5bfa
fix: keep the Detach window from covering the main window during add …
sheldon e47c6bb
Merge main into sheldon/dual-instance-couch-coop
sheldon 413e92e
fix(deps): cap swift-collections below 1.7 so tests load on macOS 26
sheldon 75b7292
merge: cap swift-collections below 1.7 so tests load on macOS 26
sheldon 2206695
docs: move swift-collections cap rationale from Package.swift to README
sheldon 8417932
merge: move swift-collections cap rationale to the README
sheldon b33133f
test: stop the close-guard test from ending the test host on macOS 26
sheldon c2eb3b9
test: stop the close-guard test from ending the test host on macOS 26
sheldon 94253ca
Merge branch 'sheldon/fix-close-guard-test-ends-test-host' into sheld…
sheldon 0cacb27
fix: don't treat a move before the first tile lands as the reader tak…
sheldon 7a36e91
feat: let couch co-op tiles sit below the menu bar or fill the screen…
sheldon 9623318
Merge branch 'main' into sheldon/dual-instance-couch-coop
anderson-oki 580a24d
fix: isolate couch co-op account services and detached actions
anderson-oki 3e67b97
fix: harden couch co-op input and window transitions
anderson-oki fef6abe
Merge branch 'main' of https://github.com/OpenCloudGaming/OpenNOW-Mac…
sheldon e12d89d
fix: retile the remaining co-op windows when one is taken by the read…
sheldon e25c0ff
Merge branch 'sheldon/dual-instance-couch-coop' of https://github.com…
sheldon bdc86da
test: cover retiling when a tiled window is taken by the reader or go…
sheldon 60884b6
fix: send an account switch to sign-in when its saved tokens are reje…
sheldon 48d04f8
fix: drop the rejected client token before the refresh-token fallback…
sheldon bf18bdc
fix: reconcile latest PR 82 account and window changes
anderson-oki 194fff8
Merge branch 'main' into sheldon/dual-instance-couch-coop
sheldon f8db633
fix: stop the refresh-token fallback from acting on another account a…
sheldon 98c11dc
fix: treat a 400 invalid_grant as a rejected grant, and drop explanat…
sheldon 35e5442
fix: bring the Jarvis auth service and account restore back under the…
sheldon 49723fa
fix: integrate latest PR 82 auth and rendering updates
anderson-oki 977eefc
Merge branch 'main' into sheldon/dual-instance-couch-coop
anderson-oki 4f4dfa1
Merge branch 'main' into sheldon/dual-instance-couch-coop
anderson-oki fd870cb
fix: integrate PR 82 microphone startup and release updates
anderson-oki cb27dcb
refactor: clarify PR 82 account and stream code
anderson-oki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import Foundation | ||
| import SwiftData | ||
|
|
||
| @MainActor | ||
| final class OPNMainAccountActions { | ||
| static let shared = OPNMainAccountActions() | ||
|
|
||
| struct Target { | ||
| let identifier: PersistentIdentifier | ||
| let accountID: String | ||
| let email: String | ||
| let userID: String | ||
| let providerID: String | ||
|
|
||
| init(account: LoginAccount) { | ||
| identifier = account.persistentModelID | ||
| accountID = account.stableAccountID | ||
| email = account.email | ||
| userID = account.userId | ||
| providerID = account.providerIdpId | ||
| } | ||
| } | ||
|
|
||
| enum Request { | ||
| case addAccount | ||
| case reauthenticate(Target) | ||
| case signOut(Target) | ||
| case forget(Target) | ||
| } | ||
|
|
||
| private weak var login: LoginViewModel? | ||
| private var pendingRequests: [Request] = [] | ||
| private let confirmation: OPNConfirmationPresentation | ||
| private let handoff: OPNMainWindowAccountHandoff | ||
|
|
||
| private enum ActionError: Error { | ||
| case missingContext | ||
| } | ||
|
|
||
| init(confirmation: OPNConfirmationPresentation = .shared, handoff: OPNMainWindowAccountHandoff = .shared) { | ||
| self.confirmation = confirmation | ||
| self.handoff = handoff | ||
| } | ||
|
|
||
| @discardableResult | ||
| func bind(login: LoginViewModel) -> Task<Void, Never> { | ||
| self.login = login | ||
| let queuedRequests = pendingRequests | ||
| pendingRequests.removeAll() | ||
| return Task { | ||
| for request in queuedRequests { | ||
| await perform(request, login: login) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func unbind(login: LoginViewModel) { | ||
| guard self.login === login else { return } | ||
| self.login = nil | ||
| } | ||
|
|
||
| @discardableResult | ||
| func request(_ request: Request) -> Task<Void, Never>? { | ||
| guard let login else { | ||
| pendingRequests.append(request) | ||
| return nil | ||
| } | ||
| return Task { await perform(request, login: login) } | ||
| } | ||
|
|
||
| private func perform(_ request: Request, login: LoginViewModel) async { | ||
| do { | ||
| try reload(login: login) | ||
| } catch { | ||
| showFailure("Saved accounts could not be loaded. Try again.") | ||
| return | ||
| } | ||
| switch request { | ||
| case .addAccount: | ||
| login.beginAddAccount() | ||
| case .reauthenticate(let target): | ||
| guard let account = resolve(target, login: login) else { return } | ||
| login.dismissAccountChooser() | ||
| login.beginReauthentication(for: account) | ||
| case .signOut(let target): | ||
| guard let account = resolve(target, login: login) else { return } | ||
| login.validationMessage = "" | ||
| await login.signOutAccount(account) | ||
| finishMutation(login: login) | ||
| case .forget(let target): | ||
| guard let account = resolve(target, login: login) else { return } | ||
| login.validationMessage = "" | ||
| login.forgetAccount(account) | ||
| finishMutation(login: login) | ||
| } | ||
| } | ||
|
|
||
| private func reload(login: LoginViewModel) throws { | ||
| guard let modelContext = login.modelContext else { throw ActionError.missingContext } | ||
| login.update( | ||
| modelContext: modelContext, | ||
| accounts: try modelContext.fetch(FetchDescriptor<LoginAccount>()), | ||
| sessions: try modelContext.fetch(FetchDescriptor<LoginSession>()), | ||
| devices: try modelContext.fetch(FetchDescriptor<LoginDeviceRegistration>()) | ||
| ) | ||
| } | ||
|
|
||
| private func resolve(_ target: Target, login: LoginViewModel) -> LoginAccount? { | ||
| guard let account = login.accounts.first(where: { | ||
| $0.persistentModelID == target.identifier && $0.stableAccountID == target.accountID | ||
| && $0.email == target.email && $0.userId == target.userID && $0.providerIdpId == target.providerID | ||
| }) else { | ||
| showFailure("This saved account changed or was removed. Choose the account again before continuing.") | ||
| return nil | ||
| } | ||
| return account | ||
| } | ||
|
|
||
| private func finishMutation(login: LoginViewModel) { | ||
| guard login.validationMessage.isEmpty else { | ||
| showFailure(login.validationMessage) | ||
| return | ||
| } | ||
| endHandoff() | ||
| } | ||
|
|
||
| private func showFailure(_ message: String) { | ||
| confirmation.present( | ||
| .init( | ||
| eyebrow: "ACCOUNT", | ||
| title: "Account action unavailable", | ||
| message: message, | ||
| actions: [OPNConfirmationAction("CLOSE") { [weak confirmation] in confirmation?.dismiss() }] | ||
| ), | ||
| onDismiss: { [weak self] in self?.endHandoff() } | ||
| ) | ||
| handoff.begin(from: nil) | ||
| } | ||
|
|
||
| private func endHandoff() { | ||
| guard login?.signInRequest == nil else { return } | ||
| handoff.end() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import SwiftUI | ||
|
|
||
| struct OPNReportIssueCommands: Commands { | ||
| @FocusedValue(\.opnReportIssuePresentation) private var presentation | ||
|
|
||
| var body: some Commands { | ||
| CommandGroup(replacing: .help) { | ||
| Button { | ||
| (presentation ?? .shared).present(context: .appEnvironment()) | ||
| } label: { | ||
| Label("Report an Issue…", systemImage: "exclamationmark.bubble") | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| enum ControllerMappingFocusPolicy { | ||
| /// Mappings follow the frontmost stream, except that couch co-op lets a pad keep playing its own | ||
| /// stream while another window has the focus. The overlay and remote-input gates still apply. | ||
| static func allowsMappings(appIsActive: Bool, windowIsKey: Bool, | ||
| remoteInputEnabled: Bool, overlayCapturesInput: Bool) -> Bool { | ||
| appIsActive && windowIsKey && remoteInputEnabled && !overlayCapturesInput | ||
| remoteInputEnabled: Bool, overlayCapturesInput: Bool, | ||
| allowsBackgroundPads: Bool = false) -> Bool { | ||
| ((appIsActive && windowIsKey) || allowsBackgroundPads) && remoteInputEnabled && !overlayCapturesInput | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.