A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
import { Runner, Status } from 'common/types'
import { TFunction } from 'i18next'
type StatusArgs = {
status: Status
t: TFunction<'gamepage', undefined>
runner: Runner
statusContext?: string
percent?: number
size?: string
}
export function getStatusLabel({
status,
statusContext,
t,
runner,
size,
percent
}: StatusArgs): string {
const statusMap: Partial<Record<Status, string>> = {
notSupportedGame: t('gamepage:status.notSupportedGame', 'Not Supported'),
notAvailable: t('gamepage:status.gameNotAvailable', 'Game not available'),
playing: t('gamepage:status.playing', 'Playing'),
queued: `${t('gamepage:status.queued', 'Queued')}`,
uninstalling: t('gamepage:status.uninstalling', 'Uninstalling'),
updating: `${t('gamepage:status.updating')} ${Math.ceil(percent || 0)}%`,
installing: `${t('gamepage:status.downloading', 'Downloading')} ${Math.ceil(
percent || 0
)}%`,
extracting: t('gamepage:status.extracting', 'Extracting'),
'syncing-saves': t('gamepage:status.syncingSaves', 'Syncing Saves'),
moving: t('gamepage:gamecard.moving', 'Moving'),
repairing: t('gamepage:gamecard.repairing', 'Repairing'),
installed: `${t('gamepage:status.installed')} ${
runner === 'sideload' ? '' : size
}`,
notInstalled: t('gamepage:status.notinstalled'),
launching: t('gamepage:status.launching', 'Launching'),
winetricks: t('gamepage:status.winetricks', 'Applying Winetricks fixes'),
redist: t(
'gamepage:status.redist',
'Installing Redistributables ({{redist}})',
{ redist: statusContext || '' }
)
}
return statusMap[status] || t('gamepage:status.notinstalled')
}
const storage = window.localStorage
const nonAvailbleGames = storage.getItem('nonAvailableGames') || '[]'
const nonAvailbleGamesArray = JSON.parse(nonAvailbleGames)
export async function handleNonAvailableGames(appName: string, runner: Runner) {
let gameAvailable: boolean
try {
gameAvailable = await window.api.isGameAvailable({
appName,
runner
})
} catch (error) {
// A failed probe must not break the status: treat it as available.
console.warn('Could not check whether the game is available', error)
return true
}
if (!gameAvailable) {
if (!nonAvailbleGamesArray.includes(appName)) {
nonAvailbleGamesArray.push(appName)
storage.setItem(
'nonAvailableGames',
JSON.stringify(nonAvailbleGamesArray)
)
}
} else {
if (nonAvailbleGamesArray.includes(appName)) {
nonAvailbleGamesArray.splice(nonAvailbleGamesArray.indexOf(appName), 1)
storage.setItem(
'nonAvailableGames',
JSON.stringify(nonAvailbleGamesArray)
)
}
}
return gameAvailable
}