From 50a329fba49b0be31dc0d174160c3e1229d78171 Mon Sep 17 00:00:00 2001 From: AkshayWarrier Date: Sat, 12 Aug 2023 03:34:59 +0530 Subject: [PATCH 1/2] library: Add Power Profile Monitor demo --- .../demos/Power Profile Monitor/main.blp | 31 +++++++++++++++++++ .../demos/Power Profile Monitor/main.js | 16 ++++++++++ .../demos/Power Profile Monitor/main.json | 6 ++++ 3 files changed, 53 insertions(+) create mode 100644 src/Library/demos/Power Profile Monitor/main.blp create mode 100644 src/Library/demos/Power Profile Monitor/main.js create mode 100644 src/Library/demos/Power Profile Monitor/main.json diff --git a/src/Library/demos/Power Profile Monitor/main.blp b/src/Library/demos/Power Profile Monitor/main.blp new file mode 100644 index 000000000..472b88929 --- /dev/null +++ b/src/Library/demos/Power Profile Monitor/main.blp @@ -0,0 +1,31 @@ +using Gtk 4.0; +using Adw 1; + +Adw.ToastOverlay overlay { + Adw.StatusPage { + title: _("Power Profile Monitor"); + description: _("An API to monitor system power profiles"); + + Box { + spacing: 24; + orientation: vertical; + + Box { + halign: center; + spacing: 6; + Image { + icon-name: "lightbulb-symbolic"; + styles ["dim-label"] + } + Label { + label: _("Try toggling Power Mode to \"Power Saver\" from Settings > Power\n or from Quick settings"); + styles ["dim-label"] + } + } + + LinkButton { + label: "API Reference"; + } + } + } +} diff --git a/src/Library/demos/Power Profile Monitor/main.js b/src/Library/demos/Power Profile Monitor/main.js new file mode 100644 index 000000000..5a77dcfc4 --- /dev/null +++ b/src/Library/demos/Power Profile Monitor/main.js @@ -0,0 +1,16 @@ +import Adw from "gi://Adw"; +import Gio from "gi://Gio"; + +const power_profile_monitor = Gio.PowerProfileMonitor.dup_default(); +const overlay = workbench.builder.get_object("overlay"); + +power_profile_monitor.connect("notify::power-saver-enabled", () => { + if (power_profile_monitor.power_saver_enabled) { + const toast = new Adw.Toast({ + title: "Paused to save power", + button_label: "Resume", + priority: Adw.ToastPriority.HIGH, + }); + overlay.add_toast(toast); + } +}); diff --git a/src/Library/demos/Power Profile Monitor/main.json b/src/Library/demos/Power Profile Monitor/main.json new file mode 100644 index 000000000..6d5d56885 --- /dev/null +++ b/src/Library/demos/Power Profile Monitor/main.json @@ -0,0 +1,6 @@ +{ + "category": "platform", + "description": "An API to monitor system power profiles", + "panels": ["code", "preview"], + "autorun": true +} From e219470f62107ed03a5942acb9b6fa02e296e48e Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 13 Aug 2023 16:04:45 +0200 Subject: [PATCH 2/2] small improvements --- src/Library/demos/Power Profile Monitor/main.blp | 5 +++-- src/Library/demos/Power Profile Monitor/main.js | 15 ++++++++++++--- src/Library/demos/Power Profile Monitor/main.json | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Library/demos/Power Profile Monitor/main.blp b/src/Library/demos/Power Profile Monitor/main.blp index 472b88929..4e4555892 100644 --- a/src/Library/demos/Power Profile Monitor/main.blp +++ b/src/Library/demos/Power Profile Monitor/main.blp @@ -4,7 +4,7 @@ using Adw 1; Adw.ToastOverlay overlay { Adw.StatusPage { title: _("Power Profile Monitor"); - description: _("An API to monitor system power profiles"); + description: _("Monitor Power Mode"); Box { spacing: 24; @@ -18,13 +18,14 @@ Adw.ToastOverlay overlay { styles ["dim-label"] } Label { - label: _("Try toggling Power Mode to \"Power Saver\" from Settings > Power\n or from Quick settings"); + label: _("Try toggling Power Mode to \"Power Saver\" from Settings → Power\n or from Quick Toggles"); styles ["dim-label"] } } LinkButton { label: "API Reference"; + uri: "https://docs.gtk.org/gio/iface.PowerProfileMonitor.html"; } } } diff --git a/src/Library/demos/Power Profile Monitor/main.js b/src/Library/demos/Power Profile Monitor/main.js index 5a77dcfc4..604b29d6b 100644 --- a/src/Library/demos/Power Profile Monitor/main.js +++ b/src/Library/demos/Power Profile Monitor/main.js @@ -5,12 +5,21 @@ const power_profile_monitor = Gio.PowerProfileMonitor.dup_default(); const overlay = workbench.builder.get_object("overlay"); power_profile_monitor.connect("notify::power-saver-enabled", () => { + let toast; + if (power_profile_monitor.power_saver_enabled) { - const toast = new Adw.Toast({ - title: "Paused to save power", + toast = new Adw.Toast({ + title: "Backup paused to save power", button_label: "Resume", priority: Adw.ToastPriority.HIGH, }); - overlay.add_toast(toast); + } else { + toast = new Adw.Toast({ + title: "Backup resumed", + priority: Adw.ToastPriority.HIGH, + }); } + + overlay.add_toast(toast); }); + diff --git a/src/Library/demos/Power Profile Monitor/main.json b/src/Library/demos/Power Profile Monitor/main.json index 6d5d56885..3a9be6e2f 100644 --- a/src/Library/demos/Power Profile Monitor/main.json +++ b/src/Library/demos/Power Profile Monitor/main.json @@ -1,6 +1,6 @@ { "category": "platform", - "description": "An API to monitor system power profiles", + "description": "Monitor Power Mode", "panels": ["code", "preview"], "autorun": true }