Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

Steam import: skip games Steam lists without a name instead of refusing the library (#208)

Mikeke581fd78277c
diff --git a/app/SteamLogin.swift b/app/SteamLogin.swift
index c83ec3cecb6..51169f0287c 100644
--- a/app/SteamLogin.swift
+++ b/app/SteamLogin.swift
@@ -94,9 +94,10 @@ enum SteamWebSession {
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
if (error as NSError).code != NSURLErrorCancelled { message = "Steam could not load. Check your connection and retry." }
}
- private func importFailed() {
+ private func importFailed(_ why: String? = nil) {
failures += 1
- message = "Steam’s game list could not be read yet. Let the page load or choose Retry import. Your previous library is kept."
+ let code = why.map { " (\($0))" } ?? ""
+ message = "Steam’s game list could not be read yet\(code). Let the page load or choose Retry import. Your previous library is kept."
if failures >= 5 { timer?.invalidate(); timer = nil }
}
private func checkLibrary() {
@@ -123,7 +124,7 @@ enum SteamWebSession {
self.web.load(URLRequest(url: URL(string: "https://steamcommunity.com/my/games/?tab=all")!))
} else { self.message = "Let your All Games page load, then choose Retry import if needed." }
case "unavailable":
- self.importFailed()
+ self.importFailed(value["why"] as? String)
case "sign-in":
self.message = "Finish signing in on Steam’s page. Your games will import automatically; installing Windows Steam is not required."
default: break
diff --git a/resources/steam-library.js b/resources/steam-library.js
index 544bec52b48..c3fec19f8a5 100644
--- a/resources/steam-library.js
+++ b/resources/steam-library.js
@@ -28,19 +28,20 @@ function reactToken() {
function snapshot(rows, count) {
if (!Array.isArray(rows) || !Number.isInteger(count) || count < 0 ||
- count > 20000 || rows.length !== count) return { state: "unavailable" };
+ count > 20000 || rows.length !== count) return { state: "unavailable", why: "count" };
const games = [];
const seen = new Set();
for (const row of rows) {
- if (!row || !/^[1-9][0-9]{0,9}$/.test(String(row.appid)) ||
- typeof row.name !== "string" || !row.name.trim() || row.name.length > 1000) {
- return { state: "unavailable" };
- }
+ if (!row || !/^[1-9][0-9]{0,9}$/.test(String(row.appid))) return { state: "unavailable", why: "appid" };
const appid = String(row.appid);
- if (seen.has(appid)) return { state: "unavailable" };
+ // Steam lists some apps without a name (delisted games, test servers, tools).
+ // Skip those rows instead of refusing the whole library; repeated rows count once.
+ if (typeof row.name !== "string" || !row.name.trim() || row.name.length > 1000 || seen.has(appid)) continue;
seen.add(appid);
games.push({ appid, name: row.name.trim().slice(0, 300) });
}
+ // Rows that all lack a name must not replace a library with an empty one.
+ if (count > 0 && games.length === 0) return { state: "unavailable", why: "names" };
return { state: "ready", steamid, game_count: games.length, games };
}
@@ -93,10 +94,10 @@ try {
const payload = await readJSON("https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?" + params,
"omit", 8 * 1024 * 1024);
const value = payload.response;
- if (!value || !Object.prototype.hasOwnProperty.call(value, "game_count")) return { state: "unavailable" };
+ if (!value || !Object.prototype.hasOwnProperty.call(value, "game_count")) return { state: "unavailable", why: "private" };
return snapshot(value.games || [], value.game_count);
} catch {
- return { state: "unavailable" };
+ return { state: "unavailable", why: "request" };
} finally {
clearTimeout(timer);
}
diff --git a/tests/test_steam_login.cjs b/tests/test_steam_login.cjs
index 7fec2b48503..a8ff7a94c2d 100644
--- a/tests/test_steam_login.cjs
+++ b/tests/test_steam_login.cjs
@@ -42,20 +42,29 @@ test("the web session stays in the Steam request and never the returned snapshot
assert.equal(value.state, "ready");
assert.ok(!JSON.stringify(value).includes(user.webapi_token));
});
-test("private, incomplete, duplicate and invalid responses do not become empty libraries", async () => {
- for (const response of [{}, {game_count:1,games:[]}, {game_count:2,games:[{appid:10,name:"A"},{appid:10,name:"A"}]},
- {game_count:1,games:[{appid:"../10",name:"A"}]}, {game_count:1,games:[{appid:10,name:""}]}]) {
+test("private, incomplete and invalid responses do not become empty libraries", async () => {
+ for (const response of [{}, {game_count:1,games:[]}, {game_count:1,games:[{appid:"../10",name:"A"}]},
+ {game_count:1,games:[{appid:10,name:""}]}, {game_count:2,games:[{appid:10},{appid:20,name:" "}]}]) {
const value = await run(...context({logged_in:true,steamid:id,webapi_token:"test"}), async () => ({ok:true,text:async()=>JSON.stringify({response})}));
assert.equal(value.state, "unavailable");
+ assert.ok(typeof value.why === "string");
}
});
+test("unnamed and repeated rows are skipped, not the whole library", async () => {
+ const response = {game_count:5, games:[{appid:730,name:"Counter-Strike 2"},{appid:1097150,name:"Fall Guys"},
+ {appid:578080,name:"PUBG: BATTLEGROUNDS"},{appid:622590},{appid:730,name:"Counter-Strike 2"}]};
+ const value = await run(...context({logged_in:true,steamid:id,webapi_token:"test"}), async () => ({ok:true,text:async()=>JSON.stringify({response})}));
+ assert.equal(value.state, "ready");
+ assert.deepEqual(value.games.map(g => g.appid), ["730", "1097150", "578080"]);
+ assert.equal(value.game_count, 3);
+});
test("an explicitly empty owned library is valid", async () => {
const value = await run(...context({logged_in:true,steamid:id,webapi_token:"test"}), async()=>({ok:true,text:async()=>JSON.stringify({response:{game_count:0}})}));
assert.equal(value.state, "ready"); assert.deepEqual(value.games, []);
});
test("request failures return no raw URL, session or exception", async () => {
const value = await run(...context({logged_in:true,steamid:id,webapi_token:"test-secret"}), async()=>{throw Error("test-secret");});
- assert.deepEqual(value, {state:"unavailable"});
+ assert.deepEqual(value, {state:"unavailable", why:"request"});
});
test("conflicting account identity cannot import a stale profile", async () => {