Linux: freedesktop support for file type association

Support freedesktop file association on Linux/Unix via the command line
arguments: `--register{-allusers}` `--unregister{-allusers}` as well
registration actions from the user preferences.

Once registered, the "Blender" application is available from launchers
and `*.blend` files are assoisated with the blender binary used for
registration.

The following operations are performed:

- Setup the desktop file.
- Setup the file association & make it default.
- Copy the icon.
- Setup the thumbnailer (`--register-allusers` only).

Notes:

- Registering/unregistering for all users manipulates files under
  `/usr/local` and requires running Blender as root.
  From the command line this can be done using `sudo`, e.g.
  `sudo ./blender --register-allusers`.
  From the GUI, the `pkexec` command is used.

- Recent versions of GNOME execute the thumbnailer in a restricted
  environment (`bwrap`) requiring `blender-thumbnailer` to be copied
  into `/usr/local/bin` (synlinks don't work).
  So thumbnailing copies the binary rather than linking and only works
  when registering for all users.

Ref !120283
This commit is contained in:
Campbell Barton
2024-04-05 11:38:21 +11:00
parent c0e4de8457
commit 9cb3a17352
9 changed files with 807 additions and 77 deletions

View File

@@ -667,15 +667,22 @@ class USERPREF_PT_system_os_settings(SystemPanel, CenterAlignMixIn, Panel):
@classmethod
def poll(cls, _context):
# Only for Windows so far
import sys
return sys.platform[:3] == "win"
# macOS isn't supported.
from sys import platform
if platform == "darwin":
return False
return True
def draw_centered(self, context, layout):
if context.preferences.system.is_microsoft_store_install:
layout.label(text="Microsoft Store installation")
layout.label(text="Use Windows 'Default Apps' to associate with blend files")
else:
from sys import platform
associate_supported = True
if platform[:3] == "win":
if context.preferences.system.is_microsoft_store_install:
layout.label(text="Microsoft Store installation")
layout.label(text="Use Windows 'Default Apps' to associate with blend files")
associate_supported = False
if associate_supported:
layout.label(text="Open blend files with this Blender version")
split = layout.split(factor=0.5)
split.alignment = 'LEFT'