Separate user and system data dirs for Flatpak

This commit is contained in:
kramo
2023-12-12 10:18:13 +01:00
parent 9bce2190f7
commit f7a3e01cee
5 changed files with 48 additions and 16 deletions

View File

@@ -17,6 +17,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from itertools import chain
from pathlib import Path
from typing import NamedTuple
@@ -35,7 +36,8 @@ class FlatpakSourceIterable(SourceIterable):
"""Generator method producing games"""
icon_theme = Gtk.IconTheme.new()
icon_theme.add_search_path(str(self.source.locations.data["icons"]))
icon_theme.add_search_path(str(self.source.locations.system_data["icons"]))
icon_theme.add_search_path(str(self.source.locations.user_data["icons"]))
blacklist = (
{"hu.kramo.Cartridges", "hu.kramo.Cartridges.Devel"}
@@ -52,7 +54,10 @@ class FlatpakSourceIterable(SourceIterable):
}
)
for entry in (self.source.locations.data["applications"]).iterdir():
for entry in chain(
(self.source.locations.system_data["applications"]).iterdir(),
(self.source.locations.user_data["applications"]).iterdir(),
):
if entry.suffix != ".desktop":
continue
@@ -108,7 +113,8 @@ class FlatpakSourceIterable(SourceIterable):
class FlatpakLocations(NamedTuple):
data: Location
system_data: Location
user_data: Location
class FlatpakSource(ExecutableFormatSource):
@@ -126,15 +132,21 @@ class FlatpakSource(ExecutableFormatSource):
super().__init__()
self.locations = FlatpakLocations(
Location(
schema_key="flatpak-location",
candidates=(
"/var/lib/flatpak/",
shared.data_dir / "flatpak",
),
schema_key="flatpak-system-location",
candidates=("/var/lib/flatpak/",),
paths={
"applications": LocationSubPath("exports/share/applications", True),
"icons": LocationSubPath("exports/share/icons", True),
},
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
)
),
Location(
schema_key="flatpak-user-location",
candidates=(shared.data_dir / "flatpak",),
paths={
"applications": LocationSubPath("exports/share/applications", True),
"icons": LocationSubPath("exports/share/icons", True),
},
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
),
)

View File

@@ -95,8 +95,10 @@ class PreferencesWindow(Adw.PreferencesWindow):
retroarch_config_file_chooser_button = Gtk.Template.Child()
flatpak_expander_row = Gtk.Template.Child()
flatpak_data_action_row = Gtk.Template.Child()
flatpak_data_file_chooser_button = Gtk.Template.Child()
flatpak_system_data_action_row = Gtk.Template.Child()
flatpak_system_data_file_chooser_button = Gtk.Template.Child()
flatpak_user_data_action_row = Gtk.Template.Child()
flatpak_user_data_file_chooser_button = Gtk.Template.Child()
flatpak_import_launchers_switch = Gtk.Template.Child()
desktop_switch = Gtk.Template.Child()

View File

@@ -322,10 +322,22 @@ template $PreferencesWindow : Adw.PreferencesWindow {
icon-name: "flatpak-source-symbolic";
}
Adw.ActionRow flatpak_data_action_row {
title: _("Install Location");
Adw.ActionRow flatpak_system_data_action_row {
title: _("System Location");
Button flatpak_data_file_chooser_button {
Button flatpak_system_data_file_chooser_button {
icon-name: "folder-symbolic";
valign: center;
styles [
"flat"
]
}
}
Adw.ActionRow flatpak_user_data_action_row {
title: _("User Location");
Button flatpak_user_data_file_chooser_button {
icon-name: "folder-symbolic";
valign: center;
styles [

View File

@@ -83,9 +83,12 @@
<key name="flatpak" type="b">
<default>true</default>
</key>
<key name="flatpak-location" type="s">
<key name="flatpak-system-location" type="s">
<default>"/var/lib/flatpak/"</default>
</key>
<key name="flatpak-user-location" type="s">
<default>"~/.local/share/flatpak/"</default>
</key>
<key name="flatpak-import-launchers" type="b">
<default>false</default>
</key>

View File

@@ -19,7 +19,10 @@
"--filesystem=~/.var/app/com.usebottles.bottles/data/bottles/:ro",
"--filesystem=~/.var/app/io.itch.itch/config/itch/:ro",
"--filesystem=~/.var/app/org.libretro.RetroArch/config/retroarch/:ro",
"--filesystem=/var/lib/flatpak:ro"
"--filesystem=/var/lib/flatpak/app:ro",
"--filesystem=/var/lib/flatpak/exports:ro",
"--filesystem=xdg-data/flatpak/app:ro",
"--filesystem=xdg-data/flatpak/exports:ro"
],
"cleanup" : [
"/include",