mirror of
https://github.com/lutris/lutris
synced 2024-09-04 23:13:35 +00:00
Add Steam account selection in account preferences
This commit is contained in:
parent
8de92e7b0f
commit
d2c10a8087
|
@ -2,14 +2,40 @@ from gettext import gettext as _
|
|||
|
||||
from gi.repository import Gtk
|
||||
|
||||
from lutris import settings
|
||||
from lutris.gui.config.base_config_box import BaseConfigBox
|
||||
from lutris.util.steam.config import get_steam_users
|
||||
|
||||
|
||||
class AccountsBox(BaseConfigBox):
|
||||
steam_account_setting = "active_steam_account"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.add(self.get_section_label(_("Steam accounts")))
|
||||
frame = Gtk.Frame(visible=True, shadow_type=Gtk.ShadowType.ETCHED_IN)
|
||||
listbox = Gtk.ListBox(visible=True)
|
||||
frame.add(listbox)
|
||||
self.pack_start(frame, False, False, 12)
|
||||
|
||||
vbox = Gtk.VBox(visible=True)
|
||||
frame.add(vbox)
|
||||
|
||||
main_radio_button = None
|
||||
active_steam_account = settings.read_setting(self.steam_account_setting)
|
||||
for account in get_steam_users():
|
||||
radio_button = Gtk.RadioButton.new_with_label_from_widget(
|
||||
main_radio_button,
|
||||
account["PersonaName"]
|
||||
)
|
||||
radio_button.set_margin_top(6)
|
||||
radio_button.set_margin_start(12)
|
||||
radio_button.set_margin_bottom(6)
|
||||
radio_button.show()
|
||||
radio_button.set_active(active_steam_account == account["steamid64"])
|
||||
radio_button.connect("toggled", self.on_steam_account_toggled, account["steamid64"])
|
||||
vbox.pack_start(radio_button, False, False, 0)
|
||||
if not main_radio_button:
|
||||
main_radio_button = radio_button
|
||||
|
||||
def on_steam_account_toggled(self, radio_button, steamid64):
|
||||
"""Handler for switching the active Steam account."""
|
||||
settings.write_setting(self.steam_account_setting, steamid64)
|
||||
|
|
|
@ -14,7 +14,7 @@ from lutris.services.itchio import ItchIoService
|
|||
from lutris.services.lutris import LutrisService
|
||||
from lutris.services.mame import MAMEService
|
||||
from lutris.services.origin import OriginService
|
||||
from lutris.services.scummvm import ScummvmService, SCUMMVM_CONFIG_FILE
|
||||
from lutris.services.scummvm import SCUMMVM_CONFIG_FILE, ScummvmService
|
||||
from lutris.services.steam import SteamService
|
||||
from lutris.services.steamwindows import SteamWindowsService
|
||||
from lutris.services.ubisoft import UbisoftConnectService
|
||||
|
|
|
@ -56,17 +56,17 @@ class ScummvmService(BaseService):
|
|||
})
|
||||
game.save()
|
||||
|
||||
def generate_installer(self, game):
|
||||
details = json.loads(game["details"])
|
||||
def generate_installer(self, db_game):
|
||||
details = json.loads(db_game["details"])
|
||||
return {
|
||||
"name": game["name"],
|
||||
"name": db_game["name"],
|
||||
"version": "ScummVM",
|
||||
"slug": game["slug"],
|
||||
"game_slug": slugify(game["lutris_slug"]),
|
||||
"slug": db_game["slug"],
|
||||
"game_slug": slugify(db_game["lutris_slug"]),
|
||||
"runner": "scummvm",
|
||||
"script": {
|
||||
"game": {
|
||||
"game_id": game["game_id"],
|
||||
"game_id": db_game["game_id"],
|
||||
"path": details["path"],
|
||||
"platform": "scummvm"
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ from lutris.services.service_game import ServiceGame
|
|||
from lutris.services.service_media import ServiceMedia
|
||||
from lutris.util.log import logger
|
||||
from lutris.util.steam.appmanifest import AppManifest, get_appmanifests
|
||||
from lutris.util.steam.config import get_steam_library, get_steamapps_dirs, get_user_steam_id64
|
||||
from lutris.util.steam.config import get_most_recent_steamid64, get_steam_library, get_steamapps_dirs
|
||||
from lutris.util.strings import slugify
|
||||
|
||||
|
||||
|
@ -91,7 +91,7 @@ class SteamService(BaseService):
|
|||
|
||||
def load(self):
|
||||
"""Return importable Steam games"""
|
||||
steamid = get_user_steam_id64()
|
||||
steamid = get_most_recent_steamid64()
|
||||
if not steamid:
|
||||
logger.error("Unable to find SteamID from Steam config")
|
||||
return
|
||||
|
|
|
@ -66,7 +66,7 @@ def read_user_config():
|
|||
return config
|
||||
|
||||
|
||||
def get_config_value(config, key):
|
||||
def get_config_value(config: dict, key: str):
|
||||
"""Fetch a value from a configuration in a case insensitive way"""
|
||||
keymap = {k.lower(): k for k in config.keys()}
|
||||
if key not in keymap:
|
||||
|
@ -77,8 +77,10 @@ def get_config_value(config, key):
|
|||
return config[keymap[key.lower()]]
|
||||
|
||||
|
||||
def get_steam_users():
|
||||
"""Return the list of Steam users on this system and the base path where the settings are located"""
|
||||
def get_user_data_dirs():
|
||||
"""Return the list of available Steam user config directories (using a SteamID32)
|
||||
and the base path where the settings are located (Returns the 1st location found)
|
||||
"""
|
||||
for steam_dir in STEAM_DATA_DIRS:
|
||||
userdata_path = os.path.join(os.path.expanduser(steam_dir), "userdata")
|
||||
if not os.path.exists(userdata_path):
|
||||
|
@ -89,17 +91,31 @@ def get_steam_users():
|
|||
return "", []
|
||||
|
||||
|
||||
def get_user_steam_id64():
|
||||
"""Read user's SteamID64 from Steam config files"""
|
||||
def get_steam_users() -> list:
|
||||
"""Return a list of available Steam users.
|
||||
Most recently used account is 1st in the list."""
|
||||
steam_users = []
|
||||
user_config = read_user_config()
|
||||
if not user_config or "users" not in user_config:
|
||||
return
|
||||
last_steam_id = None
|
||||
for steam_id in user_config["users"]:
|
||||
last_steam_id = steam_id
|
||||
if get_config_value(user_config["users"][steam_id], "mostrecent") == "1":
|
||||
return steam_id
|
||||
return last_steam_id
|
||||
return []
|
||||
most_recent = None
|
||||
for steam_id, account in user_config["users"].items():
|
||||
account["steamid64"] = steam_id
|
||||
if get_config_value(account, "mostrecent") == "1":
|
||||
most_recent = account
|
||||
else:
|
||||
steam_users.append(account)
|
||||
if most_recent:
|
||||
steam_users = [most_recent] + steam_users
|
||||
return steam_users
|
||||
|
||||
|
||||
def get_most_recent_steamid64() -> str:
|
||||
"""Read user's SteamID64 from Steam config files"""
|
||||
steam_users = get_steam_users()
|
||||
if steam_users:
|
||||
return steam_users[0]["steamid64"]
|
||||
return ""
|
||||
|
||||
|
||||
def get_steam_library(steamid):
|
||||
|
|
|
@ -11,12 +11,12 @@ from lutris.game import Game
|
|||
from lutris.util import resources, system
|
||||
from lutris.util.log import logger
|
||||
from lutris.util.steam import vdf
|
||||
from lutris.util.steam.config import get_steam_users
|
||||
from lutris.util.steam.config import get_user_data_dirs
|
||||
|
||||
|
||||
def get_config_path() -> str:
|
||||
"""Return config path for a Steam user"""
|
||||
userdatapath, user_ids = get_steam_users()
|
||||
userdatapath, user_ids = get_user_data_dirs()
|
||||
if not user_ids:
|
||||
return ""
|
||||
if len(user_ids) > 1:
|
||||
|
|
Loading…
Reference in a new issue