mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Use prefered Steam account for Steam integration and shortcuts
This commit is contained in:
parent
d2c10a8087
commit
28e09a6275
|
@ -4,11 +4,10 @@ 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
|
||||
from lutris.util.steam.config import STEAM_ACCOUNT_SETTING, get_steam_users
|
||||
|
||||
|
||||
class AccountsBox(BaseConfigBox):
|
||||
steam_account_setting = "active_steam_account"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -20,7 +19,7 @@ class AccountsBox(BaseConfigBox):
|
|||
frame.add(vbox)
|
||||
|
||||
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():
|
||||
radio_button = Gtk.RadioButton.new_with_label_from_widget(
|
||||
main_radio_button,
|
||||
|
@ -38,4 +37,4 @@ class AccountsBox(BaseConfigBox):
|
|||
|
||||
def on_steam_account_toggled(self, radio_button, steamid64):
|
||||
"""Handler for switching the active Steam account."""
|
||||
settings.write_setting(self.steam_account_setting, steamid64)
|
||||
settings.write_setting(STEAM_ACCOUNT_SETTING, steamid64)
|
||||
|
|
|
@ -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_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
|
||||
|
||||
|
||||
|
@ -91,7 +91,7 @@ class SteamService(BaseService):
|
|||
|
||||
def load(self):
|
||||
"""Return importable Steam games"""
|
||||
steamid = get_most_recent_steamid64()
|
||||
steamid = get_active_steamid64()
|
||||
if not steamid:
|
||||
logger.error("Unable to find SteamID from Steam config")
|
||||
return
|
||||
|
|
|
@ -7,6 +7,7 @@ import requests
|
|||
from lutris import settings
|
||||
from lutris.util import system
|
||||
from lutris.util.log import logger
|
||||
from lutris.util.steam.steamid import SteamID
|
||||
from lutris.util.steam.vdfutils import vdf_parse
|
||||
|
||||
STEAM_DATA_DIRS = (
|
||||
|
@ -21,6 +22,7 @@ STEAM_DATA_DIRS = (
|
|||
"/usr/share/steam",
|
||||
"/usr/local/share/steam",
|
||||
)
|
||||
STEAM_ACCOUNT_SETTING = "active_steam_account"
|
||||
|
||||
|
||||
def get_steam_dir():
|
||||
|
@ -110,14 +112,25 @@ def get_steam_users() -> list:
|
|||
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"]
|
||||
def get_active_steamid64() -> str:
|
||||
"""Return the currently active Steam ID"""
|
||||
steam_ids = [u["steamid64"] for u in get_steam_users()]
|
||||
active_steam_id = settings.read_setting(STEAM_ACCOUNT_SETTING)
|
||||
if active_steam_id in steam_ids:
|
||||
return active_steam_id
|
||||
if steam_ids:
|
||||
return steam_ids[0]
|
||||
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):
|
||||
"""Return the list of games owned by a SteamID"""
|
||||
if not steamid:
|
||||
|
|
|
@ -5,13 +5,12 @@ import re
|
|||
import shlex
|
||||
import shutil
|
||||
|
||||
from lutris import settings
|
||||
from lutris.api import format_installer_url
|
||||
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_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:
|
||||
|
@ -19,13 +18,13 @@ def get_config_path() -> str:
|
|||
userdatapath, user_ids = get_user_data_dirs()
|
||||
if not user_ids:
|
||||
return ""
|
||||
user_id = user_ids[0]
|
||||
if len(user_ids) > 1:
|
||||
preferred_id = settings.read_setting("preferred_steam_id")
|
||||
if preferred_id and preferred_id in user_ids:
|
||||
user_id = user_ids[0]
|
||||
else:
|
||||
logger.warning("No preferred Steam account selected, using %s", user_ids[0])
|
||||
user_id = user_ids[0]
|
||||
active_account = get_active_steamid64()
|
||||
if active_account:
|
||||
active_account32 = convert_steamid64_to_steamid32(active_account)
|
||||
if active_account32 in user_ids:
|
||||
user_id = active_account32
|
||||
return os.path.join(userdatapath, user_id, "config")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue