Skip to content

[FIX]: Multiple Amazon Games bugs #2897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified public/bin/darwin/nile
Binary file not shown.
Binary file modified public/bin/linux/nile
Binary file not shown.
Binary file modified public/bin/win32/nile.exe
Binary file not shown.
10 changes: 7 additions & 3 deletions src/backend/storeManagers/nile/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from 'common/types/nile'
import { existsSync, readFileSync, writeFileSync } from 'graceful-fs'
import { installStore, libraryStore } from './electronStores'
import { getNileBin } from 'backend/utils'
import { getFileSize, getNileBin, removeSpecialcharacters } from 'backend/utils'
import { callRunner } from 'backend/launcher'
import { dirname, join } from 'path'
import { app } from 'electron'
Expand Down Expand Up @@ -66,7 +66,8 @@ function loadGamesInAccount() {
} = productDetail

const info = installedGames.get(product.id)

// Create save folder name like nile
const safeFolderName = removeSpecialcharacters(title ?? '')
library.set(product.id, {
app_name: product.id,
art_cover: iconUrl,
Expand All @@ -75,11 +76,14 @@ function loadGamesInAccount() {
install: info
? {
install_path: info.path,
// For some time size was undefined in installed.json, that's why we
// need to keep this fallback to 0
install_size: getFileSize(info.size ?? 0),
version: info.version,
platform: 'Windows' // Amazon Games only supports Windows
}
: {},
folder_name: title,
folder_name: safeFolderName,
is_installed: info !== undefined,
runner: 'nile',
title: title ?? '???',
Expand Down
2 changes: 2 additions & 0 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ async function errorHandler({
}
}

// If you ever modify this range of characters, please also add them to nile
// source as this function is used to determine how game directory will be named
function removeSpecialcharacters(text: string): string {
const regexp = new RegExp(/[:|/|*|?|<|>|\\|&|{|}|%|$|@|`|!|™|+|'|"|®]/, 'gi')
return text.replaceAll(regexp, '')
Expand Down
1 change: 1 addition & 0 deletions src/common/types/nile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface NileInstallMetadataInfo {
id: string
version: string
path: string
size?: number
}

export interface NileInstallInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export default function SidebarLinks() {

const settingsPath = '/settings/app/default/general'

const loggedIn = epic.username || gog.username || amazon.username
const loggedIn = epic.username || gog.username || amazon.user_id

async function handleRefresh() {
localStorage.setItem('scrollPosition', '0')

const shouldRefresh =
(epic.username && !epic.library.length) ||
(gog.username && !gog.library.length) ||
(amazon.username && !amazon.library.length)
(amazon.user_id && !amazon.library.length)
if (shouldRefresh) {
return refreshLibrary({ runInBackground: true })
}
Expand All @@ -82,7 +82,7 @@ export default function SidebarLinks() {

// By default, open Epic Store
let defaultStore = '/epicstore'
if (!epic.username && !gog.username && amazon.username) {
if (!epic.username && !gog.username && amazon.user_id) {
// If only logged in to Amazon Games, open Amazon Gaming
defaultStore = '/amazonstore'
} else if (!epic.username && gog.username) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/UI/StoreFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default React.memo(function StoreFilter() {

const isGOGLoggedin = gog.username
const isEpicLoggedin = epic.username
const isAmazonLoggedin = amazon.username
const isAmazonLoggedin = amazon.user_id

return (
<div className="storeFilter">
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default React.memo(function Library(): JSX.Element {
if (gogCategories.includes(category) && !gog.username) {
handleCategory('all')
}
if (amazonCategories.includes(category) && !amazon.username) {
if (amazonCategories.includes(category) && !amazon.user_id) {
handleCategory('all')
}
}, [epic.username, gog.username, amazon.username])
Expand Down Expand Up @@ -244,7 +244,7 @@ export default React.memo(function Library(): JSX.Element {
} else {
const isEpic = epic.username && epicCategories.includes(category)
const isGog = gog.username && gogCategories.includes(category)
const isAmazon = amazon.username && amazonCategories.includes(category)
const isAmazon = amazon.user_id && amazonCategories.includes(category)
const epicLibrary = isEpic ? epic.library : []
const gogLibrary = isGog ? gog.library : []
const sideloadedApps = sideloadedCategories.includes(category)
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/screens/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default React.memo(function NewLogin() {
const [isEpicLoggedIn, setIsEpicLoggedIn] = useState(Boolean(epic.username))
const [isGogLoggedIn, setIsGogLoggedIn] = useState(Boolean(gog.username))
const [isAmazonLoggedIn, setIsAmazonLoggedIn] = useState(
Boolean(amazon.username)
Boolean(amazon.user_id)
)

const loginMessage = t(
Expand All @@ -42,8 +42,8 @@ export default React.memo(function NewLogin() {
useEffect(() => {
setIsEpicLoggedIn(Boolean(epic.username))
setIsGogLoggedIn(Boolean(gog.username))
setIsAmazonLoggedIn(Boolean(amazon.username))
}, [epic.username, gog.username, amazon.username, t])
setIsAmazonLoggedIn(Boolean(amazon.user_id))
}, [epic.username, gog.username, amazon.user_id, t])

async function handleLibraryClick() {
await refreshLibrary({ runInBackground: false })
Expand Down Expand Up @@ -110,7 +110,7 @@ export default React.memo(function NewLogin() {
icon={() => <AmazonLogo />}
loginUrl={amazonLoginPath}
isLoggedIn={isAmazonLoggedIn}
user={amazon.username}
user={amazon.username || 'Unknown'}
logoutAction={amazon.logout}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/WebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default function WebView() {
!gog.username
) {
setShowLoginWarningFor('gog')
} else if (startUrl.match(/gaming\.amazon\.com/) && !amazon.username) {
} else if (startUrl.match(/gaming\.amazon\.com/) && !amazon.user_id) {
setShowLoginWarningFor('amazon')
}
}, [startUrl])
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ interface StateProps {
}
amazon: {
library: GameInfo[]
user_id?: string
username?: string
}
wineVersions: WineVersionInfo[]
Expand Down Expand Up @@ -147,7 +148,8 @@ class GlobalState extends PureComponent<Props> {
},
amazon: {
library: this.loadAmazonLibrary(),
username: nileConfigStore.get_nodefault('userData.given_name')
user_id: nileConfigStore.get_nodefault('userData.user_id'),
username: nileConfigStore.get_nodefault('userData.name')
},
wineVersions: wineDownloaderInfoStore.get('wine-releases', []),
error: false,
Expand Down Expand Up @@ -423,6 +425,7 @@ class GlobalState extends PureComponent<Props> {
this.setState({
amazon: {
library: [],
user_id: response.user?.user_id,
username: response.user?.name
}
})
Expand All @@ -438,6 +441,7 @@ class GlobalState extends PureComponent<Props> {
this.setState({
amazon: {
library: [],
user_id: null,
username: null
}
})
Expand Down Expand Up @@ -497,7 +501,7 @@ class GlobalState extends PureComponent<Props> {
}

let amazonLibrary = nileLibraryStore.get('library', [])
if (amazon.username && (!amazonLibrary.length || !amazon.library.length)) {
if (amazon.user_id && (!amazonLibrary.length || !amazon.library.length)) {
window.api.logInfo('No cache found, getting data from nile...')
await window.api.refreshLibrary('nile')
amazonLibrary = this.loadAmazonLibrary()
Expand All @@ -516,6 +520,7 @@ class GlobalState extends PureComponent<Props> {
},
amazon: {
library: amazonLibrary,
user_id: amazon.user_id,
username: amazon.username
},
gameUpdates: updates,
Expand Down Expand Up @@ -861,6 +866,7 @@ class GlobalState extends PureComponent<Props> {
},
amazon: {
library: amazon.library,
user_id: amazon.user_id,
username: amazon.username,
getLoginData: this.getAmazonLoginData,
login: this.amazonLogin,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface ContextType {
}
amazon: {
library: GameInfo[]
user_id?: string
username?: string
getLoginData: () => Promise<NileLoginData>
login: (data: NileRegisterData) => Promise<string>
Expand Down