Skip to content

Commit 0fd403e

Browse files
committed
Option to use Flatpaks under Linux
This adds a configuration setting "linuxUseFlatpak" which controls whether Steam should be launched as a Flatpak or not. By default this is detected automatically based on the path, but an option in the settings can override the behaviour. If this option is enabled, we first check if we are able to read from our config directory. If not, we display an error and ask the user to give us permission. If we do, then we launch Steam through flatpak rather than the binary directly.
1 parent ebf8f02 commit 0fd403e

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

src/components/settings-components/SettingsView.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ let settingsList = [
299299
'fa-file-alt',
300300
() => emitInvoke('ShowDependencyStrings')
301301
),
302+
new SettingsRow(
303+
'Other',
304+
'Launch as Flatpak (Linux)',
305+
'Launch Steam via flatpak',
306+
async () => {
307+
switch (settings.value.getContext().global.linuxUseFlatpak) {
308+
case null:
309+
return 'Automatic';
310+
case true:
311+
return 'Flatpak';
312+
case false:
313+
return 'Native';
314+
}
315+
},
316+
'fa-exchange-alt',
317+
() => emitInvoke('ToggleLinuxUseFlatpak')
318+
),
302319
];
303320
304321
watch(search, () => {

src/pages/Manager.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ function setFunkyMode(value: boolean) {
338338
settings.value.setFunkyMode(value);
339339
}
340340
341+
function setLinuxUseFlatpak(value: boolean) {
342+
settings.value.setLinuxUseFlatpak(value);
343+
}
344+
341345
function browseDataFolder() {
342346
LinkProvider.instance.openLink('file://' + PathResolver.ROOT);
343347
}
@@ -508,6 +512,9 @@ async function handleSettingsCallbacks(invokedSetting: any) {
508512
case "ToggleFunkyMode":
509513
setFunkyMode(!settings.value.getContext().global.funkyModeEnabled);
510514
break;
515+
case "ToggleLinuxUseFlatpak":
516+
setLinuxUseFlatpak(!settings.value.getContext().global.linuxUseFlatpak);
517+
break;
511518
case "SwitchTheme":
512519
toggleDarkTheme();
513520
document.documentElement.classList.toggle('html--dark', settings.value.getContext().global.darkTheme);

src/r2mm/launching/runners/linux/SteamGameRunner_Linux.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,51 @@ export default class SteamGameRunner_Linux extends GameRunnerProvider {
5555
if (args instanceof R2Error) {
5656
return args
5757
}
58-
return this.start(game, args);
58+
return this.start(game, args, profile.getProfilePath());
5959
}
6060

6161
public async startVanilla(game: Game, profile: Profile): Promise<void | R2Error> {
6262
const instructions = await GameInstructions.getInstructionsForGame(game, profile);
63-
return this.start(game, instructions.vanillaParameters);
63+
return this.start(game, instructions.vanillaParameters, null);
6464
}
6565

66-
async start(game: Game, args: string): Promise<void | R2Error> {
66+
async start(game: Game, args: string, profiledir: string | null): Promise<void | R2Error> {
6767

6868
const settings = await ManagerSettings.getSingleton(game);
6969
const steamDir = await GameDirectoryResolverProvider.instance.getSteamDirectory();
7070
if(steamDir instanceof R2Error) {
7171
return steamDir;
7272
}
73+
let as_flatpak = settings.getContext().global.linuxUseFlatpak;
74+
if (as_flatpak === null) {
75+
// Assume that if the path contains the flatpak directory we must want to use flatpak
76+
as_flatpak = steamDir.includes("/com.valvesoftware.Steam/");
77+
}
78+
79+
if (as_flatpak && profiledir) {
80+
// Ensure we have permission to read our config dir
81+
let visible = true;
82+
const check_cmd = `flatpak run --command='sh' com.valvesoftware.Steam -c 'ls "${profiledir}"'`;
83+
await ChildProcess.exec(check_cmd, undefined, (err: Error) => {
84+
if (err) {
85+
visible = false;
86+
}
87+
});
88+
if (!visible) {
89+
throw new R2Error('Flatpak Permissions Error',
90+
`The directory "${profiledir}" is not visible from within the Flatpak container`,
91+
'`flatpak override com.valvesoftware.Steam --user --filesystem="${XDG_CONFIG_HOME:-$HOME/.config}/r2modmanPlus-local"` to grant access, then restart Steam.');
92+
}
93+
}
7394

7495
LoggerProvider.instance.Log(LogSeverity.INFO, `Steam folder is: ${steamDir}`);
7596

7697
try {
77-
const cmd = `"${steamDir}/steam.sh" -applaunch ${game.activePlatform.storeIdentifier} ${args} ${settings.getContext().gameSpecific.launchParameters}`;
98+
let cmd = `"${steamDir}/steam.sh" -applaunch ${game.activePlatform.storeIdentifier} ${args} ${settings.getContext().gameSpecific.launchParameters}`;
99+
if (as_flatpak) {
100+
cmd = `flatpak run com.valvesoftware.Steam ${cmd}`;
101+
}
102+
78103
LoggerProvider.instance.Log(LogSeverity.INFO, `Running command: ${cmd}`);
79104
await ChildProcess.exec(cmd);
80105
} catch(err) {

src/r2mm/manager/ManagerSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export default class ManagerSettings {
9898
await this.save();
9999
}
100100

101+
public async setLinuxUseFlatpak(enabled: boolean) {
102+
ManagerSettings.CONTEXT.global.linuxUseFlatpak = enabled;
103+
await this.save();
104+
}
105+
101106
public async expandCards() {
102107
ManagerSettings.CONTEXT.global.expandedCards = true;
103108
await this.save();

src/r2mm/manager/SettingsDexieStore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export default class SettingsDexieStore extends Dexie {
123123
defaultStore: undefined,
124124
gameSelectionViewMode: GameSelectionViewMode.CARD,
125125
previewPanelWidth: 500,
126+
linuxUseFlatpak: null,
126127
},
127128
gameSpecific: {
128129
version: 2,
@@ -212,6 +213,7 @@ export interface ManagerSettingsInterfaceGlobal_V2 {
212213
defaultStore: Platform | undefined;
213214
gameSelectionViewMode: GameSelectionViewMode;
214215
previewPanelWidth: number;
216+
linuxUseFlatpak: boolean | null;
215217
}
216218

217219
/**

0 commit comments

Comments
 (0)