How to get if an extenion is installed for all user in code

Does anyone know how to tell if an extension is installed for All User (root) in Code?

I am writing an extension and I need to have it take a different action if the user installs it for All Users.

Maybe for the install path, “usually” for the user will be the configuration path of the user.

You are aware of the __file__ attribute?

Even if the extension was written in Python (which the OP didn’t mention)… you could check only against pre-known assumed locations, whether the path contains /user/extensions/ or /share/extensions/ or something, but wouldn’t catch if such directory uses a symbolic link to point somewhere where the extension is actually installed.

/opt/libreoffice7.5/program/unopkg list --shared

Yes, I am using python for this.

File location approach was intriguing, You can see Windows a log file from my project on pastebin for reference.

That should be available from the ExtensionManager service, by asking css::deployment::XExtensionManager::getExtensionsWithSameIdentifier() that returns a sequence<css::deployment::XPackage> with three elements of (user, shared, bundled) repositories’ packages, which if not installed in that repository is a null reference. Note that the same extension may be installed in each repository and user takes precedence over shared over bundled. Though the third css::ucb::XCommandEnvironment argument is mandatory, a dummy instance of that interface can be passed.

See also Extension Identifiers in the DevGuide.

2 Likes

This is the solution that I used (mostly). I created an ExtensionInfo class. It has a get_extension_detail() That returns a Tuple of three, user, shared, bundled, this allows me to check how the extension is installed.
You can see an example of how I used this class in my Config class.