1#!/usr/bin/env python3

2# This file is part of Checkbox.

3#

4# Copyright 2018 Canonical Ltd.

5# Written by: Sylvain Pineau <sylvain.pineau@canonical.com>

6#

7# Checkbox is free software: you can redistribute it and/or modify

8# it under the terms of the GNU General Public License version 3,

9# as published by the Free Software Foundation.

10#

11# Checkbox is distributed in the hope that it will be useful,

12# but WITHOUT ANY WARRANTY; without even the implied warranty of

13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

14# GNU General Public License for more details.

15#

16# You should have received a copy of the GNU General Public License

17# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

18

19 import dbus

20 import gi

21 from dbus.mainloop.glib import DBusGMainLoop

22

23 gi.require_version("GLib", "2.0")

24 from gi.repository import GObject # noqa: E402

25 from gi.repository import GLib # noqa: E402

26

27

28 def filter_cb(bus, message):

29 if message.get_member() == "EventEmitted":

30 args = message.get_args_list()

31 if args[0] == "desktop-lock":

32 print("Lock Screen detected")

33 mainloop.quit()

34 elif message.get_member() == "ActiveChanged":

35 args = message.get_args_list()

36 if args[0] == True: # noqa: E712

37 print("Lock Screen detected")

38 mainloop.quit()

39

40

41 def on_timeout_expired():

42 print("You have failed to perform the required manipulation in time")

43 raise SystemExit(1)

44

45

46 DBusGMainLoop(set_as_default=True)

47 bus = dbus.SessionBus()

48 bus.add_match_string("type='signal',interface='com.ubuntu.Upstart0_6'")

49 bus.add_match_string("type='signal',interface='org.gnome.ScreenSaver'")

50 bus.add_message_filter(filter_cb)

51 mainloop = GLib.MainLoop()

52 GObject.timeout_add_seconds(30, on_timeout_expired)

53 mainloop.run()