Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(setup): ask harder when Steam ignores steam://exit (#193)

Raystorms1ce5dcd9f4e1
diff --git a/app/Sources/BridgeplayApp/Model/SteamBundle.swift b/app/Sources/BridgeplayApp/Model/SteamBundle.swift
index 75eb10f..2534b5c 100644
--- a/app/Sources/BridgeplayApp/Model/SteamBundle.swift
+++ b/app/Sources/BridgeplayApp/Model/SteamBundle.swift
@@ -1,5 +1,6 @@
// Steam app bundle patching component
+import AppKit
import Foundation
enum SteamDeployment: Sendable, Equatable {
@@ -91,14 +92,23 @@ enum SteamBundle {
var runningAnywhere: @Sendable () -> Bool = { SteamBundle.isRunning }
var runningHere: @Sendable () -> Bool = { SteamBundle.isRunningForThisUser }
var askToQuit: @Sendable () -> Void = { _ = try? Shell.run("/usr/bin/open", ["-g", "steam://exit"]) }
+ // The quit the Dock sends. NSWorkspace lists only this account's apps.
+ var requestQuit: @Sendable () -> Void = {
+ for steam in NSWorkspace.shared.runningApplications
+ where steam.executableURL?.lastPathComponent == "steam_osx" {
+ steam.terminate()
+ }
+ }
var sweep: @Sendable (String) -> Void = { _ = try? Shell.run("/usr/bin/pkill", ["-f", $0]) }
var pause: @Sendable () -> Void = { Thread.sleep(forTimeInterval: 0.5) }
- var attempts = 60
+ var attempts = 40
+ var escalationAttempts = 20
}
- // Asks this account's Steam to quit and waits up to 30 seconds. Steam is never killed:
- // it may be writing its config or an update, so a Steam that stays open is reported
- // instead. A Steam another account runs is out of reach and reported as such.
+ // Asks this account's Steam to quit with steam://exit, which Steam can ignore on its
+ // login or update screen, then with a macOS quit. Steam is never killed: it may be
+ // writing its config or an update. Steam ignores SIGTERM, so none is sent. A Steam
+ // another account runs is out of reach and reported as such.
static func stopClient(
app: URL = SupportPaths.Steam.app,
helpers: [URL] = [SupportPaths.Steam.innerApp],
@@ -110,15 +120,24 @@ enum SteamBundle {
guard client.runningHere() else { throw OpenInAnotherAccount(step: step) }
onStopping()
+ func quits(within attempts: Int) -> Bool {
+ for _ in 0..<attempts where client.runningHere() {
+ client.pause()
+ }
+ return !client.runningHere()
+ }
client.askToQuit()
- for _ in 0..<client.attempts where client.runningHere() {
- client.pause()
+ var quit = quits(within: client.attempts)
+ if !quit {
+ AppLog.note("stop: Steam ignored steam://exit, asking macOS to quit it")
+ client.requestQuit()
+ quit = quits(within: client.escalationAttempts)
}
- guard !client.runningHere() else {
+ guard quit else {
throw StepFailure(
step: step,
- detail: String(localized: "Steam did not quit. Quit Steam, then try again.")
+ detail: String(localized: "Steam did not quit. Choose Steam > Quit Steam, then try again. If Steam does not respond, quit it in Activity Monitor.")
)
}
guard !client.runningAnywhere() else { throw OpenInAnotherAccount(step: step) }
diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
index 6c75c99..11a36d3 100644
--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
@@ -8309,18 +8309,18 @@
}
}
},
- "Steam did not quit. Quit Steam, then try again." : {
+ "Steam did not quit. Choose Steam > Quit Steam, then try again. If Steam does not respond, quit it in Activity Monitor." : {
"localizations" : {
"it" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Steam non si è chiuso. Chiudi Steam, poi riprova."
+ "value" : "Steam non si è chiuso. Scegli Steam > Esci da Steam, poi riprova. Se Steam non risponde, chiudilo da Monitoraggio Attività."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
- "value" : "Steam 未能退出。请退出 Steam 后重试。"
+ "value" : "Steam 未能退出。请选择“Steam”>“退出 Steam”,然后重试。如果 Steam 没有响应,请在“活动监视器”中退出它。"
}
}
}
diff --git a/app/Tests/BridgeplayAppTests/SteamBundleTests.swift b/app/Tests/BridgeplayAppTests/SteamBundleTests.swift
index 059fb61..e726207 100644
--- a/app/Tests/BridgeplayAppTests/SteamBundleTests.swift
+++ b/app/Tests/BridgeplayAppTests/SteamBundleTests.swift
@@ -48,29 +48,40 @@ struct SteamBundleTests {
// MARK: Stopping Steam
- // A stand-in Steam: running here and in another account, and whether it quits when asked.
+ // A stand-in Steam: running here and in another account, and which request it quits on.
private final class FakeSteam: @unchecked Sendable {
+ enum Request: Comparable { case exitURL, quit, never }
+
private let lock = NSLock()
private var here: Bool
private var elsewhere: Bool
- private let quits: Bool
- private(set) var asked = 0
+ private let quitsOn: Request
+ private(set) var requests: [Request] = []
private(set) var swept: [String] = []
- init(here: Bool, elsewhere: Bool = false, quits: Bool = true) {
+ init(here: Bool, elsewhere: Bool = false, quitsOn: Request = .exitURL) {
self.here = here
self.elsewhere = elsewhere
- self.quits = quits
+ self.quitsOn = quitsOn
+ }
+
+ private func receive(_ request: Request) {
+ lock.withLock {
+ requests.append(request)
+ if request >= quitsOn { here = false }
+ }
}
var client: SteamBundle.Client {
SteamBundle.Client(
runningAnywhere: { self.lock.withLock { self.here || self.elsewhere } },
runningHere: { self.lock.withLock { self.here } },
- askToQuit: { self.lock.withLock { self.asked += 1; if self.quits { self.here = false } } },
+ askToQuit: { self.receive(.exitURL) },
+ requestQuit: { self.receive(.quit) },
sweep: { pattern in self.lock.withLock { self.swept.append(pattern) } },
pause: {},
- attempts: 3)
+ attempts: 3,
+ escalationAttempts: 2)
}
}
@@ -83,7 +94,7 @@ struct SteamBundleTests {
func closedSteamIsLeftAlone() throws {
let steam = FakeSteam(here: false)
#expect(try stop(steam) == false)
- #expect(steam.asked == 0)
+ #expect(steam.requests.isEmpty)
#expect(steam.swept.isEmpty)
}
@@ -91,17 +102,28 @@ struct SteamBundleTests {
func steamThatQuitsIsStopped() throws {
let steam = FakeSteam(here: true)
#expect(try stop(steam))
- #expect(steam.asked == 1)
+ #expect(steam.requests == [.exitURL])
#expect(steam.swept == [#"/tmp/Steam\.app/"#])
}
- // It used to be killed with SIGKILL after 30 seconds, mid-write or mid-update.
- @Test("Steam that does not quit is reported, never killed")
+ // Issue #158: Steam on its login or update screen ignored steam://exit.
+ @Test("Steam that ignores steam://exit gets a macOS quit")
+ func steamThatIgnoresTheURLIsAskedByMacOS() throws {
+ let steam = FakeSteam(here: true, quitsOn: .quit)
+ #expect(try stop(steam))
+ #expect(steam.requests == [.exitURL, .quit])
+ #expect(steam.swept == [#"/tmp/Steam\.app/"#])
+ }
+
+ // It used to be killed with SIGKILL after 30 seconds, mid-write or mid-update. There is
+ // no kill in Client to reach for.
+ @Test("Steam that does not quit is reported with what to do, never swept")
func steamThatStaysIsReported() {
- let steam = FakeSteam(here: true, quits: false)
+ let steam = FakeSteam(here: true, quitsOn: .never)
let failure = #expect(throws: StepFailure.self) { try stop(steam) }
#expect(failure?.detail.contains("did not quit") == true)
- #expect(steam.asked == 1)
+ #expect(failure?.detail.contains("Activity Monitor") == true)
+ #expect(steam.requests == [.exitURL, .quit])
#expect(steam.swept.isEmpty)
}
@@ -111,14 +133,22 @@ struct SteamBundleTests {
let steam = FakeSteam(here: false, elsewhere: true)
let failure = #expect(throws: SteamBundle.OpenInAnotherAccount.self) { try stop(steam) }
#expect(failure?.localizedDescription.contains("another account") == true)
- #expect(steam.asked == 0)
+ #expect(steam.requests.isEmpty)
}
@Test("Steam open in two accounts is reported once this one has quit")
func bothAccountsSteamIsReported() {
let steam = FakeSteam(here: true, elsewhere: true)
#expect(throws: SteamBundle.OpenInAnotherAccount.self) { try stop(steam) }
- #expect(steam.asked == 1)
+ #expect(steam.requests == [.exitURL])
+ #expect(steam.swept.isEmpty)
+ }
+
+ @Test("Steam open in another account is reported even after this one needed a macOS quit")
+ func otherAccountAfterEscalation() {
+ let steam = FakeSteam(here: true, elsewhere: true, quitsOn: .quit)
+ #expect(throws: SteamBundle.OpenInAnotherAccount.self) { try stop(steam) }
+ #expect(steam.requests == [.exitURL, .quit])
#expect(steam.swept.isEmpty)
}