Skip to content

Commit

Permalink
[Fix] Library not showing and Corrupted config dialog (#1411)
Browse files Browse the repository at this point in the history
* [Fix] Library going to Unreal Market on Login

* fix: error dialogs

* other: version

* fix: login check

* chore: skip auto-update on macOS

* fix: wineprefix error on windows

* chore: deal with old categorry epic

* fix: library logic and login event
  • Loading branch information
flavioislima authored May 30, 2022
1 parent 658ea7b commit 5bd2fdc
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 121 deletions.
45 changes: 20 additions & 25 deletions electron/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ abstract class GlobalConfig {
} catch (error) {
logError(
`Config file is corrupted, please check ${heroicConfigPath}`,
LogPrefix.Backend
LogPrefix.Backend,
false
)
version = 'v0'
}
Expand Down Expand Up @@ -94,7 +95,8 @@ abstract class GlobalConfig {
default:
logError(
`Invalid config version '${version}' requested.`,
LogPrefix.GlobalConfig
LogPrefix.GlobalConfig,
false
)
break
}
Expand All @@ -110,7 +112,8 @@ abstract class GlobalConfig {
// Upgrade failed.
logError(
`Failed to upgrade outdated ${version} config.`,
LogPrefix.GlobalConfig
LogPrefix.GlobalConfig,
false
)
}
}
Expand Down Expand Up @@ -340,7 +343,7 @@ abstract class GlobalConfig {
* Writes to file after that.
* DO NOT call `flush()` afterward.
*
* @returns true if upgrade successful, false if upgrade fails or no upgrade needed.
* @returns true if upgrade successful if upgrade fails or no upgrade needed.
*/
public abstract upgrade(): boolean

Expand Down Expand Up @@ -419,29 +422,21 @@ class GlobalConfigV0 extends GlobalConfig {
return this.getFactoryDefaults()
}

try {
let settings = JSON.parse(readFileSync(heroicConfigPath, 'utf-8'))
const defaultSettings = settings.defaultSettings as AppSettings
let settings = JSON.parse(readFileSync(heroicConfigPath, 'utf-8'))
const defaultSettings = settings.defaultSettings as AppSettings

// fix relative paths
const winePrefix = defaultSettings.winePrefix.replace('~', userHome)
// fix relative paths
const winePrefix = !isWindows
? defaultSettings?.winePrefix?.replace('~', userHome)
: ''

settings = {
...(await this.getFactoryDefaults()),
...settings.defaultSettings,
winePrefix
} as AppSettings
return settings
} catch (error) {
logError(
`Config file is corrupted, please check ${heroicConfigPath}`,
LogPrefix.Backend
)
const settings = {
...(await this.getFactoryDefaults())
}
return settings
}
settings = {
...(await this.getFactoryDefaults()),
...settings.defaultSettings,
winePrefix
} as AppSettings

return settings
}

public async getCustomWinePaths(): Promise<Set<WineInstallation>> {
Expand Down
34 changes: 13 additions & 21 deletions electron/game_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ abstract class GameConfig {
* Writes to file after that.
* DO NOT call `flush()` afterward.
*
* @returns true if upgrade successful, false if upgrade fails or no upgrade needed.
* @returns true if upgrade successful if upgrade fails or no upgrade needed.
*/
public abstract upgrade(): boolean

Expand Down Expand Up @@ -198,28 +198,20 @@ class GameConfigV0 extends GameConfig {
if (!existsSync(this.path)) {
return { ...GlobalConfig.get().config } as GameSettings
}
try {
const settings = JSON.parse(readFileSync(this.path, 'utf-8'))
// Take defaults, then overwrite if explicitly set values exist.
// The settings defined work as overrides.
const settings = JSON.parse(readFileSync(this.path, 'utf-8'))
// Take defaults, then overwrite if explicitly set values exist.
// The settings defined work as overrides.

// fix relative paths
const { winePrefix } = settings[this.appName] as GameSettings
// fix relative paths
const { winePrefix } = (settings[this.appName] as GameSettings) || {}

return {
...GlobalConfig.get().config,
...settings[this.appName],
winePrefix: winePrefix.replace('~', userHome)
} as GameSettings
} catch (error) {
logError(
`Config file is corrupted, please check ${this.path}`,
LogPrefix.Backend
)
return {
...GlobalConfig.get().config
}
}
return {
...GlobalConfig.get().config,
...settings[this.appName],
winePrefix: winePrefix
? winePrefix.replace('~', userHome)
: `${userHome}/.wine`
} as GameSettings
}

public async resetToDefaults() {
Expand Down
11 changes: 6 additions & 5 deletions electron/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ async function runLegendaryOrGogdlCommand(
errorHandler({
error: `${stdout.join().concat(stderr.join())}`,
logPath: options?.logFile,
runner: runner.name
runner: runner.name,
appName
})

if (signal) {
Expand All @@ -577,14 +578,14 @@ async function runLegendaryOrGogdlCommand(
appName
})

const dontShowDialog =
`${error}`.includes('signal') &&
`${error}`.includes('appears to be deleted')
const showDialog =
!`${error}`.includes('signal') &&
!`${error}`.includes('appears to be deleted')

logError(
['Error running', runner.name, 'command', `"${safeCommand}": ${error}`],
runner.logPrefix,
dontShowDialog
showDialog
)
return { stdout: '', stderr: `${error}`, fullCommand: safeCommand, error }
})
Expand Down
2 changes: 1 addition & 1 deletion electron/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class LegendaryLibrary {
this.library.set(app_name, null)
return app_name
} catch (error) {
logError(`Metadata for ${fileName} corrupted`, LogPrefix.Legendary, false)
logError(`Metadata for ${fileName} corrupted`, LogPrefix.Legendary)
return 'error'
}
}
Expand Down
2 changes: 1 addition & 1 deletion electron/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function logDebug(
export function logError(
text: string[] | string,
prefix: LogPrefix = LogPrefix.General,
showDialog = true,
showDialog = false,
skipLogToFile = false
) {
const extendText = `${getTimeStamp()} ERROR: ${getPrefixString(
Expand Down
7 changes: 5 additions & 2 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ import {
weblateUrl,
wikiLink,
fontsStore,
heroicConfigPath
heroicConfigPath,
isMac
} from './constants'
import { handleProtocol } from './protocol'
import { logError, logInfo, LogPrefix, logWarning } from './logger/logger'
Expand Down Expand Up @@ -192,7 +193,9 @@ async function createWindow(): Promise<BrowserWindow> {
} else {
Menu.setApplicationMenu(null)
mainWindow.loadURL(`file://${path.join(__dirname, '../build/index.html')}`)
autoUpdater.checkForUpdates()
if (!isMac) {
autoUpdater.checkForUpdates()
}
return mainWindow
}
}
Expand Down
8 changes: 2 additions & 6 deletions electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,7 @@ async function errorHandler(
const noSpaceMsg = 'Not enough available disk space'
const plat = r === 'legendary' ? 'Legendary (Epic Games)' : r
const deletedFolderMsg = 'appears to be deleted'
const otherErrorMessages = [
'No saved credentials',
'in get_user_entitlements',
'No credentials'
]
const otherErrorMessages = ['No saved credentials', 'No credentials']

if (!window) {
window = BrowserWindow.getFocusedWindow()
Expand All @@ -312,7 +308,7 @@ async function errorHandler(
execAsync(`tail "${logPath}" | grep 'disk space'`)
.then(({ stdout }) => {
if (stdout.includes(noSpaceMsg)) {
logError(noSpaceMsg, LogPrefix.Backend, false)
logError(noSpaceMsg, LogPrefix.Backend)
return showErrorBoxModal(
window,
i18next.t('box.error.diskspace.title', 'No Space'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heroic",
"version": "2.3.4",
"version": "2.3.5",
"private": true,
"main": "public/main.js",
"homepage": "./",
Expand Down
4 changes: 3 additions & 1 deletion src/components/UI/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export default function Header({ list }: ComponentProps) {

const numberOfGames = useMemo(() => {
const dlcCount =
category === 'epic' ? list.filter((lib) => lib.install.is_dlc).length : 0
category === 'legendary'
? list.filter((lib) => lib.install.is_dlc).length
: 0

return list.length - dlcCount
}, [list, category])
Expand Down
10 changes: 5 additions & 5 deletions src/components/UI/Sidebar/components/SidebarLinks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useTranslation } from 'react-i18next'
import { NavLink, useLocation } from 'react-router-dom'
import { getAppSettings } from 'src/helpers'
import ContextProvider from 'src/state/ContextProvider'
import { Runner } from 'src/types'
import { Category, Runner } from 'src/types'
import './index.css'

interface LocationState {
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function SidebarLinks() {
const loggedIn = epic.username || gog.username

const toggleCategory = useCallback(
(newCategory: string) => {
(newCategory: Category) => {
if (category !== newCategory) {
handleCategory(newCategory)
handleFilter(newCategory === 'unreal' ? 'unreal' : 'all')
Expand Down Expand Up @@ -112,9 +112,9 @@ export default function SidebarLinks() {
{epic.username && (
<a
href="#"
onClick={() => toggleCategory('epic')}
onClick={() => toggleCategory('legendary')}
className={cx('Sidebar__item SidebarLinks__subItem', {
['active']: category === 'epic'
['active']: category === 'legendary'
})}
>
{t('Epic Games', 'Epic Games')}
Expand Down Expand Up @@ -218,7 +218,7 @@ export default function SidebarLinks() {
to={`/settings/${appName}/wine`}
state={{ ...state, runner: state?.runner }}
className={cx('Sidebar__item SidebarLinks__subItem', {
['active']: category === 'wine'
['active']: type === 'wine'
})}
>
Wine
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Library/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function getLibraryTitle(
filter: string,
t: TFunction<'translation'>
) {
if (category === 'epic' || category === 'gog') {
if (category === 'legendary' || category === 'gog') {
return t('title.allGames', 'All Games')
}

Expand Down
16 changes: 11 additions & 5 deletions src/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function Library(): JSX.Element {
sortDescending={sortDescending}
toggleSortDescending={() => handleSortDescending()}
sortInstalled={sortInstalled}
library={category === 'epic' ? 'legendary' : 'gog'}
library={category === 'legendary' ? 'legendary' : 'gog'}
toggleSortinstalled={() => handleSortInstalled()}
/>
</div>
Expand Down Expand Up @@ -160,7 +160,7 @@ export default function Library(): JSX.Element {
return []
}

if (category === 'epic' && platform === 'linux') {
if (category === 'legendary' && platform === 'linux') {
return library.filter((game) => game?.is_game)
}

Expand Down Expand Up @@ -195,14 +195,20 @@ export default function Library(): JSX.Element {
// select library
const libraryToShow = useMemo(() => {
let library: GameInfo[] = []
if (epic.username && category === 'epic') {
const isEpic =
epic.username && (category === 'legendary' || category === 'unreal')
const isGog = gog.username && category === 'gog'

if (isEpic) {
library = epic.library
} else if (gog.username && category === 'gog') {
} else if (isGog) {
library = gog.library
} else if (!epic.username && category === 'epic') {
} else if (!isEpic) {
if (gog.username) {
library = gog.library
}
} else {
library = epic.library
}

// filter
Expand Down
62 changes: 27 additions & 35 deletions src/screens/WebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,41 +95,33 @@ export default function WebView() {
}
} else {
webview.addEventListener('did-navigate', () => {
if (
webview.getURL() === 'https://www.epicgames.com/id/api/redirect'
) {
webview.addEventListener(
'found-in-page',
async (res) => {
const data = res as Event & { result: { matches: number } }

if (!data.result.matches) {
return
}
webview.focus()
webview.selectAll()
webview.copy()

if (!clipboard.readText().match('sid')) {
return
}
const { sid }: SID = JSON.parse(clipboard.readText())
try {
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
await epic.login(sid)
handleSuccessfulLogin()
} catch (error) {
console.error(error)
ipcRenderer.send('logError', error)
}
},
{ once: true }
)
webview.findInPage('sid')
}
webview.findInPage('sid')
webview.addEventListener('found-in-page', async (res) => {
const data = res as Event & { result: { matches: number } }

if (!data.result.matches) {
return
}
webview.focus()
webview.selectAll()
webview.copy()

if (!clipboard.readText().match('sid')) {
return
}
const { sid }: SID = JSON.parse(clipboard.readText())
try {
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
await epic.login(sid)
handleSuccessfulLogin()
} catch (error) {
console.error(error)
ipcRenderer.send('logError', error)
}
})
})
}
}
Expand Down
Loading

0 comments on commit 5bd2fdc

Please sign in to comment.