🇨🇿 cs

Nextcloud client and troubles with KWallet

For some reason, the Nextcloud client (sometimes !!!) has trouble working properly with KWallet after login to KDE. It fails to obtain stored login information and asks for a fresh login again, which is enormously annoying.

I searched a lot, and it seems that there is a problem with the detection of particular KWallet versions inside the Qt library. The client simply does not wait for opening the vault and does not get a password (or token in this case). After fiddling with some environment variables, I ended up with a simple shell script that I run instead of a direct call of the Nextcloud Files binary.

At first, one needs to disable the “run after system startup” option in Nextcloud client settings. This will prevent the program from running directly, bypassing our new script. After that, it’s easy to add a proper shortcut to the whole shell script in the KDE startup options.

My initial version of the script looks like this:

#!/bin/sh

WALLET_NAME=kdewallet

qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.open "$WALLET_NAME" 0 "Nextcloud shell wrapper" >/dev/null

while [ `qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.isOpen "$WALLET_NAME"` != "true" ]; do
   sleep 5
done

( cd /home/martin/opt/nextcloud/ && ./Nextcloud.AppImage --background )

The whole trick lies in a manual DBus call of method org.kde.KWallet.open(), which will force the opening of the unlock dialog (and also waits for some time). After a timeout, it’s better to check for vault status in a loop to ensure the client is not run prematurely.

After the KWallet vault is detected open, the Nextcloud client binary is run (I use the AppImage distribution) with the --background switch to ensure no main window is opened after start.

It’s important to set the proper vault name to WALLET_NAME (The vault name can be found in the KWallet app). If you have the name right, you won’t be prompted for vault creation upon running the script. Also, there might be differences in the address of the DBus call depending on your KWallet version. I recommend using qdbusviewer to check the proper DBus paths.

The script surely could have some improvements. If you don’t unlock the wallet at all, the script will wait forever until the computer is shut down (and additionally checks every few seconds). But this is not my case.

Hope this helps!

Comments