1- import { CheckBox , SimpleButton } from 'flashpoint-launcher-renderer-ext/components' ;
1+ import { DropdownStringRowProps } from 'flashpoint-launcher-renderer' ;
2+ import { CheckBox , Dropdown , DropdownStringRow , SimpleButton } from 'flashpoint-launcher-renderer-ext/components' ;
23import { useAppSelector } from 'flashpoint-launcher-renderer-ext/hooks' ;
34import { getExtensionFileURL , runCommand , setExtensionEnabled } from 'flashpoint-launcher-renderer-ext/utils' ;
45import { useEffect , useState } from 'react' ;
5- import { List , RowComponentProps , useDynamicRowHeight } from 'react-window' ;
66import { DownloadExtCommand , UninstallExtCommand } from '../commands' ;
77import { loadExtIndexUrl , ManagerExtensionInfo } from '../extensionLoader' ;
88
99export type ExtensionRowProps = {
10- items : ManagerExtensionInfo [ ] ;
11- disabledExtensions : string [ ] ;
10+ item : ManagerExtensionInfo ;
11+ index : number ;
12+ disabled : boolean ;
1213}
1314
1415export function ExtensionSubsection ( ) {
@@ -32,49 +33,59 @@ export function ExtensionSubsection() {
3233 description : ext . description || 'No Description' ,
3334 newestVersion : ext . version ,
3435 iconUrl : ext . icon ? getExtensionFileURL ( ext . id , ext . icon ) : undefined ,
35- installed : true
36+ installed : true ,
37+ availableVersions : [ ] ,
3638 } satisfies ManagerExtensionInfo ;
3739 } ) ;
40+
3841 for ( const ext of availableExtensions ) {
3942 const existingIdx = installedExtensions . findIndex ( e => e . id === ext . id ) ;
4043 if ( existingIdx === - 1 ) {
4144 extensionList . push ( ext ) ;
45+ } else {
46+ extensionList [ existingIdx ] . availableVersions = ext . availableVersions ;
4247 }
4348 }
4449
4550 extensionList . sort ( ( a , b ) => a . title . localeCompare ( b . title ) ) ;
4651
47- const rowHeight = useDynamicRowHeight ( {
48- defaultRowHeight : 24
49- } ) ;
50-
5152 return < div className = 'manager-page-subsection' >
5253 < div className = 'manager-page-subsection-header' > Extensions</ div >
53- { extensionList !== undefined ? (
54- < List < ExtensionRowProps >
55- className = 'simple-scroll'
56- rowComponent = { ExtensionRow }
57- rowCount = { extensionList . length }
58- rowProps = { {
59- items : extensionList ,
60- disabledExtensions,
61- } }
62- rowHeight = { rowHeight } />
63- ) : (
64- < div > Loading...</ div >
65- ) }
54+ < div className = 'manager-page-subsection-list simple-scroll' >
55+ { extensionList . length > 0 ? extensionList . map ( ( ext , index ) => {
56+ return (
57+ < ExtensionRow
58+ item = { ext }
59+ index = { index }
60+ disabled = { ! disabledExtensions . includes ( ext . id ) } />
61+ ) ;
62+ } ) : < div > Loading...</ div > }
63+ </ div >
6664 </ div > ;
6765}
6866
69- export function ExtensionRow ( { items, disabledExtensions, index, style } : RowComponentProps < ExtensionRowProps > ) {
70- const { id, title, description, installed, newestVersion, iconUrl, getDownloadUrl } = items [ index ] ;
67+ export function ExtensionRow ( { item, disabled, index } : ExtensionRowProps ) {
68+ const { id, title, description, installed, newestVersion, availableVersions, iconUrl, getDownloadUrl } = item ;
69+ const [ selectedVersion , setSelectedVersion ] = useState ( newestVersion ) ;
7170 const [ busy , setBusy ] = useState ( false ) ;
7271 const canInstall = getDownloadUrl !== undefined ;
73- const enabled = ! disabledExtensions . includes ( id ) ;
72+ const enabled = ! disabled ;
7473 let rowClassName = 'manager-extension-row' ;
7574 if ( index % 2 === 0 ) { rowClassName += ' manager-extension-row--even' ; }
7675
77- return < div className = { rowClassName } style = { style } >
76+ const versionSelector = (
77+ < Dropdown < DropdownStringRowProps >
78+ text = { `Ver: ${ selectedVersion } ` }
79+ rowCount = { availableVersions . length }
80+ rowProps = { {
81+ items : availableVersions ,
82+ onSelect : ( index ) => setSelectedVersion ( availableVersions [ index ] )
83+ } }
84+ rowRenderer = { DropdownStringRow }
85+ />
86+ ) ;
87+
88+ return < div className = { rowClassName } >
7889 < div className = 'manager-extension-row-icon' >
7990 { iconUrl && (
8091 < img src = { iconUrl } />
@@ -110,16 +121,19 @@ export function ExtensionRow({ items, disabledExtensions, index, style }: RowCom
110121 } } />
111122 ) }
112123 { canInstall && (
113- < SimpleButton value = { 'Install' } onClick = { ( ) => {
114- setBusy ( true ) ;
115- runCommand ( DownloadExtCommand , getDownloadUrl ( newestVersion ) )
116- . catch ( ( error ) => {
117- const errorString = `Failed to download and install extension: ${ error } ` ;
118- alert ( errorString ) ;
119- log . error ( 'Manager' , errorString ) ;
120- } )
121- . finally ( ( ) => setBusy ( false ) ) ;
122- } } />
124+ < >
125+ < SimpleButton value = { 'Install' } onClick = { ( ) => {
126+ setBusy ( true ) ;
127+ runCommand ( DownloadExtCommand , getDownloadUrl ( newestVersion ) )
128+ . catch ( ( error ) => {
129+ const errorString = `Failed to download and install extension: ${ error } ` ;
130+ alert ( errorString ) ;
131+ log . error ( 'Manager' , errorString ) ;
132+ } )
133+ . finally ( ( ) => setBusy ( false ) ) ;
134+ } } />
135+ { versionSelector }
136+ </ >
123137 ) }
124138 </ >
125139 ) : < div > Busy...</ div > }
0 commit comments