Trying to build a reboot to windows button

Hey all,

I’ve never used the sleep button in the kickoff menu so I decided to embark on a mission to remove it and build a “boot to windows” button instead.
Now I’ve found the LeaveButtons.qml file and I’ve removed the hibernate/suspend from kicker/systemFavorites and added a custom button in the qml for rebooting.

looks fine so far:

image

however I’m struggling with the functionality.

RowLayout {
    id: buttonsRepeaterRow
    // HACK Can't use `visible` property, as the layout needs to be
    // visible to be able to update its implicit size, which in turn is
    // be used to set collapseActionButtons.
    enabled: !root.__layout.collapseActionButtons
    opacity: !root.__layout.collapseActionButtons ? 1 : 0
    spacing: parent.spacing
    PC3.ToolButton {
        icon.name: "windows-logo-white"
        text: i18n("Restart to Windows")
        display: Plasmoid.configuration.showActionButtonCaptions ? PC3.AbstractButton.TextBesideIcon : PC3.AbstractButton.IconOnly;
        onClicked: {
            // something goes here
        }
        PC3.ToolTip.text: text
        PC3.ToolTip.delay: Kirigami.Units.toolTipDelay
        PC3.ToolTip.visible: display === PC3.AbstractButton.IconOnly && hovered

so in the “onClicked” section I want to basically run a script or trigger a command

ENTRY_NAME="Windows Boot Manager (on /dev/sdc1)"
sudo grub-reboot "$ENTRY_NAME" && systemctl reboot

I’ve configured this so it wouldn’t need the sudo password prompt but for the life of me I cant get this to work. I’ve tried Qt.External task with file and script with file and .desktop and lots of other ways, however as you may be able to tell I’m not a qml/c/c++ or other dev.

Can I actually in some way launch a command here, or do I need to build some .co that I somehow import. I’m at wits end, any help would be appreciated.

can’t say i follow all your code, but if you are trying to execute a sudo command in a script then i’ve found a way to do that by modifying the sudoers file… from my notes

## SUPERUSER NOPASSWD ##

# to run commands that require root without having to enter a password
# the commands must be added to the sudoers file (man sudoers for more info)

sudo visudo

# place new entries at the very end of the file
# to allow user foo to run systemctl without a password

foo ma=(ALL:ALL) NOPASSWD: /usr/bin/ls, /usr/bin/systemctl, /usr/sbin/update-grub

# where 'foo' is the user name, 'ma' is the machine name, (ALL) are the users foo can impersonate.
# and NOPASSWD: is the trick to avoid the password prompt.
# the trick is limited to the command(s) listed by their fully qualified path (which ls)
# and limited to the user and machine combination listed

# to see the changes have taken effect use
sudo -ll

Thanks for the replay!
I’ve also done the visudo edit, it’s what I meant with not needing a sudo password prompt. My issue is running a script or command from within the .qml file. I’ve only managed for it to open in an editor but not run as script, the sudo password is not an issue.

1 Like