Compare commits

..
Author SHA1 Message Date
maxjivi05 b70199bf4d fix(flatpak): preserve Electron node mode arguments 2026-12-01 00:52:06 -05:00
4 changed files with 20 additions and 71 deletions

No files matched your search

@@ -325,7 +325,7 @@ object BwrapSpawner {
private const val PRELOAD_DIR = "/run/droiddeck-preload"
private const val NET_LINK = "etc/droiddeck-net"
private const val ZYPAK_SHIM = "#!/bin/sh\nprogram=\$1\nshift\nexec \"\$program\" --no-sandbox \"\$@\"\n"
private const val ZYPAK_SHIM = "#!/bin/sh\nprogram=\$1\nshift\nif [ -n \"\${ELECTRON_RUN_AS_NODE:-}\" ]; then\n exec \"\$program\" \"\$@\"\nfi\nexec \"\$program\" --no-sandbox \"\$@\"\n"
private fun zypakShims(binds: List<Bind>, root: File, dir: File): List<Bind> {
val wrappers = listOf("/app/bin/zypak-wrapper.sh", "/app/bin/zypak-wrapper").filter { guest ->
@@ -263,6 +263,21 @@ class BwrapSpawnerPlanTest {
val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }
assertTrue(shim.host.startsWith(dir.path))
assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\""))
fun runShim(mode: String?, program: String): List<String> {
val executable = File(dir, program).apply { writeText("#!/bin/sh\nprintf '%s\\n' \"\$@\"\n"); setExecutable(true) }
val process = ProcessBuilder("/bin/sh", shim.host, executable.path, "argument with spaces", "--user-flag")
if (mode == null) process.environment().remove("ELECTRON_RUN_AS_NODE")
else process.environment()["ELECTRON_RUN_AS_NODE"] = mode
val child = process.start()
val output = child.inputStream.bufferedReader().readLines()
assertEquals(0, child.waitFor())
return output
}
val args = listOf("argument with spaces", "--user-flag")
assertEquals(args, runShim("1", "code"))
assertEquals(args, runShim("0", "another-electron-app"))
assertEquals(listOf("--no-sandbox") + args, runShim(null, "code"))
assertEquals(listOf("--no-sandbox") + args, runShim("", "another-electron-app"))
assertFalse(plan.binds.any { it.guest == "/app/bin/zypak-wrapper" })
assertTrue(File(app, "bin/zypak-wrapper.sh").readText().contains("zypak-helper"))
}
@@ -979,7 +979,7 @@ def launched(argv):
def shares_sign_in(argv):
return any(arg.lower() in ("-sso", "-launcherlogin") for arg in argv[1:])
return "-sso" in (arg.lower() for arg in argv[1:])
def agent_up(processes):
@@ -993,7 +993,6 @@ class Tidy:
self.gone = AGENT_GONE if gone is None else gone
self.game_since = None
self.closed_for_game = False
self.retained_for_sign_in = False
self.agent_seen = False
self.agent_lost = None
@@ -1002,23 +1001,19 @@ class Tidy:
games = [argv for _, argv in processes if launched(argv)]
if games:
self.game_since = self.game_since if self.game_since is not None else now
client_open = any(is_client(argv) for _, argv in own)
cleanup_pending = not self.closed_for_game or (self.retained_for_sign_in and not client_open)
if own and cleanup_pending and now - self.game_since >= self.settle:
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
self.retained_for_sign_in = False
if keeps_open(steam_root()):
say("Battle.net is set to stay open as a game launches: left open")
return False
if client_open and any(shares_sign_in(argv) for argv in games):
self.retained_for_sign_in = True
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
say("the game is up: closing what is left of Battle.net (%d process(es)) to leave it their memory" % len(own))
stop(own)
return True
return False
self.game_since, self.closed_for_game, self.retained_for_sign_in = None, False, False
self.game_since, self.closed_for_game = None, False
if not any(is_client(argv) for _, argv in processes):
self.agent_seen, self.agent_lost = False, None
elif agent_up(processes):
-61
View File
@@ -689,13 +689,6 @@ class ProcessTest(Temp):
self.assertFalse(BNET["shares_sign_in"](["D2R.exe", "-uid", "osi"]))
self.assertFalse(BNET["shares_sign_in"](["-sso.exe"]))
def test_sign_in_flags_are_whole_arguments_after_the_program(self):
for argv in (["Example.exe", "-launcherlogin"], ["Example.exe", "-LAUNCHERLOGIN"]):
self.assertTrue(BNET["shares_sign_in"](argv))
for argv in ([], ["-launcherlogin"], ["Example.exe", "--launcherlogin"],
["Example.exe", "-launcherlogin=false"], ["Example.exe", "path/-launcherlogin"]):
self.assertFalse(BNET["shares_sign_in"](argv))
def test_battle_net_takes_work_once_its_agent_is_up(self):
client = (1, ["C:\\Program Files (x86)\\Battle.net\\Battle.net.exe"])
agent = (2, ["C:\\ProgramData\\Battle.net\\Agent\\Agent.9824\\Agent.exe"])
@@ -877,51 +870,6 @@ class TidyTest(unittest.TestCase):
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_launcher_sign_in_keeps_the_client_without_a_time_limit(self):
for flag in ("-launcherlogin", "-LAUNCHERLOGIN"):
with self.subTest(flag=flag):
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.PAGE, self.AGENT, game]
self.assertEqual(self.run_tidy(tidy, [(0, up), (20, up), (120, up), (3600, up)]),
[False, False, False, False])
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_launcher_sign_in_still_reclaims_helpers_after_the_client_exits(self):
game = (6, ["C:\\Games\\Example.exe", "-launcherlogin", "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
self.run_tidy(tidy, [(0, [self.CLIENT, self.AGENT, game]),
(5, [self.AGENT, game]), (20, [self.AGENT, game])])
self.assertEqual(self.stopped, [[3]])
def test_sign_in_helpers_are_reclaimed_after_a_post_settle_client_exit(self):
for flag in ("-sso", "-launcherlogin"):
with self.subTest(flag=flag):
self.stopped.clear()
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.PAGE, self.AGENT, self.WINE, game]
remaining = [self.AGENT, self.WINE, game]
closed = self.run_tidy(tidy, [(0, up), (20, up), (29, up), (30, remaining),
(40, remaining)])
self.assertEqual(closed, [False, False, False, True, False])
self.assertEqual(self.stopped, [[3]])
self.assertEqual(self.notified, [])
def test_stay_open_preference_preserves_helpers_after_a_post_settle_client_exit(self):
for flag in ("-sso", "-launcherlogin"):
with self.subTest(flag=flag):
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.AGENT, game]
with mock.patch.dict(BNET, {"keeps_open": lambda root: True}):
closed = self.run_tidy(tidy, [(0, up), (20, up), (30, [self.AGENT, game]),
(120, [self.AGENT, game])])
self.assertEqual(closed, [False, False, False, False])
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_what_battle_net_left_beside_such_a_game_once_closed_itself_is_stopped(self):
d4 = (6, ["C:\\Program Files (x86)\\Diablo IV\\Diablo IV.exe", "-sso", "-launch", "-uid", "fenris"])
tidy = BNET["Tidy"](settle=20, gone=30)
@@ -1233,15 +1181,6 @@ class LaunchTest(Harness):
self.assertEqual(BNET["launch"](self.root, "Fen"), 0)
self.assertEqual([c for c in self.calls if c[0] == "stop"], [("stop", [10, 11, 12, 13, 14, 30])])
def test_launcher_sign_in_keeps_the_client_until_the_game_exits(self):
self.install()
up = self.clients() + [(30, self.AGENT)]
game = (40, ["C:\\Games\\Example.exe", "-launcherlogin", "-uid", "example"])
self.states = [[], [], up, up + [game], up + [game], up + [game], up, up]
with mock.patch.dict(BNET, {"GAME_SETTLE": 0}):
self.assertEqual(BNET["launch"](self.root, "Example"), 0)
self.assertEqual([c for c in self.calls if c[0] == "stop"], [("stop", [10, 11, 12, 13, 14, 30])])
def test_a_game_installed_in_battle_nets_folder_is_followed_not_stopped(self):
self.install()
up = self.clients() + [(30, self.AGENT)]