Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn running in Demo Mode #1963

Merged
merged 10 commits into from
Jan 2, 2023
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;
}
}