[gnome-initial-setup: 2/20] gnome-initial-setup: Add mock infrastructure to prevent saving changes
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup: 2/20] gnome-initial-setup: Add mock infrastructure to prevent saving changes
- Date: Fri, 14 Feb 2020 16:48:53 +0000 (UTC)
commit a141d26ce0599d1201dede3eb62878199eb41c9c
Author: Philip Withnall <withnall endlessm com>
Date: Thu Feb 6 15:24:13 2020 +0000
gnome-initial-setup: Add mock infrastructure to prevent saving changes
When testing gnome-initial-setup, it’s useful to be able to run out of
the build directory and test the UI without committing changes to disk
permanently. Support that by disabling saving changes if in ‘mock mode’,
which is currently enabled when running in a JHBuild shell.
Signed-off-by: Philip Withnall <withnall endlessm com>
gnome-initial-setup/gis-driver.c | 7 +++++++
gnome-initial-setup/gnome-initial-setup.c | 23 ++++++++++++++++++++++-
gnome-initial-setup/gnome-initial-setup.h | 1 +
meson.build | 9 +++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index f172458..b3f6606 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -739,6 +739,13 @@ void
gis_driver_save_data (GisDriver *driver)
{
GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+
+ if (gis_get_mock_mode ())
+ {
+ g_message ("%s: Skipping saving data due to being in mock mode", G_STRFUNC);
+ return;
+ }
+
gis_assistant_save_data (priv->assistant);
}
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 2c3836c..b1eedb9 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -255,6 +255,10 @@ main (int argc, char *argv[])
gtk_init (&argc, &argv);
g_message ("Starting gnome-initial-setup");
+ if (gis_get_mock_mode ())
+ g_message ("Mock mode: changes will not be saved to disk");
+ else
+ g_message ("Production mode: changes will be saved to disk");
skipped_pages = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_widget_destroy);
mode = get_mode ();
@@ -264,7 +268,7 @@ main (int argc, char *argv[])
* the keyring manually so that we can pass the credentials
* along to the new user in the handoff.
*/
- if (mode == GIS_DRIVER_MODE_NEW_USER)
+ if (mode == GIS_DRIVER_MODE_NEW_USER && !gis_get_mock_mode ())
gis_ensure_login_keyring ();
driver = gis_driver_new (mode);
@@ -298,3 +302,20 @@ gis_ensure_stamp_files (void)
}
g_free (file);
}
+
+/**
+ * gis_get_mock_mode:
+ *
+ * Gets whether gnome-initial-setup has been built for development, and hence
+ * shouldn’t permanently change any system configuration.
+ *
+ * By default, mock mode is enabled when running in a build environment. This
+ * heuristic may be changed in future.
+ *
+ * Returns: %TRUE if in mock mode, %FALSE otherwise
+ */
+gboolean
+gis_get_mock_mode (void)
+{
+ return (g_getenv ("UNDER_JHBUILD") != NULL);
+}
diff --git a/gnome-initial-setup/gnome-initial-setup.h b/gnome-initial-setup/gnome-initial-setup.h
index dc5cf60..b6af4f3 100644
--- a/gnome-initial-setup/gnome-initial-setup.h
+++ b/gnome-initial-setup/gnome-initial-setup.h
@@ -36,6 +36,7 @@ typedef struct _GisPage GisPage;
#include "gis-keyring.h"
void gis_ensure_stamp_files (void);
+gboolean gis_get_mock_mode (void);
#endif /* __GNOME_INITIAL_SETUP_H__ */
diff --git a/meson.build b/meson.build
index e667997..4c3ec4f 100644
--- a/meson.build
+++ b/meson.build
@@ -30,6 +30,15 @@ conf.set_quoted('PKGDATADIR', pkgdata_dir)
conf.set('SECRET_API_SUBJECT_TO_CHANGE', true)
conf.set_quoted('G_LOG_DOMAIN', 'InitialSetup')
+version_arr = meson.project_version().split('.')
+major_version = version_arr[0].to_int()
+minor_version = version_arr[1].to_int()
+micro_version = version_arr[2].to_int()
+
+conf.set('GIS_MAJOR_VERSION', major_version)
+conf.set('GIS_MINOR_VERSION', minor_version)
+conf.set('GIS_MICRO_VERSION', micro_version)
+
enable_systemd = get_option('systemd')
if enable_systemd
systemd_dep = dependency('systemd', required: false)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]