|
| 1 | +import Gio from "gi://Gio"; |
| 2 | +import GLib from "gi://GLib"; |
| 3 | +import Gtk from "gi://Gtk"; |
| 4 | + |
| 5 | +import { build } from "../../troll/src/main.js"; |
| 6 | + |
| 7 | +import Interface from "./Permissions.blp" with { type: "uri" }; |
| 8 | + |
| 9 | +import illustration from "./permissions.svg"; |
| 10 | + |
| 11 | +import { getFlatpakInfo } from "../util.js"; |
| 12 | + |
| 13 | +const action_permissions = new Gio.SimpleAction({ |
| 14 | + name: "permissions", |
| 15 | + parameter_type: null, |
| 16 | +}); |
| 17 | + |
| 18 | +export function Permissions({ window }) { |
| 19 | + const { dialog, picture_illustration, label_command, button_info } = |
| 20 | + build(Interface); |
| 21 | + |
| 22 | + picture_illustration.set_resource(illustration); |
| 23 | + label_command.label = `flatpak override --user --share=network --socket=pulseaudio --device=input ${GLib.getenv( |
| 24 | + "FLATPAK_ID", |
| 25 | + )}`; |
| 26 | + |
| 27 | + button_info.connect("clicked", () => { |
| 28 | + new Gtk.UriLauncher({ |
| 29 | + uri: "https://docs.flatpak.org/en/latest/sandbox-permissions.html", |
| 30 | + }) |
| 31 | + .launch(window, null) |
| 32 | + .catch(console.error); |
| 33 | + }); |
| 34 | + |
| 35 | + action_permissions.connect("activate", () => { |
| 36 | + dialog.present(window); |
| 37 | + }); |
| 38 | + |
| 39 | + window.add_action(action_permissions); |
| 40 | +} |
| 41 | + |
| 42 | +const missing_permissions = (() => { |
| 43 | + const flatpak_info = getFlatpakInfo(); |
| 44 | + const shared = flatpak_info.get_string_list("Context", "shared"); |
| 45 | + const sockets = flatpak_info.get_string_list("Context", "sockets"); |
| 46 | + const devices = flatpak_info.get_string_list("Context", "devices"); |
| 47 | + |
| 48 | + return ( |
| 49 | + !shared.includes("network") || |
| 50 | + !sockets.includes("pulseaudio") || |
| 51 | + !devices.includes("all") |
| 52 | + ); |
| 53 | +})(); |
| 54 | + |
| 55 | +export function needsAdditionalPermissions({ demo }) { |
| 56 | + if (!demo["flatpak-finish-args"]) return false; |
| 57 | + return missing_permissions; |
| 58 | +} |
| 59 | + |
| 60 | +export function showPermissionsDialog({ window }) { |
| 61 | + window.activate_action("permissions", null); |
| 62 | +} |
0 commit comments