Use prefered Steam account for Steam integration and shortcuts

This commit is contained in:
Mathieu Comandon 2023-10-10 13:45:25 -07:00
parent d2c10a8087
commit 28e09a6275
4 changed files with 30 additions and 19 deletions

View file

@ -4,11 +4,10 @@ from gi.repository import Gtk
from lutris import settings from lutris import settings
from lutris.gui.config.base_config_box import BaseConfigBox from lutris.gui.config.base_config_box import BaseConfigBox
from lutris.util.steam.config import get_steam_users from lutris.util.steam.config import STEAM_ACCOUNT_SETTING, get_steam_users
class AccountsBox(BaseConfigBox): class AccountsBox(BaseConfigBox):
steam_account_setting = "active_steam_account"
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -20,7 +19,7 @@ class AccountsBox(BaseConfigBox):
frame.add(vbox) frame.add(vbox)
main_radio_button = None main_radio_button = None
active_steam_account = settings.read_setting(self.steam_account_setting) active_steam_account = settings.read_setting(STEAM_ACCOUNT_SETTING)
for account in get_steam_users(): for account in get_steam_users():
radio_button = Gtk.RadioButton.new_with_label_from_widget( radio_button = Gtk.RadioButton.new_with_label_from_widget(
main_radio_button, main_radio_button,
@ -38,4 +37,4 @@ class AccountsBox(BaseConfigBox):
def on_steam_account_toggled(self, radio_button, steamid64): def on_steam_account_toggled(self, radio_button, steamid64):
"""Handler for switching the active Steam account.""" """Handler for switching the active Steam account."""
settings.write_setting(self.steam_account_setting, steamid64) settings.write_setting(STEAM_ACCOUNT_SETTING, steamid64)

View file

@ -17,7 +17,7 @@ from lutris.services.service_game import ServiceGame
from lutris.services.service_media import ServiceMedia from lutris.services.service_media import ServiceMedia
from lutris.util.log import logger from lutris.util.log import logger
from lutris.util.steam.appmanifest import AppManifest, get_appmanifests from lutris.util.steam.appmanifest import AppManifest, get_appmanifests
from lutris.util.steam.config import get_most_recent_steamid64, get_steam_library, get_steamapps_dirs from lutris.util.steam.config import get_active_steamid64, get_steam_library, get_steamapps_dirs
from lutris.util.strings import slugify from lutris.util.strings import slugify
@ -91,7 +91,7 @@ class SteamService(BaseService):
def load(self): def load(self):
"""Return importable Steam games""" """Return importable Steam games"""
steamid = get_most_recent_steamid64() steamid = get_active_steamid64()
if not steamid: if not steamid:
logger.error("Unable to find SteamID from Steam config") logger.error("Unable to find SteamID from Steam config")
return return

View file

@ -7,6 +7,7 @@ import requests
from lutris import settings from lutris import settings
from lutris.util import system from lutris.util import system
from lutris.util.log import logger from lutris.util.log import logger
from lutris.util.steam.steamid import SteamID
from lutris.util.steam.vdfutils import vdf_parse from lutris.util.steam.vdfutils import vdf_parse
STEAM_DATA_DIRS = ( STEAM_DATA_DIRS = (
@ -21,6 +22,7 @@ STEAM_DATA_DIRS = (
"/usr/share/steam", "/usr/share/steam",
"/usr/local/share/steam", "/usr/local/share/steam",
) )
STEAM_ACCOUNT_SETTING = "active_steam_account"
def get_steam_dir(): def get_steam_dir():
@ -110,14 +112,25 @@ def get_steam_users() -> list:
return steam_users return steam_users
def get_most_recent_steamid64() -> str: def get_active_steamid64() -> str:
"""Read user's SteamID64 from Steam config files""" """Return the currently active Steam ID"""
steam_users = get_steam_users() steam_ids = [u["steamid64"] for u in get_steam_users()]
if steam_users: active_steam_id = settings.read_setting(STEAM_ACCOUNT_SETTING)
return steam_users[0]["steamid64"] if active_steam_id in steam_ids:
return active_steam_id
if steam_ids:
return steam_ids[0]
return "" return ""
def convert_steamid64_to_steamid32(steamid64: str) -> str:
"""Return the 32bit variant of SteamIDs, used for folder names in userdata"""
if not steamid64.isnumeric():
return ""
steam_id = SteamID.from_steamid64(int(steamid64))
return str(steam_id.get_32_bit_community_id())
def get_steam_library(steamid): def get_steam_library(steamid):
"""Return the list of games owned by a SteamID""" """Return the list of games owned by a SteamID"""
if not steamid: if not steamid:

View file

@ -5,13 +5,12 @@ import re
import shlex import shlex
import shutil import shutil
from lutris import settings
from lutris.api import format_installer_url from lutris.api import format_installer_url
from lutris.game import Game from lutris.game import Game
from lutris.util import resources, system from lutris.util import resources, system
from lutris.util.log import logger from lutris.util.log import logger
from lutris.util.steam import vdf from lutris.util.steam import vdf
from lutris.util.steam.config import get_user_data_dirs from lutris.util.steam.config import convert_steamid64_to_steamid32, get_active_steamid64, get_user_data_dirs
def get_config_path() -> str: def get_config_path() -> str:
@ -19,13 +18,13 @@ def get_config_path() -> str:
userdatapath, user_ids = get_user_data_dirs() userdatapath, user_ids = get_user_data_dirs()
if not user_ids: if not user_ids:
return "" return ""
user_id = user_ids[0]
if len(user_ids) > 1: if len(user_ids) > 1:
preferred_id = settings.read_setting("preferred_steam_id") active_account = get_active_steamid64()
if preferred_id and preferred_id in user_ids: if active_account:
user_id = user_ids[0] active_account32 = convert_steamid64_to_steamid32(active_account)
else: if active_account32 in user_ids:
logger.warning("No preferred Steam account selected, using %s", user_ids[0]) user_id = active_account32
user_id = user_ids[0]
return os.path.join(userdatapath, user_id, "config") return os.path.join(userdatapath, user_id, "config")