feat: add uptime on power profile (#349)

* feat: add uptime on power profile

* feat: add uptime on power profile

* feat: add uptime on power profile

* feat: add uptime on power profile

* Update modules/menus/energy/profiles/index.ts

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>

* Update modules/menus/energy/profiles/index.ts

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>

* Update modules/menus/energy/profiles/index.ts

* Update modules/menus/energy/profiles/index.ts

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-10-21 14:29:36 +05:45
committed by GitHub
parent 2126cf0657
commit ca664e3e78
2 changed files with 25 additions and 7 deletions

View File

@@ -1,12 +1,20 @@
const powerProfiles = await Service.import('powerprofiles'); const powerProfiles = await Service.import('powerprofiles');
import { PowerProfile, PowerProfileObject, PowerProfiles } from 'lib/types/powerprofiles.js'; import { PowerProfile, PowerProfileObject, PowerProfiles } from 'lib/types/powerprofiles.js';
import icons from '../../../icons/index.js';
import { BoxWidget } from 'lib/types/widget.js'; import { BoxWidget } from 'lib/types/widget.js';
import icons from '../../../icons/index.js';
import { uptime } from 'lib/variables.js';
const EnergyProfiles = (): BoxWidget => { const EnergyProfiles = (): BoxWidget => {
const isValidProfile = (profile: string): profile is PowerProfile => const isValidProfile = (profile: string): profile is PowerProfile =>
profile === 'power-saver' || profile === 'balanced' || profile === 'performance'; profile === 'power-saver' || profile === 'balanced' || profile === 'performance';
function renderUptime(curUptime: number): string {
const days = Math.floor(curUptime / (60 * 24));
const hours = Math.floor((curUptime % (60 * 24)) / 60);
const minutes = Math.floor(curUptime % 60);
return ` : ${days}d ${hours}h ${minutes}m`;
}
return Widget.Box({ return Widget.Box({
class_name: 'menu-section-container energy', class_name: 'menu-section-container energy',
vertical: true, vertical: true,
@@ -14,12 +22,19 @@ const EnergyProfiles = (): BoxWidget => {
Widget.Box({ Widget.Box({
class_name: 'menu-label-container', class_name: 'menu-label-container',
hpack: 'fill', hpack: 'fill',
child: Widget.Label({ children: [
Widget.Label({
class_name: 'menu-label', class_name: 'menu-label',
hexpand: true, hexpand: true,
hpack: 'start', hpack: 'start',
label: 'Power Profile', label: 'Power Profile',
}), }),
Widget.Label({
class_name: 'menu-label uptime',
label: uptime.bind().as(renderUptime),
tooltipText: 'Uptime',
}),
],
}), }),
Widget.Box({ Widget.Box({
class_name: 'menu-items-section', class_name: 'menu-items-section',

View File

@@ -22,6 +22,9 @@
background: if($bar-menus-monochrome, $bar-menus-cards, $bar-menus-menu-battery-card-color); background: if($bar-menus-monochrome, $bar-menus-cards, $bar-menus-menu-battery-card-color);
} }
.uptime {
font-size: 0.92em;
}
.menu-items-section { .menu-items-section {
background: if($bar-menus-monochrome, $bar-menus-cards, $bar-menus-menu-battery-card-color); background: if($bar-menus-monochrome, $bar-menus-cards, $bar-menus-menu-battery-card-color);