From 5071c3be1495b4d250c5167965302fe486dd07e0 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Mon, 10 Feb 2020 16:22:04 +0000
Subject: [PATCH] test-ui: Always offer to unshare home, with a clearer UI

Rephrase it so that in the UI, unsharing the home directory looks like
the active choice ("separate home directory"), with the shared home
directory as the passive/default choice.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel-test-ui | 55 ++++++++++++++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/pressure-vessel-test-ui b/pressure-vessel-test-ui
index f6f25bd8f..d13b36e14 100755
--- a/pressure-vessel-test-ui
+++ b/pressure-vessel-test-ui
@@ -44,8 +44,21 @@ from gi.repository import Gtk
 logger = logging.getLogger('pressure-vessel-test-ui')
 
 
-# This doesn't fully work yet. Hack at own risk.
-CAN_UNSHARE_HOME = (os.getenv('PRESSURE_VESSEL_SHARE_HOME') is not None)
+def tristate_environment(name):
+    # type: (str) -> typing.Optional[bool]
+    value = os.getenv(name)
+
+    if value is None or value == '':
+        return None
+
+    if value == '1':
+        return True
+
+    if value == '0':
+        return False
+
+    logger.warning('Unrecognised value %r for $%s', value, name)
+    return None
 
 
 class Gui:
@@ -129,17 +142,29 @@ class Gui:
 
         row += 1
 
-        if CAN_UNSHARE_HOME:
-            self.share_home_check = Gtk.CheckButton.new_with_label(
-                'Share real home directory'
-            )
-            self.share_home_check.set_active(
-                bool(os.getenv('PRESSURE_VESSEL_SHARE_HOME')))
-            self.grid.attach(self.share_home_check, 1, row, 1, 1)
+        self.unshare_home_check = Gtk.CheckButton.new_with_label(
+            'Use a separate home directory per game'
+        )
+        share_home = tristate_environment('PRESSURE_VESSEL_SHARE_HOME')
+        self.unshare_home_check.set_active(
+            share_home is not None and not share_home
+        )
+        self.grid.attach(self.unshare_home_check, 1, row, 1, 1)
+        row += 1
+
+        label = Gtk.Label.new('')
+        label.set_markup(
+            '<small><i>'
+            'Creating a separate home directory is experimental, '
+            'and is likely to break Steam Cloud Auto-Sync, Steam Workshop '
+            'and probably other features.'
+            '</i></small>'
+        )
+        label.set_halign(Gtk.Align.START)
+        label.set_line_wrap(True)
+        self.grid.attach(label, 1, row, 1, 1)
+        row += 1
 
-            row += 1
-        else:
-            self.share_home_check = None
 
         self.xterm_check = Gtk.CheckButton.new_with_label('Run in an xterm')
         self.xterm_check.set_active(False)
@@ -334,10 +359,10 @@ class Gui:
             argv.append('--runtime')
             argv.append(os.path.join(id, 'files'))
 
-        if self.share_home_check is None or self.share_home_check.get_active():
-            argv.append('--share-home')
-        else:
+        if self.unshare_home_check.get_active():
             argv.append('--unshare-home')
+        else:
+            argv.append('--share-home')
 
         if self.xterm_check.get_active():
             argv.append('--terminal=xterm')
-- 
GitLab