* feat: launcher icon auto detect from os name * feat: add more * fix: revamp distro icon * feat: on hover only show actions if available on notifications (#396) * feat: on hover only show actions if available on notifications * feat: on hover only show actions if available on notifications * fix: make the change configurable * fix: remove unneeded op * Added the ability to scale a popover. (#443) * Added the ability to scale a popover. * Removed redundant code * Provide a cli command to clear notifications. (#444) * Added a cpu temperature custom module. (#446) * Added a CPU Temperature module. * Update defauls and add wiki link. * Move celsius to fahr conversion to method. * fix: move distoicons , use capitalizeLetter func * fix: lint * Rename dissto.ts to distro.ts * Update lib/utils.ts --------- Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { PowerOptions } from 'lib/types/options';
|
|
import { GButton } from 'lib/types/widget';
|
|
import { capitalizeFirstLetter } from 'lib/utils';
|
|
import options from 'options';
|
|
import powermenu from '../power/helpers/actions';
|
|
|
|
const { confirmation, shutdown, logout, sleep, reboot, showLabel } = options.menus.power;
|
|
|
|
export const PowerButton = (action: PowerOptions): GButton => {
|
|
const handleClick = (action: PowerOptions): void => {
|
|
const actions = {
|
|
shutdown: shutdown.value,
|
|
reboot: reboot.value,
|
|
logout: logout.value,
|
|
sleep: sleep.value,
|
|
};
|
|
App.closeWindow('powerdropdownmenu');
|
|
|
|
if (!confirmation.value) {
|
|
Utils.execAsync(actions[action]).catch((err) =>
|
|
console.error(`Failed to execute ${action} command. Error: ${err}`),
|
|
);
|
|
} else {
|
|
powermenu.customAction(action, actions[action]);
|
|
}
|
|
};
|
|
|
|
const powerIconMap = {
|
|
shutdown: '',
|
|
reboot: '',
|
|
logout: '',
|
|
sleep: '',
|
|
};
|
|
|
|
return Widget.Button({
|
|
className: showLabel.bind('value').as((shwLbl) => {
|
|
return `power-menu-button ${action} ${!shwLbl ? 'no-label' : ''}`;
|
|
}),
|
|
on_clicked: () => handleClick(action),
|
|
child: Widget.Box({
|
|
vertical: false,
|
|
children: showLabel.bind('value').as((shwLbl) => {
|
|
if (shwLbl) {
|
|
return [
|
|
Widget.Label({
|
|
label: powerIconMap[action],
|
|
className: `power-button-icon ${action}-icon txt-icon`,
|
|
}),
|
|
Widget.Label({
|
|
hpack: 'center',
|
|
hexpand: true,
|
|
label: capitalizeFirstLetter(action),
|
|
className: `power-button-label ${action}-label show-label`,
|
|
}),
|
|
];
|
|
}
|
|
return [
|
|
Widget.Label({
|
|
label: powerIconMap[action],
|
|
className: `power-button-icon ${action}-icon no-label txt-icon`,
|
|
}),
|
|
];
|
|
}),
|
|
}),
|
|
});
|
|
};
|