Skip to content

Commit

Permalink
clubhouse: Request background permission
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Nov 25, 2020
1 parent 99173ac commit 1973103
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eosclubhouse/clubhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from eosclubhouse.animation import Animation, AnimationImage, AnimationSystem, Animator, \
get_character_animation_dirs
from eosclubhouse import metrics
from eosclubhouse.portal import Portal

from eosclubhouse.widgets import FixedLayerGroup, ScalableImage, gtk_widget_add_custom_css_provider

Expand Down Expand Up @@ -3082,6 +3083,7 @@ def __init__(self):
super().__init__(application_id=CLUBHOUSE_NAME,
inactivity_timeout=self._INACTIVITY_TIMEOUT,
resource_base_path='/com/hack_computer/Clubhouse')
Portal.request_background()

self._installing_extension = False
self._use_inapp_notifications = False
Expand Down
52 changes: 52 additions & 0 deletions eosclubhouse/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (C) 2020 Endless OS Foundation LLC.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

import logging

from gi.repository import Gio, GLib


_logger = logging.getLogger(__name__)


class Portal:
_proxy = None

@classmethod
def _get_proxy(klass):
if klass._proxy is None:
klass._proxy = Gio.DBusProxy.new_for_bus_sync(
Gio.BusType.SESSION,
0,
None,
'org.freedesktop.portal.Desktop',
'/org/freedesktop/portal/desktop',
'org.freedesktop.portal.Background',
None
)
return klass._proxy

@classmethod
def request_background(klass, message=''):
try:
proxy = klass._get_proxy()
options = {}
if message:
options['reason'] = GLib.Variant('s', message)
proxy.RequestBackground('(sa{sv})', '', options)
except GLib.Error as err:
_logger.warning('Error requesting background permission to portal: %s', err)

0 comments on commit 1973103

Please sign in to comment.