Skip to content
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

Cleanup platform checks. Remove old code. #3477

Merged
merged 8 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 0 additions & 7 deletions e2e/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,3 @@ electronTest('gets heroic, legendary, and gog versions', async (app) => {
expect(compareVersions(gogdlVersion, '0.7.1')).toBeGreaterThanOrEqual(0)
})
})

electronTest('test ipcMainInvokeHandler', async (app) => {
const page = await app.firstWindow()
const platform = await page.evaluate(async () => window.api.getPlatform())
console.log('Platform: ', platform)
expect(platform).toEqual(process.platform)
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this test because I removed the getPlatform function, that info is now exposed in the preload.ts file so we don't need an extra call to the backend

2 changes: 0 additions & 2 deletions src/backend/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export const createNewWindow = (url: string) =>
export const readConfig = async (file: 'library' | 'user') =>
ipcRenderer.invoke('readConfig', file)

export const getPlatform = async () => ipcRenderer.invoke('getPlatform')

export const isLoggedIn = async () => ipcRenderer.invoke('isLoggedIn')

export const writeConfig = async (data: {
Expand Down
10 changes: 5 additions & 5 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'
import { homedir, platform } from 'os'
import { homedir } from 'os'
import { join, resolve } from 'path'
import { parse } from '@node-steam/vdf'

Expand Down Expand Up @@ -27,9 +27,9 @@ const fontsStore = new TypeCheckedStoreBackend('fontsStore', {
name: 'fonts'
})

const isMac = platform() === 'darwin'
const isWindows = platform() === 'win32'
const isLinux = platform() === 'linux'
const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'
const isLinux = process.platform === 'linux'
const isSteamDeckGameMode = process.env.XDG_CURRENT_DESKTOP === 'gamescope'
const isCLIFullscreen = process.argv.includes('--fullscreen')
const isCLINoGui = process.argv.includes('--no-gui')
Expand Down Expand Up @@ -214,7 +214,7 @@ const necessaryFoldersByPlatform = {
}

export function createNecessaryFolders() {
necessaryFoldersByPlatform[platform()].forEach((folder: string) => {
necessaryFoldersByPlatform[process.platform].forEach((folder: string) => {
if (!existsSync(folder)) {
mkdirSync(folder)
}
Expand Down
5 changes: 2 additions & 3 deletions src/backend/downloadmanager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { DMStatus, InstallParams, Runner } from 'common/types'
import i18next from 'i18next'
import { notify, showDialogBoxModalAuto } from '../dialog/dialog'
import { isOnline } from '../online_monitor'
import { fixesPath } from 'backend/constants'
import { fixesPath, isWindows } from 'backend/constants'
import path from 'path'
import { existsSync, mkdirSync } from 'graceful-fs'
import { platform } from 'os'
import { storeMap } from 'common/utils'

async function installQueueElement(params: InstallParams): Promise<{
Expand Down Expand Up @@ -75,7 +74,7 @@ async function installQueueElement(params: InstallParams): Promise<{
}

try {
if (platform() !== 'win32') {
if (!isWindows) {
downloadFixesFor(appName, runner)
}

Expand Down
5 changes: 2 additions & 3 deletions src/backend/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { getGOGdlBin, getLegendaryBin } from 'backend/utils'
import { join } from 'path'
import { formatSystemInfo, getSystemInfo } from '../utils/systeminfo'
import { appendFile, writeFile } from 'fs/promises'
import { gamesConfigPath } from 'backend/constants'
import { gamesConfigPath, isWindows } from 'backend/constants'
import { gameManagerMap } from 'backend/storeManagers'
import { platform } from 'os'

export enum LogPrefix {
General = '',
Expand Down Expand Up @@ -392,7 +391,7 @@ class LogWriter {
const notNative =
['windows', 'Windows', 'Win32'].includes(
this.gameInfo.install.platform || ''
) && platform() !== 'win32'
) && !isWindows

// init log file and then append message if any
try {
Expand Down
22 changes: 9 additions & 13 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'electron'
import 'backend/updater'
import { autoUpdater } from 'electron-updater'
import { cpus, platform } from 'os'
import { cpus } from 'os'
import {
access,
constants,
Expand Down Expand Up @@ -94,7 +94,9 @@ import {
createNecessaryFolders,
fixAsarPath,
isSnap,
fixesPath
fixesPath,
isWindows,
isMac
} from './constants'
import { handleProtocol } from './protocol'
import {
Expand Down Expand Up @@ -160,7 +162,6 @@ import { storeMap } from 'common/utils'
app.commandLine?.appendSwitch('ozone-platform-hint', 'auto')

const { showOpenDialog } = dialog
const isWindows = platform() === 'win32'

async function initializeWindow(): Promise<BrowserWindow> {
createNecessaryFolders()
Expand Down Expand Up @@ -234,9 +235,7 @@ async function initializeWindow(): Promise<BrowserWindow> {
handleExit()
})

if (isWindows) {
detectVCRedist(mainWindow)
}
detectVCRedist(mainWindow)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detectVCRedist already checks if isWindows inside the function


if (process.env.VITE_DEV_SERVER_URL) {
if (!process.env.HEROIC_NO_REACT_DEVTOOLS) {
Expand Down Expand Up @@ -430,7 +429,6 @@ if (!gotTheLock) {
]
})

GOGUser.migrateCredentialsConfig()
const mainWindow = await initializeWindow()

protocol.handle('heroic', (request) => {
Expand Down Expand Up @@ -637,7 +635,7 @@ ipcMain.on('quit', async () => handleExit())
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (!isMac) {
app.quit()
}
})
Expand Down Expand Up @@ -709,8 +707,6 @@ ipcMain.handle('isFlatpak', () => isFlatpak)
ipcMain.handle('getGameOverride', async () => getGameOverride())
ipcMain.handle('getGameSdl', async (event, appName) => getGameSdl(appName))

ipcMain.handle('getPlatform', () => process.platform)

ipcMain.handle('showUpdateSetting', () => !isFlatpak)

ipcMain.handle('getLatestReleases', async () => {
Expand Down Expand Up @@ -831,12 +827,12 @@ ipcMain.handle('getAlternativeWine', async () =>
GlobalConfig.get().getAlternativeWine()
)

ipcMain.handle('readConfig', async (event, config_class) => {
if (config_class === 'library') {
ipcMain.handle('readConfig', async (event, configClass) => {
if (configClass === 'library') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to follow conventions

await libraryManagerMap['legendary'].refresh()
return LegendaryLibraryManager.getListOfGames()
}
const userInfo = await LegendaryUser.getUserInfo()
const userInfo = LegendaryUser.getUserInfo()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this await was not needed, the linter was flagging it

return userInfo?.displayName ?? ''
})

Expand Down
8 changes: 4 additions & 4 deletions src/backend/main_window.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppSettings, WindowProps } from 'common/types'
import { BrowserWindow, screen } from 'electron'
import path from 'path'
import { configStore } from './constants'
import { configStore, isLinux } from './constants'

let mainWindow: BrowserWindow | null = null

Expand Down Expand Up @@ -61,11 +61,11 @@ export const createMainWindow = () => {
const settings = configStore.get('settings', <AppSettings>{})
if (settings?.framelessWindow) {
// use native overlay controls where supported
if (['darwin', 'win32'].includes(process.platform)) {
if (isLinux) {
windowProps.frame = false
} else {
windowProps.titleBarStyle = 'hidden'
windowProps.titleBarOverlay = true
} else {
windowProps.frame = false
}
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contextBridge.exposeInMainWorld(
'isSteamDeckGameMode',
process.env.XDG_CURRENT_DESKTOP === 'gamescope'
)
contextBridge.exposeInMainWorld('platform', process.platform)

if (navigator.userAgent.includes('Windows')) {
Object.defineProperty(navigator, 'platform', {
Expand Down
13 changes: 0 additions & 13 deletions src/backend/storeManagers/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,6 @@ export async function getInstallInfo(
}
}
installInfoStore.set(installInfoStoreKey, info)
if (!info) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few lines above we do const info = { ..... }, I couldn't find any way this could be false since it's defined right before this line

logWarning(
[
'Failed to get Install Info for',
`${appName}`,
`using ${installPlatform} as platform,`,
'returning empty object'
],
LogPrefix.Gog
)
// @ts-expect-error TODO: Handle this better
return {}
}
return info
}

Expand Down
22 changes: 1 addition & 21 deletions src/backend/storeManagers/gog/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios'
import { writeFileSync, existsSync, unlinkSync } from 'graceful-fs'
import { existsSync, unlinkSync } from 'graceful-fs'
import { logError, logInfo, LogPrefix, logWarning } from '../../logger/logger'
import { GOGLoginData } from 'common/types'
import { configStore } from './electronStores'
Expand Down Expand Up @@ -115,26 +115,6 @@ export class GOGUser {
return JSON.parse(stdout)
}

/**
* Migrates existing authorization config to one supported by gogdl
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with linguin, we don't need this anymore, it was here temporarily to migrate credentials over a few releases

*/
public static migrateCredentialsConfig() {
if (!configStore.has('credentials')) {
return
}

const credentials = configStore.get_nodefault('credentials')
if (credentials?.loginTime)
credentials.loginTime = credentials?.loginTime / 1000

writeFileSync(
gogdlAuthConfig,
JSON.stringify({ '46899977096215655': credentials })
)
configStore.delete('credentials')
configStore.set('isLoggedIn', true)
}

public static logout() {
clearCache('gog')
configStore.clear()
Expand Down
5 changes: 3 additions & 2 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
isWindows,
installed,
configStore,
isCLINoGui
isCLINoGui,
isLinux
} from '../../constants'
import {
appendGameLog,
Expand Down Expand Up @@ -945,7 +946,7 @@ export async function stop(appName: string, stopWine = true) {
// not a perfect solution but it's the only choice for now

// @adityaruplaha: this is kinda arbitary and I don't understand it.
const pattern = process.platform === 'linux' ? appName : 'legendary'
const pattern = isLinux ? appName : 'legendary'
killPattern(pattern)

if (stopWine && !isNative(appName)) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/storeManagers/nile/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
logInfo,
logsDisabled
} from 'backend/logger/logger'
import { isWindows } from 'backend/constants'
import { isLinux, isWindows } from 'backend/constants'
import { GameConfig } from 'backend/game_config'
import {
getRunnerCallWithoutCredentials,
Expand Down Expand Up @@ -556,7 +556,7 @@ export async function forceUninstall(appName: string) {
}

export async function stop(appName: string, stopWine = true) {
const pattern = process.platform === 'linux' ? appName : 'nile'
const pattern = isLinux ? appName : 'nile'
killPattern(pattern)

if (stopWine && !isNative()) {
Expand Down
1 change: 0 additions & 1 deletion src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ interface AsyncIPCFunctions {
isMaximized: () => boolean
isMinimized: () => boolean
isFlatpak: () => boolean
getPlatform: () => NodeJS.Platform
showUpdateSetting: () => boolean
getLatestReleases: () => Promise<Release[]>
getCurrentChangelog: () => Promise<Release | null>
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const notify = (args: { title: string; body: string }) =>

const loginPage = window.api.openLoginPage

const getPlatform = window.api.getPlatform

const sidInfoPage = window.api.openSidInfoPage

const handleQuit = window.api.quit
Expand Down Expand Up @@ -163,7 +161,6 @@ export {
getGameSettings,
getInstallInfo,
getLegendaryConfig,
getPlatform,
getProgress,
handleQuit,
install,
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 @@ -85,7 +85,7 @@ export default React.memo(function Library(): JSX.Element {
initialStoresfilters = JSON.parse(storesFiltersString) as StoresFilters
} else {
// Else, use the old `category` filter
// TODO: we can remove this eventually after a few releases
// TODO: we can remove this eventually after a few releases and just use the code of the if
const storedCategory = (storage.getItem('category') as Category) || 'all'
initialStoresfilters = {
legendary: epicCategories.includes(storedCategory),
Expand All @@ -112,7 +112,7 @@ export default React.memo(function Library(): JSX.Element {
) as PlatformsFilters
} else {
// Else, use the old `category` filter
// TODO: we can remove this eventually after a few releases
// TODO: we can remove this eventually after a few releases and just use the code of the if
const storedCategory = storage.getItem('filterPlatform') || 'all'
initialPlatformsfilters = {
win: ['all', 'win'].includes(storedCategory),
Expand Down
15 changes: 3 additions & 12 deletions src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ import {
HelpItem
} from 'frontend/types'
import { withTranslation } from 'react-i18next'
import {
getGameInfo,
getLegendaryConfig,
getPlatform,
launch,
notify
} from '../helpers'
import { getGameInfo, getLegendaryConfig, launch, notify } from '../helpers'
import { i18n, t, TFunction } from 'i18next'

import ContextProvider from './ContextProvider'
Expand Down Expand Up @@ -78,7 +72,7 @@ interface StateProps {
language: string
libraryStatus: GameStatus[]
libraryTopSection: string
platform: NodeJS.Platform | 'unknown'
platform: NodeJS.Platform
refreshing: boolean
refreshingInTheBackground: boolean
hiddenGames: HiddenGame[]
Expand Down Expand Up @@ -172,7 +166,7 @@ class GlobalState extends PureComponent<Props> {
language: this.props.i18n.language,
libraryStatus: [],
libraryTopSection: globalSettings?.libraryTopSection || 'disabled',
platform: 'unknown',
platform: window.platform,
refreshing: false,
refreshingInTheBackground: true,
hiddenGames: configStore.get('games.hidden', []),
Expand Down Expand Up @@ -853,7 +847,6 @@ class GlobalState extends PureComponent<Props> {
const legendaryUser = configStore.has('userInfo')
const gogUser = gogConfigStore.has('userData')
const amazonUser = nileConfigStore.has('userData')
const platform = await getPlatform()

if (legendaryUser) {
await window.api.getUserInfo()
Expand All @@ -868,8 +861,6 @@ class GlobalState extends PureComponent<Props> {
this.setState({ gameUpdates: storedGameUpdates })
}

this.setState({ platform })

if (legendaryUser || gogUser || amazonUser) {
this.refreshLibrary({
checkForUpdates: true,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ declare global {
) => Promise<string>
setTheme: (themeClass: string) => void
isSteamDeckGameMode: boolean
platform: NodeJS.Platform
}

interface WindowEventMap {
Expand Down
Loading