From e9cf8b37a62a2ee62d4a87e857fdfa9f634fa20e Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 12:51:32 -0300 Subject: [PATCH 1/8] Cleanup platform checks in main.ts --- src/backend/main.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backend/main.ts b/src/backend/main.ts index c485f49a64..2b0bb73813 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -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, @@ -94,7 +94,9 @@ import { createNecessaryFolders, fixAsarPath, isSnap, - fixesPath + fixesPath, + isWindows, + isMac } from './constants' import { handleProtocol } from './protocol' import { @@ -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 { createNecessaryFolders() @@ -234,9 +235,7 @@ async function initializeWindow(): Promise { handleExit() }) - if (isWindows) { - detectVCRedist(mainWindow) - } + detectVCRedist(mainWindow) if (process.env.VITE_DEV_SERVER_URL) { if (!process.env.HEROIC_NO_REACT_DEVTOOLS) { @@ -637,7 +636,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() } }) From 2dfebf4e8c42253d82681443cccbd8d2d0361c54 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 12:52:05 -0300 Subject: [PATCH 2/8] Fix env var name convention and remove unneeded await --- src/backend/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/main.ts b/src/backend/main.ts index 2b0bb73813..37af3c0704 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -830,12 +830,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') { await libraryManagerMap['legendary'].refresh() return LegendaryLibraryManager.getListOfGames() } - const userInfo = await LegendaryUser.getUserInfo() + const userInfo = LegendaryUser.getUserInfo() return userInfo?.displayName ?? '' }) From fa35810eaf7b584da3a7e2086c85ef035ecf9199 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 12:52:43 -0300 Subject: [PATCH 3/8] Remove GOG credentials migration temporary code --- src/backend/main.ts | 1 - src/backend/storeManagers/gog/user.ts | 22 +--------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/backend/main.ts b/src/backend/main.ts index 37af3c0704..f4f45f379f 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -429,7 +429,6 @@ if (!gotTheLock) { ] }) - GOGUser.migrateCredentialsConfig() const mainWindow = await initializeWindow() protocol.handle('heroic', (request) => { diff --git a/src/backend/storeManagers/gog/user.ts b/src/backend/storeManagers/gog/user.ts index 19000d8fea..ff84957cb5 100644 --- a/src/backend/storeManagers/gog/user.ts +++ b/src/backend/storeManagers/gog/user.ts @@ -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' @@ -115,26 +115,6 @@ export class GOGUser { return JSON.parse(stdout) } - /** - * Migrates existing authorization config to one supported by gogdl - */ - 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() From 7b3a2cf30dd7190693a85649b13ebe8d713814d5 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 12:53:42 -0300 Subject: [PATCH 4/8] Remove uneeded undefined/null check --- src/backend/storeManagers/gog/library.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/backend/storeManagers/gog/library.ts b/src/backend/storeManagers/gog/library.ts index dd34fc3e17..a92942e7d4 100644 --- a/src/backend/storeManagers/gog/library.ts +++ b/src/backend/storeManagers/gog/library.ts @@ -696,19 +696,6 @@ export async function getInstallInfo( } } installInfoStore.set(installInfoStoreKey, info) - if (!info) { - 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 } From 8ce6bc8870b7f46e67cabbae42e8880d2f2d4fda Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 13:01:18 -0300 Subject: [PATCH 5/8] Improve future deletion comment --- src/frontend/screens/Library/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/screens/Library/index.tsx b/src/frontend/screens/Library/index.tsx index 263e1c61eb..bb720bd8fe 100644 --- a/src/frontend/screens/Library/index.tsx +++ b/src/frontend/screens/Library/index.tsx @@ -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), @@ -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), From 7fdea223917ad24d1490bb2f24e18dc14eb51562 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 13:31:19 -0300 Subject: [PATCH 6/8] Replace process.platorm with constants. Preload platform in the frontend. --- e2e/api.spec.ts | 7 ------- src/backend/api/helpers.ts | 2 -- src/backend/constants.ts | 10 +++++----- src/backend/downloadmanager/utils.ts | 5 ++--- src/backend/logger/logger.ts | 5 ++--- src/backend/main.ts | 2 -- src/backend/main_window.ts | 8 ++++---- src/backend/preload.ts | 1 + src/backend/storeManagers/legendary/games.ts | 5 +++-- src/backend/storeManagers/nile/games.ts | 4 ++-- src/common/typedefs/ipcBridge.d.ts | 1 - src/frontend/helpers/index.ts | 3 --- src/frontend/state/GlobalState.tsx | 15 +++------------ src/frontend/types.ts | 1 + 14 files changed, 23 insertions(+), 46 deletions(-) diff --git a/e2e/api.spec.ts b/e2e/api.spec.ts index 378db1370a..9bc85fdd5c 100644 --- a/e2e/api.spec.ts +++ b/e2e/api.spec.ts @@ -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) -}) diff --git a/src/backend/api/helpers.ts b/src/backend/api/helpers.ts index 6a8250183b..938d5f2ca6 100644 --- a/src/backend/api/helpers.ts +++ b/src/backend/api/helpers.ts @@ -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: { diff --git a/src/backend/constants.ts b/src/backend/constants.ts index eeea8c3ee9..4e9d8382bd 100644 --- a/src/backend/constants.ts +++ b/src/backend/constants.ts @@ -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' @@ -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') @@ -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) } diff --git a/src/backend/downloadmanager/utils.ts b/src/backend/downloadmanager/utils.ts index 547e62237b..7eab9fb562 100644 --- a/src/backend/downloadmanager/utils.ts +++ b/src/backend/downloadmanager/utils.ts @@ -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<{ @@ -75,7 +74,7 @@ async function installQueueElement(params: InstallParams): Promise<{ } try { - if (platform() !== 'win32') { + if (!isWindows) { downloadFixesFor(appName, runner) } diff --git a/src/backend/logger/logger.ts b/src/backend/logger/logger.ts index f7b00b31fd..db4bbfdbef 100644 --- a/src/backend/logger/logger.ts +++ b/src/backend/logger/logger.ts @@ -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 = '', @@ -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 { diff --git a/src/backend/main.ts b/src/backend/main.ts index f4f45f379f..ef1903abb9 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -707,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 () => { diff --git a/src/backend/main_window.ts b/src/backend/main_window.ts index dc7b98b365..2be982ec81 100644 --- a/src/backend/main_window.ts +++ b/src/backend/main_window.ts @@ -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 @@ -61,11 +61,11 @@ export const createMainWindow = () => { const settings = configStore.get('settings', {}) 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 } } diff --git a/src/backend/preload.ts b/src/backend/preload.ts index 5edfd40e82..54958c0b2e 100644 --- a/src/backend/preload.ts +++ b/src/backend/preload.ts @@ -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', { diff --git a/src/backend/storeManagers/legendary/games.ts b/src/backend/storeManagers/legendary/games.ts index b66110d3e5..cff9004051 100644 --- a/src/backend/storeManagers/legendary/games.ts +++ b/src/backend/storeManagers/legendary/games.ts @@ -36,7 +36,8 @@ import { isWindows, installed, configStore, - isCLINoGui + isCLINoGui, + isLinux } from '../../constants' import { appendGameLog, @@ -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)) { diff --git a/src/backend/storeManagers/nile/games.ts b/src/backend/storeManagers/nile/games.ts index 673c803520..d358743002 100644 --- a/src/backend/storeManagers/nile/games.ts +++ b/src/backend/storeManagers/nile/games.ts @@ -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, @@ -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()) { diff --git a/src/common/typedefs/ipcBridge.d.ts b/src/common/typedefs/ipcBridge.d.ts index 341aaed72e..39b05a6015 100644 --- a/src/common/typedefs/ipcBridge.d.ts +++ b/src/common/typedefs/ipcBridge.d.ts @@ -151,7 +151,6 @@ interface AsyncIPCFunctions { isMaximized: () => boolean isMinimized: () => boolean isFlatpak: () => boolean - getPlatform: () => NodeJS.Platform showUpdateSetting: () => boolean getLatestReleases: () => Promise getCurrentChangelog: () => Promise diff --git a/src/frontend/helpers/index.ts b/src/frontend/helpers/index.ts index 258fb23f98..f2958e1dbc 100644 --- a/src/frontend/helpers/index.ts +++ b/src/frontend/helpers/index.ts @@ -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 @@ -163,7 +161,6 @@ export { getGameSettings, getInstallInfo, getLegendaryConfig, - getPlatform, getProgress, handleQuit, install, diff --git a/src/frontend/state/GlobalState.tsx b/src/frontend/state/GlobalState.tsx index 292d37b6d4..1ff1efb1d3 100644 --- a/src/frontend/state/GlobalState.tsx +++ b/src/frontend/state/GlobalState.tsx @@ -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' @@ -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[] @@ -172,7 +166,7 @@ class GlobalState extends PureComponent { language: this.props.i18n.language, libraryStatus: [], libraryTopSection: globalSettings?.libraryTopSection || 'disabled', - platform: 'unknown', + platform: window.platform, refreshing: false, refreshingInTheBackground: true, hiddenGames: configStore.get('games.hidden', []), @@ -853,7 +847,6 @@ class GlobalState extends PureComponent { 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() @@ -868,8 +861,6 @@ class GlobalState extends PureComponent { this.setState({ gameUpdates: storedGameUpdates }) } - this.setState({ platform }) - if (legendaryUser || gogUser || amazonUser) { this.refreshLibrary({ checkForUpdates: true, diff --git a/src/frontend/types.ts b/src/frontend/types.ts index ec35934dcf..ddac1fd12a 100644 --- a/src/frontend/types.ts +++ b/src/frontend/types.ts @@ -164,6 +164,7 @@ declare global { ) => Promise setTheme: (themeClass: string) => void isSteamDeckGameMode: boolean + platform: NodeJS.Platform } interface WindowEventMap { From 8a1bfdaa3cb705e8c240aa089fdd07306d894604 Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 15:45:00 -0300 Subject: [PATCH 7/8] Revert change to fix specs --- src/backend/main_window.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/main_window.ts b/src/backend/main_window.ts index 2be982ec81..dc7b98b365 100644 --- a/src/backend/main_window.ts +++ b/src/backend/main_window.ts @@ -1,7 +1,7 @@ import { AppSettings, WindowProps } from 'common/types' import { BrowserWindow, screen } from 'electron' import path from 'path' -import { configStore, isLinux } from './constants' +import { configStore } from './constants' let mainWindow: BrowserWindow | null = null @@ -61,11 +61,11 @@ export const createMainWindow = () => { const settings = configStore.get('settings', {}) if (settings?.framelessWindow) { // use native overlay controls where supported - if (isLinux) { - windowProps.frame = false - } else { + if (['darwin', 'win32'].includes(process.platform)) { windowProps.titleBarStyle = 'hidden' windowProps.titleBarOverlay = true + } else { + windowProps.frame = false } } From 5723db41542763ff000eb4c95b4cae0124e131ab Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Sun, 28 Jan 2024 15:52:03 -0300 Subject: [PATCH 8/8] Cleanup reading settings --- src/backend/config.ts | 7 ------- src/backend/main.ts | 16 ++++------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/backend/config.ts b/src/backend/config.ts index d5375a74a1..a1a1907827 100644 --- a/src/backend/config.ts +++ b/src/backend/config.ts @@ -275,13 +275,6 @@ class GlobalConfigV0 extends GlobalConfig { winePrefix } as AppSettings - // TODO: Remove this after a couple of stable releases - // Get settings only from config-store - const currentConfigStore = configStore.get_nodefault('settings') - if (!currentConfigStore?.defaultInstallPath) { - configStore.set('settings', settings) - } - return settings } diff --git a/src/backend/main.ts b/src/backend/main.ts index ef1903abb9..002654d62c 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -338,15 +338,6 @@ if (!gotTheLock) { app.setAppUserModelId('Heroic Games Launcher') } - // TODO: Remove this after a couple of stable releases - // Affects only current users, not new installs - const settings = GlobalConfig.get().getSettings() - const { language } = settings - const currentConfigStore = configStore.get_nodefault('settings') - if (!currentConfigStore?.defaultInstallPath) { - configStore.set('settings', settings) - } - runOnceWhenOnline(async () => { const isLoggedIn = LegendaryUser.isLoggedIn() @@ -364,6 +355,8 @@ if (!gotTheLock) { } }) + const settings = GlobalConfig.get().getSettings() + // Make sure lock is not present when starting up playtimeSyncQueue.delete('lock') if (!settings.disablePlaytimeSync) { @@ -383,7 +376,7 @@ if (!gotTheLock) { returnEmptyString: false, returnNull: false, fallbackLng: 'en', - lng: language, + lng: settings.language, supportedLngs: [ 'ar', 'az', @@ -445,8 +438,7 @@ if (!gotTheLock) { logWarning('Protocol already registered.', LogPrefix.Backend) } - const { startInTray } = GlobalConfig.get().getSettings() - const headless = isCLINoGui || startInTray + const headless = isCLINoGui || settings.startInTray if (!headless) { mainWindow.once('ready-to-show', () => { const props = configStore.get_nodefault('window-props')