From c5fd1da26919aca035235c29d14d845145e2d09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 28 Oct 2024 17:50:37 -0700 Subject: [PATCH] Don't check for updates in demo mode (#163) --- src/Backends/SystemUpdate.vala | 4 ++++ src/Utils/SessionUtils.vala | 23 +++++++++++++++++++++++ src/meson.build | 1 + 3 files changed, 28 insertions(+) create mode 100644 src/Utils/SessionUtils.vala diff --git a/src/Backends/SystemUpdate.vala b/src/Backends/SystemUpdate.vala index e8902632..7908d369 100644 --- a/src/Backends/SystemUpdate.vala +++ b/src/Backends/SystemUpdate.vala @@ -65,6 +65,10 @@ public class SettingsDaemon.Backends.SystemUpdate : Object { } public async void check_for_updates (bool force, bool notify) throws DBusError, IOError { + if (SettingsDaemon.Utils.is_running_in_demo_mode () && !force) { + return; + } + if (current_state.state != UP_TO_DATE && current_state.state != AVAILABLE && !force) { return; } diff --git a/src/Utils/SessionUtils.vala b/src/Utils/SessionUtils.vala new file mode 100644 index 00000000..92c23573 --- /dev/null +++ b/src/Utils/SessionUtils.vala @@ -0,0 +1,23 @@ +/* + * Copyright 2024 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +namespace SettingsDaemon.Utils { + public static bool is_running_in_demo_mode () { + var proc_cmdline = File.new_for_path ("/proc/cmdline"); + try { + var @is = proc_cmdline.read (); + var dis = new DataInputStream (@is); + + var line = dis.read_line (); + if ("boot=casper" in line || "boot=live" in line || "rd.live.image" in line) { + return true; + } + } catch (Error e) { + critical ("Couldn't detect if running in Demo Mode: %s", e.message); + } + + return false; + } +} diff --git a/src/meson.build b/src/meson.build index eda9764c..472148b9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,6 +11,7 @@ sources = files( 'Backends/PrefersColorSchemeSettings.vala', 'Backends/SystemUpdate.vala', 'Utils/PkUtils.vala', + 'Utils/SessionUtils.vala', 'Utils/SunriseSunsetCalculator.vala', )