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

[Refactor] Constants cleanup #4264

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/backend/__tests__/constants.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixAsarPath } from '../constants'
import { fixAsarPath } from 'backend/constants/paths'

export function overrideProcessPlatform(os: string): string {
const original_os = process.platform
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('Constants - fixAsarPath', () => {
describe('Constants - getShell', () => {
async function getShell(): Promise<string> {
jest.resetModules()
return import('../constants').then((module) => {
return import('../constants/others').then((module) => {
return module.execOptions.shell
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/__tests__/main_window.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createMainWindow, sendFrontendMessage } from '../main_window'
import { BrowserWindow, Display, screen } from 'electron'
import { configStore } from '../constants'
import { overrideProcessPlatform } from './constants.test'
import { configStore } from 'backend/constants/key_value_stores'

jest.mock('../logger/logfile')

Expand Down
6 changes: 5 additions & 1 deletion src/backend/anticheat/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { anticheatDataPath, isMac, isWindows } from '../constants'
import { logInfo, LogPrefix, logWarning } from '../logger/logger'
import { readFileSync, writeFileSync } from 'graceful-fs'
import { AntiCheatInfo } from 'common/types'
import { runOnceWhenOnline } from '../online_monitor'
import { axiosClient } from 'backend/utils'
import { join } from 'node:path'
import { appFolder } from 'backend/constants/paths'
import { isMac, isWindows } from 'backend/constants/environment'

const anticheatDataPath = join(appFolder, 'areweanticheatyet.json')

async function downloadAntiCheatData() {
if (process.env.CI === 'e2e') return
Expand Down
54 changes: 40 additions & 14 deletions src/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@ import {
GlobalConfigVersion,
WineInstallation
} from 'common/types'
import {
currentGlobalConfigVersion,
configPath,
defaultWinePrefix,
gamesConfigPath,
heroicInstallPath,
userHome,
isFlatpak,
isMac,
isWindows,
getSteamCompatFolder,
configStore,
isLinux
} from './constants'
import { currentGlobalConfigVersion } from 'backend/constants/others'

import { logError, logInfo, LogPrefix } from './logger/logger'
import {
Expand All @@ -32,6 +19,45 @@ import {
getWineskinWine
} from './utils/compatibility_layers'
import { backendEvents } from './backend_events'
import { configStore } from './constants/key_value_stores'
import { isFlatpak, isLinux, isMac, isWindows } from './constants/environment'
import {
configPath,
defaultWinePrefix,
gamesConfigPath,
heroicInstallPath,
userHome
} from './constants/paths'
import { join } from 'path'
import { spawnSync } from 'child_process'

function getSteamCompatFolder() {
// Paths are from https://savelocation.net/steam-game-folder
if (isWindows) {
const defaultWinPath = join(process.env['PROGRAMFILES(X86)'] ?? '', 'Steam')
return defaultWinPath
} else if (isMac) {
return join(userHome, 'Library/Application Support/Steam')
} else {
const flatpakSteamPath = join(
userHome,
'.var/app/com.valvesoftware.Steam/.steam/steam'
)

if (existsSync(flatpakSteamPath)) {
// check if steam is really installed via flatpak
const { status } = spawnSync('flatpak', [
'info',
'com.valvesoftware.Steam'
])

if (status === 0) {
return flatpakSteamPath
}
}
return join(userHome, '.steam/steam')
}
}

/**
* This class does config handling.
Expand Down
Loading
Loading