Skip to content

Commit 2a91c1d

Browse files
authored
Add ProtonUp-Qt shortcut to Steam library (#177)
* Add install_steam_library_shortcut * Steam shortcut: Create shortcuts file if not exist * Steam shortcut: Fix Flatpak run command * Add "Add Steam shortcut" to about dialog * Steam shortcut: Add app icon * Steam shortcut: Add Tooltip to button
1 parent 4aef45a commit 2a91c1d

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

pupgui2/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
APP_NAME = 'ProtonUp-Qt'
99
APP_VERSION = '2.8.0'
10+
APP_ID = 'net.davidotek.pupgui2'
11+
APP_ICON_FILE = os.path.join(xdg_config_home, 'pupgui/appicon256.png')
1012
APP_GHAPI_URL = 'https://api.github.com/repos/Davidotek/ProtonUp-qt/releases'
1113
DAVIDOTEK_KOFI_URL = 'https://ko-fi.com/davidotek'
1214
PROTONUPQT_GITHUB_URL = 'https://github.com/DavidoTek/ProtonUp-Qt'

pupgui2/pupgui2aboutdialog.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
from pupgui2.constants import APP_NAME, APP_VERSION, APP_GHAPI_URL, ABOUT_TEXT, BUILD_INFO
1111
from pupgui2.constants import DAVIDOTEK_KOFI_URL, PROTONUPQT_GITHUB_URL
12+
from pupgui2.steamutil import install_steam_library_shortcut
1213
from pupgui2.util import config_theme, apply_dark_theme, config_advanced_mode
1314
from pupgui2.util import open_webbrowser_thread
15+
from pupgui2.util import install_directory
1416

1517

1618
class PupguiAboutDialog(QObject):
@@ -68,6 +70,8 @@ def setup_ui(self):
6870
self.ui.checkAdvancedMode.setChecked(config_advanced_mode() == 'enabled')
6971
self.ui.checkAdvancedMode.stateChanged.connect(self.check_advanced_mode_state_changed)
7072

73+
self.ui.btnAddSteamShortcut.clicked.connect(self.btn_add_steam_shortcut_clicked)
74+
7175
if os.getenv('APPIMAGE') is None:
7276
self.ui.btnCheckForUpdates.setVisible(False)
7377

@@ -113,3 +117,9 @@ def tag_name_to_version(self, tag_name : str):
113117
tag_name = tag_name.replace('v', '')
114118
vers = tag_name.split('.')
115119
return [0, 0, 0] if len(vers) != 3 else vers
120+
121+
def btn_add_steam_shortcut_clicked(self):
122+
result = install_steam_library_shortcut(install_directory())
123+
if result != 1:
124+
self.ui.btnAddSteamShortcut.setText(self.tr('Added shortcut!'))
125+
self.ui.btnAddSteamShortcut.setEnabled(False)
20.6 KB
Loading

pupgui2/resources/ui/pupgui2_aboutdialog.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@
164164
</property>
165165
</spacer>
166166
</item>
167+
<item>
168+
<widget class="QPushButton" name="btnAddSteamShortcut">
169+
<property name="toolTip">
170+
<string>Adds a shortcut to open ProtonUp-Qt from your Steam library.
171+
To remove the shortcut, open Steam and select &quot;remove non-Steam game from your library&quot;.</string>
172+
</property>
173+
<property name="text">
174+
<string>Add Steam shortcut</string>
175+
</property>
176+
</widget>
177+
</item>
167178
<item>
168179
<widget class="QPushButton" name="btnAboutQt">
169180
<property name="text">

pupgui2/steamutil.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import vdf
77
import requests
88
import threading
9+
import pkgutil
910
from steam.utils.appcache import parse_appinfo
1011

1112
from PySide6.QtCore import Signal
1213
from PySide6.QtWidgets import QMessageBox, QApplication
1314

15+
from pupgui2.constants import APP_NAME, APP_ID, APP_ICON_FILE
1416
from pupgui2.constants import LOCAL_AWACY_GAME_LIST, PROTONDB_API_URL
1517
from pupgui2.constants import STEAM_STL_INSTALL_PATH, STEAM_STL_CONFIG_PATH, STEAM_STL_SHELL_FILES, STEAM_STL_FISH_VARIABLES
1618
from pupgui2.datastructures import SteamApp, AWACYStatus, BasicCompatTool, CTType
@@ -497,3 +499,78 @@ def remove_steamtinkerlaunch(compat_folder='', remove_config=True, ctmod_object=
497499
except IOError as e:
498500
print('Something went wrong trying to uninstall SteamTinkerLaunch. Aborting...', e)
499501
return False
502+
503+
504+
def install_steam_library_shortcut(steam_config_folder: str, remove_shortcut=False) -> int:
505+
"""
506+
Adds a shortcut to launch this app to the Steam Library
507+
Return: 0=success, 1=error, 2=already installed
508+
"""
509+
users_folder = os.path.realpath(os.path.join(os.path.expanduser(steam_config_folder), os.pardir, 'userdata'))
510+
511+
try:
512+
if not os.path.isfile(APP_ICON_FILE):
513+
with open(APP_ICON_FILE, 'wb') as f:
514+
f.write(pkgutil.get_data(__name__, 'resources/img/appicon256.png'))
515+
516+
for userf in os.listdir(users_folder):
517+
user_cfg_dir = os.path.join(users_folder, userf, 'config')
518+
shortcuts_file = os.path.join(user_cfg_dir, 'shortcuts.vdf')
519+
520+
if not os.path.exists(user_cfg_dir):
521+
continue
522+
523+
shortcuts_vdf = {}
524+
sid=-1
525+
if os.path.exists(shortcuts_file):
526+
with open(shortcuts_file, 'rb') as f:
527+
shortcuts_vdf = vdf.binary_load(f)
528+
529+
for sid in list(shortcuts_vdf.get('shortcuts', {}).keys()):
530+
svalue = shortcuts_vdf.get('shortcuts', {}).get(sid)
531+
if APP_NAME in svalue.get('AppName', ''):
532+
if remove_shortcut:
533+
shortcuts_vdf.get('shortcuts', {}).pop(sid)
534+
else:
535+
return 2
536+
537+
with open(shortcuts_file, 'wb') as f:
538+
if not remove_shortcut:
539+
run_config = ['', '']
540+
if os.path.exists('/.flatpak-info'):
541+
run_config = [f'/usr/bin/flatpak', f'run {APP_ID}']
542+
elif exe := subprocess.run(['which', APP_ID], universal_newlines=True, stdout=subprocess.PIPE).stdout.strip():
543+
run_config = [exe, '']
544+
elif exe := os.getenv('APPIMAGE'):
545+
if APP_NAME in exe:
546+
exe = os.path.join(exe, os.pardir, APP_NAME + '*.AppImage') # remove version from file name
547+
run_config = [exe, '']
548+
else:
549+
return 1
550+
551+
sid = str(int(sid) + 1)
552+
shortcuts_vdf.setdefault('shortcuts', {})[sid] = {
553+
'appid': 1621167219,
554+
'AppName': APP_NAME,
555+
'Exe': f'"{run_config[0]}"',
556+
'StartDir': './',
557+
'icon': APP_ICON_FILE,
558+
'ShortcutPath': '',
559+
'LaunchOptions': run_config[1],
560+
'IsHidden': 0,
561+
'AllowDesktopConfig': 1,
562+
'AllowOverlay': 1,
563+
'OpenVR': 0,
564+
'Devkit': 0,
565+
'DevkitGameID': '',
566+
'DevkitOverrideAppID': 0,
567+
'LastPlayTime': 0,
568+
'FlatpakAppID': '',
569+
'tags': {}
570+
}
571+
572+
f.write(vdf.binary_dumps(shortcuts_vdf))
573+
except Exception as e:
574+
print(f'Error: Could not add {APP_NAME} as Steam shortcut:', e)
575+
576+
return 0

0 commit comments

Comments
 (0)