Skip to content

Commit

Permalink
Warn running in Demo Mode (#1963)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl committed Jan 2, 2023
1 parent f4369fa commit 4c755a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public class AppCenterCore.Client : Object {
public async void update_cache (bool force = false, CacheUpdateType cache_update_type = CacheUpdateType.ALL) {
cancellable.reset ();

if (Utils.is_running_in_demo_mode ()) {
return;
}

debug ("update cache called %s", force.to_string ());
bool success = false;

Expand Down
18 changes: 18 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
box.add (headerbar);
box.add (network_info_bar);

if (Utils.is_running_in_demo_mode ()) {
var demo_mode_info_bar_label = new Gtk.Label ("<b>%s</b> %s".printf (
_("Running in Demo Mode"),
_("Install %s to browse and install apps.").printf (Environment.get_os_info (GLib.OsInfoKey.NAME))
)) {
use_markup = true,
wrap = true
};

var demo_mode_info_bar = new Gtk.InfoBar () {
message_type = Gtk.MessageType.WARNING
};
demo_mode_info_bar.get_content_area ().add (demo_mode_info_bar_label);

box.add (demo_mode_info_bar);
}

box.add (overlay);
box.show_all ();

Expand Down
17 changes: 17 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,21 @@ namespace Utils {
.replace ("&gt;", ">")
.replace ("&#39;", "'");
}

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;
}
}

0 comments on commit 4c755a4

Please sign in to comment.