From 8953eea9e0b451d1038643d160a5f533b61e3c5e Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:26:07 -0500 Subject: [PATCH] fix(battlenet): keep the launch behavior a player chose in Battle.net (#2750) --- .../overlay/usr/local/bin/droiddeck-battlenet | 14 +++++++- tools/tests/test_battlenet.py | 34 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet index 1944635308..066f9c572e 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet @@ -321,6 +321,15 @@ def install_path(root, library): return letter.upper() + ":\\" + path[len(target):].strip("/").replace("/", "\\") +def keeps_open(root): + try: + with open(os.path.join(drive_c(root), *CONFIG), encoding="utf-8-sig") as f: + client = json.load(f).get("Client") + except (OSError, ValueError, AttributeError): + return False + return isinstance(client, dict) and LAUNCH_BEHAVIOR[0] in client and client[LAUNCH_BEHAVIOR[0]] != LAUNCH_BEHAVIOR[1] + + def write_config(root, library=None): path = os.path.join(drive_c(root), *CONFIG) key, value = LAUNCH_BEHAVIOR @@ -338,7 +347,7 @@ def write_config(root, library=None): return None client = config["Client"] changes = [] - if client.get(key) != value: + if key not in client: client[key] = value changes.append("launch") if client.get("HardwareAcceleration") != "false": @@ -875,6 +884,9 @@ class Tidy: self.game_since = self.game_since if self.game_since is not None else now if own and not self.closed_for_game and now - self.game_since >= self.settle: self.closed_for_game, self.agent_seen, self.agent_lost = True, False, None + if keeps_open(steam_root()): + say("Battle.net is set to stay open as a game launches: left open") + return False if any(is_client(argv) for _, argv in own) and any(shares_sign_in(argv) for argv in games): say("Battle.net stayed open beside a game signing in with its token: left open") return False diff --git a/tools/tests/test_battlenet.py b/tools/tests/test_battlenet.py index cc92c78cc4..ece44f60d6 100644 --- a/tools/tests/test_battlenet.py +++ b/tools/tests/test_battlenet.py @@ -180,7 +180,7 @@ class ConfigAndMenuTest(Temp): self.assertEqual(config["Client"]["Streaming"]["StreamingEnabled"], "false") self.assertEqual(config["Client"]["GameLaunchWindowBehavior"], "2") self.assertIsNone(BNET["write_config"](root)) - path.write_text('{"Client": {"HardwareAcceleration": "false", "GameLaunchWindowBehavior": "0"}, "Games": {"osi": {}}}') + path.write_text('{"Client": {"HardwareAcceleration": "false"}, "Games": {"osi": {}}}') self.assertEqual(BNET["write_config"](root), "launch 32-bit") config = json.loads(path.read_text()) self.assertEqual(config, {"Client": {"HardwareAcceleration": "false", "GameLaunchWindowBehavior": "2"}, @@ -189,6 +189,29 @@ class ConfigAndMenuTest(Temp): self.assertEqual(BNET["write_config"](root), "acceleration 32-bit") self.assertEqual(json.loads(path.read_text())["Client"]["HardwareAcceleration"], "false") + def test_a_launch_behavior_the_player_chose_is_kept(self): + root = str(self.tmp) + path = self.config_path() + path.parent.mkdir(parents=True) + for behavior in ("0", "1"): + with self.subTest(behavior): + path.write_text('{"Client": {"HardwareAcceleration": "false", "GameLaunchWindowBehavior": "%s"}, ' + '"Games": {"s1": {"Run64Bit": "false", "Run64BitSet": "true"}}}' % behavior) + self.assertIsNone(BNET["write_config"](root)) + self.assertEqual(json.loads(path.read_text())["Client"]["GameLaunchWindowBehavior"], behavior) + self.assertTrue(BNET["keeps_open"](root)) + + def test_only_a_launch_behavior_other_than_exit_keeps_battle_net_open(self): + root = str(self.tmp) + self.assertFalse(BNET["keeps_open"](root)) + path = self.config_path() + path.parent.mkdir(parents=True) + for text in ("{not json", "[1, 2]", '{"Client": "x"}', '{"Client": {}}', + '{"Client": {"GameLaunchWindowBehavior": "2"}}'): + with self.subTest(text): + path.write_text(text) + self.assertFalse(BNET["keeps_open"](root)) + def test_starcraft_starts_its_32_bit_client_until_a_player_picks_one(self): root = str(self.tmp) BNET["write_config"](root) @@ -656,6 +679,7 @@ class TidyTest(unittest.TestCase): "say": lambda message: None, "stop": lambda found, wait=0: self.stopped.append(sorted(pid for pid, _ in found)), "notify": lambda title, body, icon=None: self.notified.append(title), + "keeps_open": lambda root: False, }) patcher.start() self.addCleanup(patcher.stop) @@ -672,6 +696,14 @@ class TidyTest(unittest.TestCase): self.assertEqual(self.stopped, [[1, 2, 3]]) self.assertEqual(self.notified, []) + def test_battle_net_the_player_set_to_stay_open_is_left_open(self): + up = [self.CLIENT, self.PAGE, self.AGENT, self.WINE] + tidy = BNET["Tidy"](settle=20, gone=30) + with mock.patch.dict(BNET, {"keeps_open": lambda root: True}): + closed = self.run_tidy(tidy, [(0, up), (5, up + [self.GAME]), (25, up + [self.GAME]), (60, up + [self.GAME])]) + self.assertEqual(closed, [False, False, False, False]) + self.assertEqual(self.stopped, []) + def test_battle_net_beside_a_game_signing_in_with_its_token_is_left_open(self): d4 = (6, ["C:\\Program Files (x86)\\Diablo IV\\Diablo IV.exe", "-nostreamline", "-sso", "-launch", "-uid", "fenris"]) up = [self.CLIENT, self.PAGE, self.AGENT]