Skip to content

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

Fix launch alert, Steam detection, and download error edge cases

NotProtonNot08467be85dc1
diff --git a/app/Sources/NotProtonApp/Support/PinnedDownload.swift b/app/Sources/NotProtonApp/Support/PinnedDownload.swift
index a0de345..bdf461b 100644
--- a/app/Sources/NotProtonApp/Support/PinnedDownload.swift
+++ b/app/Sources/NotProtonApp/Support/PinnedDownload.swift
@@ -36,33 +36,43 @@ enum PinnedDownload {
for base in bases {
let host = base.host() ?? base.absoluteString
report(.fetching(host: host))
+ let body: URL, response: URLResponse
do {
- let (body, response) = try await URLSession.shared.download(from: base.appending(path: file))
- defer { try? FileManager.default.removeItem(at: body) }
+ (body, response) = try await URLSession.shared.download(from: base.appending(path: file))
+ } catch {
+ refusals.append("\(host): \(error.localizedDescription)")
+ kinds.insert(.unreachable)
+ continue
+ }
+ defer { try? FileManager.default.removeItem(at: body) }
- if let http = response as? HTTPURLResponse, http.statusCode != 200 {
- refusals.append("\(host) answered \(http.statusCode)")
- kinds.insert(.answered)
- continue
- }
+ if let http = response as? HTTPURLResponse, http.statusCode != 200 {
+ refusals.append("\(host) answered \(http.statusCode)")
+ kinds.insert(.answered)
+ continue
+ }
- let got = try Digest.sha256(of: body)
- guard got == sha256 else {
- refusals.append("\(host) served \(got.prefix(16)) rather than \(sha256.prefix(16))")
- kinds.insert(.mismatch)
- continue
- }
+ let got = try Digest.sha256(of: body)
+ guard got == sha256 else {
+ refusals.append("\(host) served \(got.prefix(16)) rather than \(sha256.prefix(16))")
+ kinds.insert(.mismatch)
+ continue
+ }
+ do {
try FileManager.default.createDirectory(
at: downloads, withIntermediateDirectories: true
)
try? FileManager.default.removeItem(at: archive)
try FileManager.default.moveItem(at: body, to: archive)
- return archive
} catch {
- refusals.append("\(host): \(error.localizedDescription)")
- kinds.insert(.unreachable)
+ throw StepFailure(
+ step: step,
+ detail: String(localized: "\(downloads.path(percentEncoded: false)) could not be written. ")
+ + error.localizedDescription
+ )
}
+ return archive
}
AppLog.note("\(file) refused by all \(bases.count) hosts: \(refusals.joined(separator: ". "))")
diff --git a/app/Sources/NotProtonApp/Support/Shell.swift b/app/Sources/NotProtonApp/Support/Shell.swift
index 4312c15..b434a03 100644
--- a/app/Sources/NotProtonApp/Support/Shell.swift
+++ b/app/Sources/NotProtonApp/Support/Shell.swift
@@ -151,7 +151,7 @@ enum Shell {
named name: String, pgrep: String = "/usr/bin/pgrep",
drainTimeout: DispatchTimeInterval = outputDrainTimeout
) -> Bool {
- guard let result = try? run(pgrep, ["-x", name], drainTimeout: drainTimeout)
+ guard let result = try? run(pgrep, ["-x", "-U", String(getuid()), name], drainTimeout: drainTimeout)
else { return false }
return result.succeeded
}
diff --git a/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift b/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
index 0ee6cd1..1a719ad 100644
--- a/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
+++ b/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
@@ -88,6 +88,30 @@ struct PinnedDownloadTests {
#expect(try String(contentsOf: got, encoding: .utf8) == body)
}
+ @Test("A download that cannot be saved is not blamed on the network")
+ func saveFailureIsNotUnreachable() async throws {
+ let work = try scratchDirectory("pinned")
+ defer { try? FileManager.default.removeItem(at: work) }
+
+ let body = "the real package"
+ let first = try host(work, named: "package.tar", serving: body)
+ let second = try host(work, named: "package.tar", serving: body)
+ let downloads = work.appending(path: "downloads")
+ try Data("not a folder".utf8).write(to: downloads)
+ let reported = Reports()
+
+ let failure = try await #require(throws: StepFailure.self) {
+ _ = try await PinnedDownload.obtain(
+ file: "package.tar", sha256: Digest.sha256(of: Data(body.utf8)),
+ bases: [first, second], into: downloads, step: "test",
+ report: { reported.add($0.label) })
+ }
+
+ #expect(!failure.detail.contains("could not reach"))
+ #expect(failure.detail.contains(downloads.path(percentEncoded: false)))
+ #expect(reported.all.count == 1)
+ }
+
@Test("An archive already on disk that matches is not fetched again")
func reusesMatchingArchive() async throws {
let work = try scratchDirectory("pinned")
diff --git a/app/Tests/NotProtonAppTests/ShellTests.swift b/app/Tests/NotProtonAppTests/ShellTests.swift
index 5105425..db652c0 100644
--- a/app/Tests/NotProtonAppTests/ShellTests.swift
+++ b/app/Tests/NotProtonAppTests/ShellTests.swift
@@ -114,6 +114,11 @@ struct ShellTests {
named: "anything", pgrep: pgrep, drainTimeout: .milliseconds(200)))
}
+ @Test("A process another account runs does not count")
+ func anotherAccountsProcessDoesNotCount() {
+ #expect(Shell.processIsRunning(named: "WindowServer") == false)
+ }
+
@Test("Nothing matching reports nothing running")
func noMatchReportsNothingRunning() throws {
let (pgrep, dir) = try stubPgrep(body: "exit 1")
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index d1c6703..f24cbac 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -293,6 +293,7 @@ tool_name() {
# Steam passes "run" for helpers such as install scripts, which get no dialog.
show_alert() {
[ "$verb" != run ] || return 0
+ exec 8>&- 9>&-
osascript >/dev/null 2>&1 <<APPLESCRIPT || true
display alert "$1" message "$2" as critical
APPLESCRIPT
diff --git a/dylib/tests/buildcheck.sh b/dylib/tests/buildcheck.sh
index 35bb165..c9cf614 100644
--- a/dylib/tests/buildcheck.sh
+++ b/dylib/tests/buildcheck.sh
@@ -84,6 +84,27 @@ last run by CrossOver Preview (FEX)
CrossOver Preview (FEX)
")"
+echo "== alerts =="
+alert=$(extract show_alert)
+[ -n "$alert" ] || { echo "FAIL: show_alert not found in $SRC"; exit 1; }
+data=$(mktemp -d "$work/compatdata.XXXXXX")
+(
+ verb=waitforexitandrun
+ # shellcheck disable=SC2329 # show_alert runs this in place of the real dialog
+ osascript() {
+ if /usr/bin/lockf -s -t 0 "$data/.notproton-prefix.lock" true; then
+ echo free > "$data/during-alert"
+ else
+ echo held > "$data/during-alert"
+ fi
+ }
+ eval "$alert"
+ exec 8>> "$data/.notproton-prefix.lock"
+ /usr/bin/lockf -s -t 0 8
+ show_alert "title" "message"
+)
+is "an open alert does not keep the prefix locked" "free" "$(cat "$data/during-alert" 2>/dev/null)"
+
if [ "$fails" -eq 0 ]; then
echo "==> buildcheck: all assertions hold"
else