Skip to content

Commit

Permalink
[Tech] Add ts-prune to find dead code (#2210)
Browse files Browse the repository at this point in the history
* [i18n] Updated Translations (#2076)

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Translated using Weblate (French)

Currently translated at 100.0% (401 of 401 strings)

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Co-authored-by: John Donne <akheron@zaclys.net>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/globals/fr/
Translation: Heroic Games Launcher/GamePage
Translation: Heroic Games Launcher/Globals

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Heroic Games Launcher/Globals
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/globals/

Co-authored-by: John Donne <akheron@zaclys.net>

* [Fix] Beta 3 Fixes + some small improvements (#2079)

* fix: hide wine options on macOS

* fix: playing status not changing correctly

* fix: download progress color

* fix: wine-manager reload button

* fix: launch win sideloaded games on macOS

* fix: isGameAvailable for sideloaded games

* fix: dont show wine tools on windows and mac

* feat: game not available status

* feat: improved not available check on game page

* i18n: updated keys

* fix: dont show update button when not available

* fix: gamecard not available classes

* fix: getInstallInfo error when json parse fails

* other: fade in card animation

* chore: heroic version hover

* fix: reload gamecard on status changes

* fix: proper pass platform when importing epic games

* i18n: updated keys

* fix: compute saves path for windows games on macOS

* fix: gamecard status not updating after import

* feat: proper show not supported games

* fix: codecheck

* fix: Hiding a game doesn't remove it from the list unless re-rendered #2078

* fix: showing as not available after uninstall

* fix: typo

* fix: hide runexe for native games on sideload

* fix: hide wine options for native games

* fix: show refreshing icon when refreshing library

* fix: pr comments

* chore: renamed import

* fix: remove install info for unsuported games

* fix: dont fetch changelog if already saw it

* fix: installing native macOS games for GOG

* chore: removed audioFix settings and component

* [Revert] Revert #2075 (#2090)

* chore: updated version

* chore: readme update

* fix: GameList Header columns

* fix: uninstalled status on game list

* fix: platform filter on macOS

* chore: accurate macOS info

* fix: gog error message when apiData is null

* [Other] Update icons with better quality ones  (#2096)

* other: updated tray icons and added OS logic

* chore: log

* [i18n] Updated Translations (#2088)

* Translated using Weblate (Swedish)

Currently translated at 100.0% (402 of 402 strings)

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Co-authored-by: dpanter <dpanter@donottrackplus.net>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/globals/sv/
Translation: Heroic Games Launcher/GamePage
Translation: Heroic Games Launcher/Globals

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <hosted@weblate.org>
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/gamepage/
Translation: Heroic Games Launcher/GamePage

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Heroic Games Launcher/Globals
Translate-URL: https://hosted.weblate.org/projects/heroic-games-launcher/globals/

Co-authored-by: dpanter <dpanter@donottrackplus.net>

* [Feature/Wine] Add DXVK Framerate Limit Toggle (#2068)

* [Feature] Add DXVK FPS Limit toggle

Checkbox to enable/disable DXVK FPS and a text field to input enter FPS cap value

* Run prettier

* Fix function not used error

* Show for macOS Crossover and Linux Wine games

* Add !nativeGame

* Add ts-prune

* yarn i18n

* Merge clean up

* Remove clearFinished

* Merge fixes

* yarn i18n

* Review suggestions

* Only uncomment moveInstall

* Debug workflow

* Remove debug

* Debug workflow

* Remove debug

* Dont export ProtonVerb

* prettier-fix

* Remove moveInstall for sideload apps

* Add find-deadcode to linter workflow

* review fixes

Co-authored-by: Weblate (bot) <hosted@weblate.org>
Co-authored-by: John Donne <akheron@zaclys.net>
Co-authored-by: Flávio F Lima <flavioislima@gmail.com>
Co-authored-by: dpanter <dpanter@donottrackplus.net>
Co-authored-by: Rishabh Moharir <74495920+redromnon@users.noreply.github.com>
  • Loading branch information
6 people authored Jan 23, 2023
1 parent cdcd16f commit a5db684
Show file tree
Hide file tree
Showing 42 changed files with 336 additions and 394 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
run: yarn lint
- name: Prettier code.
run: yarn prettier
- name: Find dead code
run: yarn find-deadcode
3 changes: 3 additions & 0 deletions .ts-prunerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore": "src/common/typedefs"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@
"source-map-support": "^0.5.21",
"steam-shortcut-editor": "^3.1.1",
"systeminformation": "^5.15.0",
"ts-prune": "^0.10.3",
"tslib": "^2.4.0"
},
"scripts": {
"start": "vite",
"codecheck": "tsc --noEmit",
"find-deadcode": "ts-prune --error",
"test": "jest",
"test-watch": "jest --watch --maxWorkers=25%",
"test:ci": "jest --runInBand --silent",
Expand Down
1 change: 1 addition & 0 deletions src/backend/__mocks__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ constants.configStore = {

constants.currentLogFile = 'current.log'
constants.lastLogFile = 'last.log'
constants.isSteamDeckGameMode = false

module.exports = constants
export {}
3 changes: 2 additions & 1 deletion src/backend/__mocks__/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const app = {
// app override
getPath: jest.fn().mockImplementation((path: string) => {
return join(appBasePath, path)
})
}),
getVersion: jest.fn()
}

class Notification {
Expand Down
6 changes: 5 additions & 1 deletion src/backend/__mocks__/i18next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ const t = (key: string) => {
return key
}

export default { t }
const i18next = {
t: t
}

export { i18next as default, t }
6 changes: 0 additions & 6 deletions src/backend/__mocks__/utils.ts

This file was deleted.

40 changes: 29 additions & 11 deletions src/backend/__tests__/constants.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixAsarPath, getShell } from '../constants'
import { fixAsarPath } from '../constants'

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

Expand Down Expand Up @@ -26,34 +26,52 @@ describe('Constants - getShell', () => {
return original_os
}

test('get enviroment SHELL for unix os', () => {
async function getShell(): Promise<string> {
jest.resetModules()
return await import('../constants').then((module) => {
return module.execOptions.shell
})
}

test('get shell for linux', async () => {
// override platform
const originalPlatform = overrideProcessPlatform('linux')

const shell = getShell()
const shell = await getShell()
expect(shell).toBe('/bin/bash')

// get back to original platform
overrideProcessPlatform(originalPlatform)
})

test('get default shell for unix os', () => {
test('get shell for windows', async () => {
// override platform
const originalPlatform = overrideProcessPlatform('linux')
const originalPlatform = overrideProcessPlatform('win32')

const shell = getShell()
expect(shell).toBe('/bin/bash')
const shell = await getShell()
expect(shell).toBe('powershell.exe')

// get back to original platform
overrideProcessPlatform(originalPlatform)
})

test('get powershell windows', () => {
test('get shell for mac', async () => {
// override platform
const originalPlatform = overrideProcessPlatform('win32')
const originalPlatform = overrideProcessPlatform('darwin')

const shell = getShell()
expect(shell).toBe('powershell.exe')
const shell = await getShell()
expect(shell).toBe('/bin/zsh')

// get back to original platform
overrideProcessPlatform(originalPlatform)
})

test('get default shell for unix os', async () => {
// override platform
const originalPlatform = overrideProcessPlatform('linux')

const shell = await getShell()
expect(shell).toBe('/bin/bash')

// get back to original platform
overrideProcessPlatform(originalPlatform)
Expand Down
9 changes: 1 addition & 8 deletions src/backend/__tests__/main_window.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
createMainWindow,
setMainWindow,
sendFrontendMessage
} from '../main_window'
import { createMainWindow, sendFrontendMessage } from '../main_window'
import { BrowserWindow, Display, screen } from 'electron'
import { configStore } from '../constants'

Expand All @@ -13,7 +9,6 @@ describe('main_window', () => {
describe('if no main window', () => {
beforeAll(() => {
BrowserWindow['setAllWindows']([])
setMainWindow(null)
})

it('returns false', () => {
Expand All @@ -30,7 +25,6 @@ describe('main_window', () => {

// stub windows
beforeAll(() => {
setMainWindow(null)
BrowserWindow['setAllWindows']([window])
})

Expand All @@ -41,7 +35,6 @@ describe('main_window', () => {

// cleanup stubs
afterAll(() => {
setMainWindow(null)
BrowserWindow['setAllWindows']([])
})

Expand Down
42 changes: 42 additions & 0 deletions src/backend/__tests__/test_data/github-api-heroic-test-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"test_data": {
"data": [
{
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.6.0-beta.1",
"id": 100,
"tag_name": "v2.6.0-beta.1",
"name": "2.6.0 Beta",
"prerelease": true,
"published_at": "2022-13-14T10:53:29Z",
"body": "2.6.0 Beta Release"
},
{
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.5.2",
"id": 200,
"tag_name": "v2.5.2",
"name": "2.5.2 HOTFIX #2",
"prerelease": false,
"published_at": "2022-12-14T10:53:29Z",
"body": "2.5.2 HOTFIX #2 Release"
},
{
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.5.0-beta.3",
"id": 300,
"tag_name": "v2.5.0-beta.3",
"name": "2.5.0 Beta",
"prerelease": true,
"published_at": "2022-11-14T10:53:29Z",
"body": "2.5.0 Beta Release"
},
{
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.5.0",
"id": 400,
"tag_name": "v2.5.0",
"name": "2.5.0",
"prerelease": false,
"published_at": "2022-10-14T10:53:29Z",
"body": "2.5.0 Release"
}
]
}
}
93 changes: 88 additions & 5 deletions src/backend/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { quoteIfNecessary, removeQuoteIfNecessary, semverGt } from '../utils'
import axios from 'axios'
import { app } from 'electron'
import { logError } from '../logger/logger'
import * as utils from '../utils'
import { test_data } from './test_data/github-api-heroic-test-data.json'

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

describe('electron/utils.ts', () => {
describe('backend/utils.ts', () => {
test('quoteIfNeccessary', () => {
const testCases = new Map<string, string>([
['path/without/spaces', 'path/without/spaces'],
Expand All @@ -13,7 +19,7 @@ describe('electron/utils.ts', () => {
])

testCases.forEach((expectString, inputString) => {
expect(quoteIfNecessary(inputString)).toStrictEqual(expectString)
expect(utils.quoteIfNecessary(inputString)).toStrictEqual(expectString)
})
})

Expand All @@ -24,7 +30,9 @@ describe('electron/utils.ts', () => {
])

testCases.forEach((expectString, inputString) => {
expect(removeQuoteIfNecessary(inputString)).toStrictEqual(expectString)
expect(utils.removeQuoteIfNecessary(inputString)).toStrictEqual(
expectString
)
})
})

Expand All @@ -45,7 +53,82 @@ describe('electron/utils.ts', () => {
])

testCases.forEach((expectValue, versions) => {
expect(semverGt(versions.target, versions.base)).toBe(expectValue)
expect(
utils.testingExportsUtils.semverGt(versions.target, versions.base)
).toBe(expectValue)
})
})

describe('getLatestReleases', () => {
test('Simple version', async () => {
jest.spyOn(axios, 'get').mockResolvedValue(test_data)
jest.spyOn(app, 'getVersion').mockReturnValueOnce('2.4.0')

const releases = await utils.getLatestReleases()
expect(releases).toMatchInlineSnapshot(`
Array [
Object {
"body": "2.5.2 HOTFIX #2 Release",
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.5.2",
"id": 200,
"name": "2.5.2 HOTFIX #2",
"prerelease": false,
"published_at": "2022-12-14T10:53:29Z",
"tag_name": "v2.5.2",
"type": "stable",
},
Object {
"body": "2.6.0 Beta Release",
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.6.0-beta.1",
"id": 100,
"name": "2.6.0 Beta",
"prerelease": true,
"published_at": "2022-13-14T10:53:29Z",
"tag_name": "v2.6.0-beta.1",
"type": "beta",
},
]
`)
})

test('Complex version', async () => {
jest.spyOn(axios, 'get').mockResolvedValue(test_data)
jest.spyOn(app, 'getVersion').mockReturnValueOnce('2.5.5-beta.3')

const releases = await utils.getLatestReleases()
expect(releases).toMatchInlineSnapshot(`
Array [
Object {
"body": "2.6.0 Beta Release",
"html_url": "https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/releases/tag/v2.6.0-beta.1",
"id": 100,
"name": "2.6.0 Beta",
"prerelease": true,
"published_at": "2022-13-14T10:53:29Z",
"tag_name": "v2.6.0-beta.1",
"type": "beta",
},
]
`)
})

test('Empty version', async () => {
jest.spyOn(axios, 'get').mockResolvedValue(test_data)
jest.spyOn(app, 'getVersion').mockReturnValueOnce('')

const releases = await utils.getLatestReleases()
expect(releases).toMatchInlineSnapshot(`Array []`)
})

test('Fetching available releases fails', async () => {
jest.spyOn(axios, 'get').mockRejectedValue('Failed to fetch!')

const releases = await utils.getLatestReleases()
expect(logError).toBeCalledWith(
['Error when checking for Heroic updates', 'Failed to fetch!'],
'Backend'
)
expect(releases).toMatchInlineSnapshot(`Array []`)
})
})
})
2 changes: 0 additions & 2 deletions src/backend/api/downloadmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export const getDMQueueInformation = async () =>
export const removeFromDMQueue = (appName: string) =>
ipcRenderer.send('removeFromDMQueue', appName)

export const clearDMFinished = () => ipcRenderer.send('clearDMFinished')

export const handleDMQueueInformation = (
onChange: (e: Electron.IpcRendererEvent, elements: DMQueueElement[]) => void
) => {
Expand Down
5 changes: 0 additions & 5 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const installed = join(legendaryConfigPath, 'installed.json')
const legendaryMetadata = join(legendaryConfigPath, 'metadata')
const fallBackImage = 'fallback'
const epicLoginUrl = 'https://legendary.gl/epiclogin'
const gogLoginUrl =
'https://auth.gog.com/auth?client_id=46899977096215655&redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&response_type=code&layout=galaxy'
const sidInfoUrl =
'https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher/wiki/How-To:-Epic-Alternative-Login'
const heroicGithubURL =
Expand Down Expand Up @@ -186,10 +184,8 @@ export {
discordLink,
execOptions,
fixAsarPath,
getShell,
configStore,
heroicConfigPath,
heroicFolder,
heroicGamesConfigPath,
heroicGithubURL,
heroicIconFolder,
Expand All @@ -212,7 +208,6 @@ export {
legendaryConfigPath,
legendaryMetadata,
epicLoginUrl,
gogLoginUrl,
patreonPage,
sidInfoUrl,
supportURL,
Expand Down
1 change: 1 addition & 0 deletions src/backend/dialog/__mocks__/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const dialog = jest.requireActual('../dialog')

dialog.showDialogBoxModalAuto = jest.fn()
dialog.notify = jest.fn()

module.exports = dialog
export {}
Loading

0 comments on commit a5db684

Please sign in to comment.