|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) |
| 4 | + */ |
| 5 | + |
| 6 | +public class Gala.ShutdownManager : Object { |
| 7 | + public ScreenShield screen_shield { private get; construct; } |
| 8 | + |
| 9 | + private LoginManager? login_manager; |
| 10 | + private UnixInputStream? inhibitor; |
| 11 | + |
| 12 | + public ShutdownManager (ScreenShield screen_shield) { |
| 13 | + Object (screen_shield: screen_shield); |
| 14 | + } |
| 15 | + |
| 16 | + construct { |
| 17 | + setup_dbus_interface.begin (); |
| 18 | + } |
| 19 | + |
| 20 | + private async void setup_dbus_interface () { |
| 21 | + try { |
| 22 | + login_manager = yield Bus.get_proxy (BusType.SYSTEM, "org.freedesktop.login1", "/org/freedesktop/login1"); |
| 23 | + inhibit_shutdown (); |
| 24 | + |
| 25 | + login_manager.prepare_for_shutdown.connect ((about_to_shutdown) => { |
| 26 | + if (!about_to_shutdown) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + screen_shield.activate (300, remove_inhibitor); |
| 31 | + }); |
| 32 | + } catch (Error e) { |
| 33 | + warning ("Couldn't get login manager: %s", e.message); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + private void inhibit_shutdown () requires (login_manager != null && inhibitor == null) { |
| 38 | + try { |
| 39 | + inhibitor = login_manager.inhibit ("shutdown", "Pantheon", "Pantheon needs to play shutdown animation", "delay"); |
| 40 | + } catch (Error e) { |
| 41 | + warning ("Couldn't inhibit shutdown, no shutdown animation will be player: %s", e.message); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private void remove_inhibitor () requires (inhibitor != null) { |
| 46 | + try { |
| 47 | + inhibitor.close (); |
| 48 | + } catch (Error e) { |
| 49 | + warning ("Couldn't remove shutdown inhibitor: %s", e.message); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments