Skip to content

[Feature] Add ExperimentalFeatures feature with dummy example #2881

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

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@
},
"esync": "Enable Esync",
"exit-to-tray": "Exit to System Tray",
"experimental_features": {
"enableNewShinyFeature": "New shiny feature"
},
"FsrSharpnessStrenght": "FSR Sharpness Strength",
"fsync": "Enable Fsync",
"gamemode": "Use GameMode (Feral Game Mode needs to be installed)",
Expand Down Expand Up @@ -598,6 +601,9 @@
"installing": "Installing EAC Runtime...",
"name": "EasyAntiCheat Runtime"
},
"experimental_features": {
"title": "Experimental Features"
},
"gameMode": {
"eacRuntimeEnabled": {
"message": "The EAC runtime is enabled, which won't function correctly without GameMode. Do you want to disable the EAC Runtime and GameMode?",
Expand Down
5 changes: 5 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export type Release = {
body?: string
}

export type ExperimentalFeatures = {
enableNewShinyFeature: boolean
}

export interface AppSettings extends GameSettings {
addDesktopShortcuts: boolean
addStartMenuShortcuts: boolean
Expand All @@ -66,6 +70,7 @@ export interface AppSettings extends GameSettings {
egsLinkedPath: string
enableUpdates: boolean
exitToTray: boolean
experimentalFeatures: ExperimentalFeatures
hideChangelogsOnStartup: boolean
libraryTopSection: LibraryTopSectionOptions
maxRecentGames: number
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/components/UI/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react'
import React, { useContext, useEffect, useRef, useState } from 'react'

import CurrentDownload from './components/CurrentDownload'
import SidebarLinks from './components/SidebarLinks'
Expand All @@ -8,6 +8,7 @@ import { DMQueueElement } from 'common/types'

import { ReactComponent as HeroicIcon } from 'frontend/assets/heroic-icon.svg'
import { useNavigate } from 'react-router-dom'
import ContextProvider from 'frontend/state/ContextProvider'

let sidebarSize = localStorage.getItem('sidebar-width') || 240
const minWidth = 60
Expand All @@ -17,6 +18,7 @@ const collapsedWidth = 120
export default React.memo(function Sidebar() {
const sidebarEl = useRef<HTMLDivElement | null>(null)
const [currentDMElement, setCurrentDMElement] = useState<DMQueueElement>()
const { experimentalFeatures } = useContext(ContextProvider)

const navigate = useNavigate()

Expand Down Expand Up @@ -144,6 +146,9 @@ export default React.memo(function Sidebar() {
)}
</div>
<HeroicVersion />
{experimentalFeatures.enableNewShinyFeature && (
<p>New Shiny Feature enabled</p>
)}
<div className="resizer" onMouseDown={handleDragStart} />
</aside>
)
Expand Down
54 changes: 54 additions & 0 deletions src/frontend/screens/Settings/components/ExperimentalFeatures.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useContext, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import useSetting from 'frontend/hooks/useSetting'
import { ToggleSwitch } from 'frontend/components/UI'
import ContextProvider from 'frontend/state/ContextProvider'

const FEATURES = ['enableNewShinyFeature']

const ExperimentalFeatures = () => {
const { t } = useTranslation()
const [experimentalFeatures, setExprimentalFeatures] = useSetting(
'experimentalFeatures',
{ enableNewShinyFeature: false }
)
const { handleExperimentalFeatures } = useContext(ContextProvider)

const toggleFeature = (feature: string) => {
setExprimentalFeatures({
...experimentalFeatures,
[feature]: !experimentalFeatures[feature]
})
}

useEffect(() => {
handleExperimentalFeatures(experimentalFeatures)
}, [experimentalFeatures])

/*
Translations:
t('setting.experimental_features.enableNewShinyFeature', 'New shiny feature')
*/

return (
<>
<h3>
{t('settings.experimental_features.title', 'Experimental Features')}
</h3>
{FEATURES.map((feature) => {
return (
<div key={feature}>
<ToggleSwitch
htmlId={feature}
value={experimentalFeatures[feature]}
handleChange={() => toggleFeature(feature)}
title={t(`setting.experimental_features.${feature}`, feature)}
/>
</div>
)
})}
</>
)
}

export default ExperimentalFeatures
1 change: 1 addition & 0 deletions src/frontend/screens/Settings/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { default as EnableEsync } from './EnableEsync'
export { default as EnableFSR } from './EnableFSR'
export { default as EnableFsync } from './EnableFsync'
export { default as EnvVariablesTable } from './EnvVariablesTable'
export { default as ExperimentalFeatures } from './ExperimentalFeatures'
export { default as GameMode } from './GameMode'
export { default as IgnoreGameUpdates } from './IgnoreGameUpdates'
export { default as HideChangelogOnStartup } from './HideChangelogOnStartup'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
AltLegendaryBin,
AltNileBin,
DisableLogs,
DownloadNoHTTPS
DownloadNoHTTPS,
ExperimentalFeatures
} from '../../components'

export default function AdvancedSettings() {
Expand Down Expand Up @@ -296,6 +297,8 @@ export default function AdvancedSettings() {
</div>
<br />
<hr />
<ExperimentalFeatures />
<hr />
</div>
<div className="footerFlex">
<button
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/state/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const initialContext: ContextType = {
lastChangelogShown: null,
setLastChangelogShown: () => null,
isSettingsModalOpen: { value: false, type: 'settings' },
setIsSettingsModalOpen: () => null
setIsSettingsModalOpen: () => null,
experimentalFeatures: { enableNewShinyFeature: false },
handleExperimentalFeatures: () => null
}

export default React.createContext(initialContext)
14 changes: 12 additions & 2 deletions src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
Runner,
WineVersionInfo,
InstallParams,
LibraryTopSectionOptions
LibraryTopSectionOptions,
ExperimentalFeatures
} from 'common/types'
import {
Category,
Expand Down Expand Up @@ -112,6 +113,7 @@ interface StateProps {
appName: string
runner: Runner
}
experimentalFeatures: ExperimentalFeatures
}

class GlobalState extends PureComponent<Props> {
Expand Down Expand Up @@ -195,7 +197,10 @@ class GlobalState extends PureComponent<Props> {
externalLinkDialogOptions: { showDialog: false },
hideChangelogsOnStartup: globalSettings?.hideChangelogsOnStartup || false,
lastChangelogShown: JSON.parse(storage.getItem('last_changelog') || 'null'),
settingsModalOpen: { value: false, type: 'settings', gameInfo: undefined }
settingsModalOpen: { value: false, type: 'settings', gameInfo: undefined },
experimentalFeatures: globalSettings?.experimentalFeatures || {
enableNewShinyFeature: false
}
}

setLanguage = (newLanguage: string) => {
Expand Down Expand Up @@ -344,6 +349,10 @@ class GlobalState extends PureComponent<Props> {
this.setState({ libraryTopSection: value })
}

handleExperimentalFeatures = (value: ExperimentalFeatures) => {
this.setState({ experimentalFeatures: value })
}

handleSuccessfulLogin = (runner: Runner) => {
this.handleCategory('all')
this.refreshLibrary({
Expand Down Expand Up @@ -889,6 +898,7 @@ class GlobalState extends PureComponent<Props> {
remove: this.removeGameFromFavourites
},
handleLibraryTopSection: this.handleLibraryTopSection,
handleExperimentalFeatures: this.handleExperimentalFeatures,
setTheme: this.setTheme,
setZoomPercent: this.setZoomPercent,
setAllTilesInColor: this.setAllTilesInColor,
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ButtonOptions,
LibraryTopSectionOptions,
DMQueueElement,
DownloadManagerState
DownloadManagerState,
ExperimentalFeatures
} from 'common/types'
import { NileLoginData, NileRegisterData } from 'common/types/nile'

Expand Down Expand Up @@ -104,6 +105,8 @@ export interface ContextType {
type?: 'settings' | 'log',
gameInfo?: GameInfo
) => void
experimentalFeatures: ExperimentalFeatures
handleExperimentalFeatures: (newSetting: ExperimentalFeatures) => void
}

export type DialogModalOptions = {
Expand Down