Skip to content

Commit 10f5782

Browse files
committed
[FIX] Add offline warning dialog for games that are not playable offline
1 parent 1b8a059 commit 10f5782

File tree

5 files changed

+90
-41
lines changed

5 files changed

+90
-41
lines changed

public/locales/en/gamepage.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"title": "Move Game Installation"
1515
},
1616
"no": "NO",
17+
"offline_warning": {
18+
"message": "This game might not work properly offline. Do you want to play anyway?",
19+
"playAnyway": "Play Anyway",
20+
"title": "Offline Warning"
21+
},
22+
"ok": "OK",
1723
"repair": {
1824
"message": "Do you want to try to repair this game? This can take a long time.",
1925
"title": "Verify and Repair"

src/frontend/helpers/library.ts

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ type LaunchOptions = {
169169
hasUpdate: boolean
170170
showDialogModal: (options: DialogModalOptions) => void
171171
args?: string[]
172+
notPlayableOffline?: boolean
172173
}
173174

174175
const launch = async ({
@@ -178,29 +179,33 @@ const launch = async ({
178179
runner,
179180
hasUpdate,
180181
showDialogModal,
181-
args
182+
args,
183+
notPlayableOffline
182184
}: LaunchOptions): Promise<{ status: 'done' | 'error' | 'abort' }> => {
183-
// First handle update dialog if needed
184-
if (hasUpdate) {
185-
const { ignoreGameUpdates } = await window.api.requestGameSettings(appName)
186-
187-
if (ignoreGameUpdates) {
188-
// If updates are ignored, proceed to check launch options
189-
return checkLaunchOptionsAndLaunch({
190-
appName,
191-
t,
192-
launchArguments,
193-
runner,
194-
showDialogModal,
195-
args,
196-
skipVersionCheck: true,
197-
hasUpdate
198-
})
199-
}
185+
const proceedToLaunch = async () => {
186+
// First handle update dialog if needed
187+
if (hasUpdate) {
188+
const { ignoreGameUpdates } =
189+
await window.api.requestGameSettings(appName)
190+
191+
if (ignoreGameUpdates) {
192+
// If updates are ignored, proceed to check launch options
193+
return checkLaunchOptionsAndLaunch({
194+
appName,
195+
t,
196+
launchArguments,
197+
runner,
198+
showDialogModal,
199+
args,
200+
skipVersionCheck: true,
201+
hasUpdate
202+
})
203+
}
200204

201-
// promisifies the showDialogModal button click callbacks
202-
const launchFinished = new Promise<{ status: 'done' | 'error' | 'abort' }>(
203-
(res) => {
205+
// promisifies the showDialogModal button click callbacks
206+
const launchFinished = new Promise<{
207+
status: 'done' | 'error' | 'abort'
208+
}>((res) => {
204209
showDialogModal({
205210
message: t('gamepage:box.update.message'),
206211
title: t('gamepage:box.update.title'),
@@ -236,25 +241,55 @@ const launch = async ({
236241
}
237242
]
238243
})
239-
}
240-
)
244+
})
245+
246+
return launchFinished
247+
}
248+
249+
// No update needed, proceed to check launch options
250+
return checkLaunchOptionsAndLaunch({
251+
appName,
252+
t,
253+
launchArguments,
254+
runner,
255+
showDialogModal,
256+
args,
257+
hasUpdate
258+
})
259+
}
241260

242-
return launchFinished
261+
if (notPlayableOffline) {
262+
return new Promise((res) => {
263+
showDialogModal({
264+
title: t('gamepage:box.offline_warning.title', 'Offline Warning'),
265+
message: t(
266+
'gamepage:box.offline_warning.message',
267+
'This game might not work properly offline. Do you want to play anyway?'
268+
),
269+
type: 'MESSAGE',
270+
buttons: [
271+
{
272+
text: t('box.ok', 'OK'),
273+
onClick: () => {
274+
showDialogModal({ showDialog: false })
275+
res({ status: 'abort' })
276+
}
277+
},
278+
{
279+
text: t('gamepage:box.offline_warning.playAnyway', 'Play Anyway'),
280+
onClick: async () => {
281+
showDialogModal({ showDialog: false })
282+
res(await proceedToLaunch())
283+
}
284+
}
285+
]
286+
})
287+
})
243288
}
244289

245-
// No update needed, proceed to check launch options
246-
return checkLaunchOptionsAndLaunch({
247-
appName,
248-
t,
249-
launchArguments,
250-
runner,
251-
showDialogModal,
252-
args,
253-
hasUpdate
254-
})
290+
return proceedToLaunch()
255291
}
256292

257-
// Helper function to check for launch options and show dialog if needed
258293
async function checkLaunchOptionsAndLaunch({
259294
appName,
260295
t,

src/frontend/screens/Game/GamePage/components/MainButton.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ const MainButton = ({
196196
is.syncing ||
197197
is.launching ||
198198
is.installingWinetricksPackages ||
199-
is.installingRedist ||
200-
is.notPlayableOffline
199+
is.installingRedist
201200
}
202201
autoFocus={true}
203202
onClick={async () => handlePlay(gameInfo)}

src/frontend/screens/Game/GamePage/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ export default React.memo(function GamePage(): JSX.Element | null {
541541
launchArguments,
542542
runner: gameInfo.runner,
543543
hasUpdate,
544-
showDialogModal
544+
showDialogModal,
545+
notPlayableOffline
545546
})
546547
}
547548

src/frontend/screens/Library/components/GameCard/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ const GameCard = ({
101101

102102
const navigate = useNavigate()
103103

104-
const { hiddenGames, favouriteGames, showDialogModal, activeController } =
105-
useContext(ContextProvider)
104+
const {
105+
hiddenGames,
106+
favouriteGames,
107+
showDialogModal,
108+
activeController,
109+
connectivity
110+
} = useContext(ContextProvider)
106111
const { openGameSettingsModal, openGameLogsModal, openGameCategoriesModal } =
107112
useGlobalState.keys(
108113
'openGameSettingsModal',
@@ -545,12 +550,15 @@ const GameCard = ({
545550

546551
if (isInstalled) {
547552
setIsLaunching(true)
553+
const isOffline = connectivity.status !== 'online'
554+
const notPlayableOffline = isOffline && !gameInfo.canRunOffline
548555
return launch({
549556
appName,
550557
t,
551558
runner,
552559
hasUpdate,
553-
showDialogModal
560+
showDialogModal,
561+
notPlayableOffline
554562
})
555563
}
556564
return

0 commit comments

Comments
 (0)