mirror of
https://github.com/lutris/lutris
synced 2024-09-21 00:31:19 +00:00
Install game launcher before a user can login to a service
This commit is contained in:
parent
1fb175a013
commit
4184add31e
|
@ -1,13 +1,10 @@
|
|||
"""GUI dialog for reporting issues"""
|
||||
# Standard Library
|
||||
import json
|
||||
import os
|
||||
from gettext import gettext as _
|
||||
|
||||
# Third Party Libraries
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Lutris Modules
|
||||
from lutris.gui.dialogs import NoticeDialog
|
||||
from lutris.gui.widgets.window import BaseApplicationWindow
|
||||
from lutris.util.linux import gather_system_info
|
||||
|
|
|
@ -14,9 +14,6 @@ DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 F
|
|||
class WebConnectDialog(Dialog):
|
||||
"""Login form for external services"""
|
||||
|
||||
default_width = 390
|
||||
default_height = 500
|
||||
|
||||
def __init__(self, service, parent=None):
|
||||
|
||||
self.context = WebKit2.WebContext.new()
|
||||
|
@ -33,7 +30,7 @@ class WebConnectDialog(Dialog):
|
|||
super().__init__(title=service.name, parent=parent)
|
||||
|
||||
self.set_border_width(0)
|
||||
self.set_default_size(self.default_width, self.default_height)
|
||||
self.set_default_size(self.service.login_window_width, self.service.login_window_height)
|
||||
|
||||
self.webview = WebKit2.WebView.new_with_context(self.context)
|
||||
self.webview.load_uri(service.login_url)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Generic service utilities"""
|
||||
import os
|
||||
import shutil
|
||||
from gettext import gettext as _
|
||||
|
||||
from gi.repository import Gio, GObject
|
||||
|
||||
|
@ -8,11 +9,13 @@ from lutris import api, settings
|
|||
from lutris.api import get_game_installers
|
||||
from lutris.config import write_game_config
|
||||
from lutris.database import sql
|
||||
from lutris.database.games import add_game, get_games
|
||||
from lutris.database.games import add_game, get_game_by_field, get_games
|
||||
from lutris.database.services import ServiceGameCollection
|
||||
from lutris.game import Game
|
||||
from lutris.gui.dialogs import NoticeDialog
|
||||
from lutris.gui.dialogs.webconnect_dialog import WebConnectDialog
|
||||
from lutris.gui.views.media_loader import download_media
|
||||
from lutris.installer import get_installers
|
||||
from lutris.services.service_media import ServiceMedia
|
||||
from lutris.util import system
|
||||
from lutris.util.cookies import WebkitCookieJar
|
||||
|
@ -82,12 +85,29 @@ class BaseService(GObject.Object):
|
|||
return self.id
|
||||
|
||||
def run(self):
|
||||
"""Override this method to run a launcher"""
|
||||
logger.warning("This service doesn't run anything")
|
||||
"""Launch the game client"""
|
||||
launcher = self.get_launcher()
|
||||
if launcher:
|
||||
launcher.emit("game-launch")
|
||||
|
||||
def is_launchable(self):
|
||||
if self.client_installer:
|
||||
return get_game_by_field(self.client_installer, "slug")
|
||||
return False
|
||||
|
||||
def get_launcher(self):
|
||||
if not self.client_installer:
|
||||
return
|
||||
db_launcher = get_game_by_field(self.client_installer, "slug")
|
||||
if db_launcher:
|
||||
return Game(db_launcher["id"])
|
||||
|
||||
def is_launcher_installed(self):
|
||||
launcher = self.get_launcher()
|
||||
if not launcher:
|
||||
return False
|
||||
return launcher.is_installed
|
||||
|
||||
def reload(self):
|
||||
"""Refresh the service's games"""
|
||||
self.emit("service-games-load")
|
||||
|
@ -276,12 +296,23 @@ class OnlineService(BaseService):
|
|||
cache_path = NotImplemented
|
||||
requires_login_page = False
|
||||
|
||||
login_window_width = 390
|
||||
login_window_height = 500
|
||||
|
||||
@property
|
||||
def credential_files(self):
|
||||
"""Return a list of all files used for authentication"""
|
||||
return [self.cookies_path]
|
||||
|
||||
def login(self, parent=None):
|
||||
if self.client_installer and not self.is_launcher_installed():
|
||||
NoticeDialog(
|
||||
_("This service requires a game launcher. The following steps will install it.\n"
|
||||
"Once the client is installed, you can login to %s.") % self.name)
|
||||
application = Gio.Application.get_default()
|
||||
installers = get_installers(game_slug=self.client_installer)
|
||||
application.show_installer_window(installers)
|
||||
return
|
||||
logger.debug("Connecting to %s", self.name)
|
||||
dialog = WebConnectDialog(self, parent)
|
||||
dialog.set_modal(True)
|
||||
|
|
|
@ -83,6 +83,8 @@ class UbisoftConnectService(OnlineService):
|
|||
runner = "wine"
|
||||
client_installer = "ubisoft-connect"
|
||||
browser_size = (460, 690)
|
||||
login_window_width = 460
|
||||
login_window_height = 690
|
||||
cookies_path = os.path.join(settings.CACHE_DIR, "ubisoft/.auth")
|
||||
token_path = os.path.join(settings.CACHE_DIR, "ubisoft/.token")
|
||||
cache_path = os.path.join(settings.CACHE_DIR, "ubisoft/library/")
|
||||
|
@ -120,14 +122,6 @@ class UbisoftConnectService(OnlineService):
|
|||
self.emit("service-login")
|
||||
return (user_data['userId'], user_data['username'])
|
||||
|
||||
def run(self):
|
||||
db_game = get_game_by_field(self.client_installer, "slug")
|
||||
game = Game(db_game["id"])
|
||||
game.emit("game-launch")
|
||||
|
||||
def is_launchable(self):
|
||||
return get_game_by_field(self.client_installer, "slug")
|
||||
|
||||
def is_connected(self):
|
||||
return self.is_authenticated()
|
||||
|
||||
|
|
Loading…
Reference in a new issue