fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
e1bb94c
2.4.0
1import { 2CloudDownload , 3ContentCopy , 4Settings as SettingsIcon , 5} from '@mui/icons-material' ; 6import { 7Alert , 8Button , 9CircularProgress , 10Dialog , 11DialogContent , 12DialogContentText , 13DialogTitle , 14Fab , 15FormControl , 16FormControlLabel , 17FormLabel , 18InputLabel , 19Link , 20MenuItem , 21Radio , 22RadioGroup , 23Select , 24Stack , 25TextField , 26Tooltip , 27Typography , 28} from '@mui/material' ; 29import { ChangeEvent , useEffect , useMemo , useState } from 'react' ; 30import { lt , valid } from 'semver' ; 31import LabeledCheckbox from './LabeledCheckbox' ; 32import { 33AdminedTournament , 34CopyHostFormat , 35EnforcerSetting , 36Mode , 37} from '../common/types' ; 38 39function LabeledRadioButton ({ label, value} :{ label :string ; value :Mode }) { 40return ( 41< FormControlLabel 42disableTypography 43label = { label } 44labelPlacement = "end" 45value = { value } 46control = {< Radio />} 47sx = {{ typography :'caption' }} 48/> 49); 50} 51 52export default function Settings ({ 53 appVersion, 54 latestAppVersion, 55 mode, 56 setMode, 57 enforcerSetting, 58 setEnforcerSetting, 59 vlerkMode, 60 setVlerkMode, 61 guidedMode, 62 setGuidedMode, 63 smuggleCostumeIndex, 64 setSmuggleCostumeIndex, 65 useLAN, 66 setUseLAN, 67 fileNameFormat, 68 setFileNameFormat, 69 folderNameFormat, 70 setFolderNameFormat, 71 hideCopyButton, 72 setHideCopyButton, 73 setAdminedTournaments, 74 showErrorDialog, 75 enforcerVersion, 76 hostFormat, 77} :{ 78appVersion :string ; 79latestAppVersion :string ; 80mode :Mode ; 81setMode :( mode :Mode ) => void ; 82enforcerSetting :EnforcerSetting ; 83setEnforcerSetting :( enforcerSetting :EnforcerSetting ) => void ; 84vlerkMode :boolean ; 85setVlerkMode :( vlerkMode :boolean ) => void ; 86guidedMode :boolean ; 87setGuidedMode :( guidedMode :boolean ) => void ; 88smuggleCostumeIndex :boolean ; 89setSmuggleCostumeIndex :( smuggleCostumeIndex :boolean ) => void ; 90useLAN :boolean ; 91setUseLAN :( useLAN :boolean ) => void ; 92fileNameFormat :string ; 93setFileNameFormat :( fileNameFormat :string ) => void ; 94folderNameFormat :string ; 95setFolderNameFormat :( folderNameFormat :string ) => void ; 96hideCopyButton :boolean ; 97setHideCopyButton :( hideCopyButton :boolean ) => void ; 98setAdminedTournaments :( tournaments :AdminedTournament []) => void ; 99showErrorDialog :( errors :string []) => void ; 100enforcerVersion :string ; 101hostFormat :CopyHostFormat ; 102}) { 103const [ gotSettings , setGotSettings ] = useState ( false ); 104const [ startggApiKey , setStartggApiKey ] = useState ( '' ); 105const [ challongeApiKey , setChallongeApiKey ] = useState ( '' ); 106const [ parryggApiKey , setParryggApiKey ] = useState ( '' ); 107useEffect (() => { 108( async () => { 109const startggKeyPromise = window . electron . getStartggKey (); 110const challongeKeyPromise = window . electron . getChallongeKey (); 111const parryggKeyPromise = window . electron . getParryggKey (); 112setStartggApiKey ( await startggKeyPromise ); 113setChallongeApiKey ( await challongeKeyPromise ); 114setParryggApiKey ( await parryggKeyPromise ); 115setGotSettings ( true ); 116})(); 117}, []); 118 119const [ open , setOpen ] = useState ( false ); 120const [ copied , setCopied ] = useState ( false ); 121const [ hasAutoOpened , setHasAutoOpened ] = useState ( false ); 122const [ shouldGetTournaments , setShouldGetTournaments ] = useState ( false ); 123 124const needUpdate = useMemo ( 125() => 126valid ( appVersion ) && 127valid ( latestAppVersion ) && 128lt ( appVersion , latestAppVersion ), 129[ appVersion , latestAppVersion ], 130); 131if ( 132gotSettings && 133! hasAutoOpened && 134(( mode === Mode . STARTGG && ! startggApiKey ) || 135( mode === Mode . CHALLONGE && ! challongeApiKey ) || 136( mode === Mode . PARRYGG && ! parryggApiKey ) || 137needUpdate ) 138) { 139setOpen ( true ); 140setHasAutoOpened ( true ); 141} 142 143const [ trashDir , setTrashDir ] = useState ( '' ); 144useEffect (() => { 145( async () => { 146const trashDirPromise = window . electron . getTrashDir (); 147setTrashDir ( await trashDirPromise ); 148})(); 149}, []); 150 151const [ choosingTrashDir , setChoosingTrashDir ] = useState ( false ); 152 153return ( 154<> 155< Tooltip arrow title = "Settings" > 156< Fab 157onClick = {() => setOpen ( true )} 158size = "small" 159style = {{ position :'absolute' , bottom :8 , left :8 }} 160sx = {{ 161zIndex :( theme ) => theme . zIndex . modal + 1 , 162}} 163> 164< SettingsIcon /> 165</ Fab > 166</ Tooltip > 167< Dialog 168fullWidth 169open = { open } 170onClose = { async () => { 171try { 172await Promise . all ([ 173window . electron . setChallongeKey ( challongeApiKey ), 174window . electron . setStartggKey ( startggApiKey ), 175window . electron . setParryggKey ( parryggApiKey ), 176window . electron . setFileNameFormat ( fileNameFormat ), 177window . electron . setFolderNameFormat ( folderNameFormat ), 178]); 179} catch ( e :any ) { 180showErrorDialog ([ e instanceof Error ?e . message :e ]); 181} 182if ( shouldGetTournaments ) { 183if ( 184( mode === Mode . STARTGG && startggApiKey ) || 185( mode === Mode . CHALLONGE && challongeApiKey ) || 186( mode === Mode . PARRYGG && parryggApiKey ) 187) { 188try { 189setAdminedTournaments ( await window . electron . getTournaments ()); 190} catch ( e :any ) { 191showErrorDialog ([ e instanceof Error ?e . message :e ]); 192} finally { 193setShouldGetTournaments ( false ); 194} 195} else { 196setAdminedTournaments ([]); 197setShouldGetTournaments ( false ); 198} 199} 200setOpen ( false ); 201}} 202> 203< Stack 204alignItems = "center" 205direction = "row" 206justifyContent = "space-between" 207marginRight = "24px" 208> 209< DialogTitle > Settings </ DialogTitle > 210< Typography variant = "caption" > 211Replay Reporter for Slippi version { appVersion } 212</ Typography > 213</ Stack > 214< DialogContent sx = {{ pt :0 }}> 215< Stack > 216< FormControl > 217< FormLabel id = "mode-radio-group-label" > Mode </ FormLabel > 218< RadioGroup 219aria-labelledby = "mode-radio-group-label" 220name = "mode-radio-group" 221row 222value = { mode } 223onChange = { async ( event :ChangeEvent < HTMLInputElement >) => { 224const newMode = event . target . value as Mode ; 225await window . electron . setMode ( newMode ); 226setMode ( newMode ); 227setShouldGetTournaments ( true ); 228}} 229> 230< LabeledRadioButton label = "start.gg" value = { Mode . STARTGG } /> 231< LabeledRadioButton label = "Challonge" value = { Mode . CHALLONGE } /> 232< LabeledRadioButton label = "parry.gg" value = { Mode . PARRYGG } /> 233< LabeledRadioButton 234label = "Offline Mode" 235value = { Mode . OFFLINE_MODE } 236/> 237< LabeledRadioButton label = "Manual" value = { Mode . MANUAL } /> 238</ RadioGroup > 239</ FormControl > 240</ Stack > 241{ mode === Mode . STARTGG && ( 242<> 243< DialogContentText > 244Get your start.gg API key by clicking “Create new token” in the 245< br /> 246“Personal Access Tokens” tab of { ' ' } 247< Link 248href = "https://start.gg/admin/profile/developer" 249target = "_blank" 250rel = "noreferrer" 251> 252this page 253</ Link > 254. Keep it private! 255</ DialogContentText > 256< Stack alignItems = "center" direction = "row" gap = "8px" > 257< TextField 258fullWidth 259label = "start.gg API key (Keep it private!)" 260onChange = {( event ) => { 261setStartggApiKey ( event . target . value ); 262setShouldGetTournaments ( true ); 263}} 264size = "small" 265type = "password" 266value = { startggApiKey } 267variant = "standard" 268/> 269< Button 270disabled = { copied } 271endIcon = { copied ?undefined :< ContentCopy />} 272onClick = { async () => { 273await window . electron . copyToClipboard ( startggApiKey ); 274setCopied ( true ); 275setTimeout (() => setCopied ( false ), 5000 ); 276}} 277variant = "contained" 278> 279{ copied ?'Copied!' :'Copy' } 280</ Button > 281</ Stack > 282</> 283)} 284{ mode === Mode . CHALLONGE && ( 285<> 286< DialogContentText > 287Get your Challonge v1 API key on { ' ' } 288< Link 289href = "https://challonge.com/settings/developer" 290target = "_blank" 291rel = "noreferrer" 292> 293this page 294</ Link >{ ' ' } 295(you may need to click “Generate a new API key”). Keep it 296private! 297</ DialogContentText > 298< Stack alignItems = "center" direction = "row" gap = "8px" > 299< TextField 300fullWidth 301label = "Challonge v1 API key (Keep it private!)" 302onChange = {( event ) => { 303setChallongeApiKey ( event . target . value ); 304setShouldGetTournaments ( true ); 305}} 306size = "small" 307type = "password" 308value = { challongeApiKey } 309variant = "standard" 310/> 311< Button 312disabled = { copied } 313endIcon = { copied ?undefined :< ContentCopy />} 314onClick = { async () => { 315await window . electron . copyToClipboard ( challongeApiKey ); 316setCopied ( true ); 317setTimeout (() => setCopied ( false ), 5000 ); 318}} 319variant = "contained" 320> 321{ copied ?'Copied!' :'Copy' } 322</ Button > 323</ Stack > 324</> 325)} 326{ mode === Mode . PARRYGG && ( 327<> 328< DialogContentText > 329Get your parry.gg API key from { ' ' } 330< Link href = "https://parry.gg" target = "_blank" rel = "noreferrer" > 331parry.gg 332</ Link > 333. Keep it private! 334</ DialogContentText > 335< Stack alignItems = "center" direction = "row" gap = "8px" > 336< TextField 337fullWidth 338label = "parry.gg API key (Keep it private!)" 339onChange = {( event ) => { 340setParryggApiKey ( event . target . value ); 341setShouldGetTournaments ( true ); 342}} 343size = "small" 344type = "password" 345value = { parryggApiKey } 346variant = "standard" 347/> 348< Button 349disabled = { copied } 350endIcon = { copied ?undefined :< ContentCopy />} 351onClick = { async () => { 352await window . electron . copyToClipboard ( parryggApiKey ); 353setCopied ( true ); 354setTimeout (() => setCopied ( false ), 5000 ); 355}} 356variant = "contained" 357> 358{ copied ?'Copied!' :'Copy' } 359</ Button > 360</ Stack > 361</> 362)} 363< Stack > 364< LabeledCheckbox 365checked = { guidedMode } 366label = "Use walkthrough mode" 367labelPlacement = "end" 368set = { async ( checked ) => { 369await window . electron . setGuidedMode ( checked ); 370setGuidedMode ( checked ); 371}} 372/> 373< Stack 374direction = "row" 375justifyContent = "space-between" 376alignItems = "center" 377> 378< LabeledCheckbox 379checked = { trashDir . length > 0 } 380disabled = { ! trashDir } 381label = { 382trashDir 383 ?'Using trash folder:' 384 :'Deleting replays permanently' 385} 386labelPlacement = "end" 387set = { async ( checked ) => { 388if ( ! checked ) { 389await window . electron . clearTrashDir (); 390setTrashDir ( '' ); 391} 392}} 393style = {{ flexShrink :0 }} 394/> 395{ trashDir ?( 396< Typography 397overflow = "hidden" 398textAlign = "left" 399textOverflow = "ellipsis" 400style = {{ direction :'rtl' , opacity :'0.5' }} 401variant = "caption" 402whiteSpace = "nowrap" 403> 404{ trashDir } 405</ Typography > 406) :( 407< Button 408disabled = { choosingTrashDir } 409endIcon = { 410choosingTrashDir ?( 411< CircularProgress size = "24px" /> 412) :undefined 413} 414onClick = { async () => { 415setChoosingTrashDir ( true ); 416try { 417setTrashDir ( await window . electron . chooseTrashDir ()); 418} catch { 419// just catch 420} finally { 421setChoosingTrashDir ( false ); 422} 423}} 424variant = "contained" 425> 426Set trash folder 427</ Button > 428)} 429</ Stack > 430< LabeledCheckbox 431checked = { vlerkMode } 432label = { 433< span > 434Use "Vlerk mode "for post tournament supplemental 435reporting, { ' ' } 436< Link 437href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/vlerk.md` } 438target = "_blank" 439rel = "noreferrer" 440> 441see more details 442</ Link > 443</ span > 444} 445labelPlacement = "end" 446set = { async ( checked ) => { 447await window . electron . setVlerkMode ( checked ); 448setVlerkMode ( checked ); 449}} 450/> 451< LabeledCheckbox 452checked = { useLAN } 453label = "Use LAN" 454labelPlacement = "end" 455set = { async ( checked ) => { 456await window . electron . setUseLAN ( checked ); 457setUseLAN ( checked ); 458}} 459/> 460{( mode === Mode . STARTGG || mode === Mode . OFFLINE_MODE ) && ( 461< LabeledCheckbox 462disabled = { hostFormat . smuggleCostumeIndex !== undefined } 463checked = { smuggleCostumeIndex } 464label = { 465< span > 466Report character color, { ' ' } 467< Link 468href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/color.md` } 469target = "_blank" 470rel = "noreferrer" 471> 472see more details 473</ Link > 474</ span > 475} 476labelPlacement = "end" 477set = { async ( checked ) => { 478await window . electron . setSmuggleCostumeIndex ( checked ); 479setSmuggleCostumeIndex ( checked ); 480}} 481/> 482)} 483< LabeledCheckbox 484checked = { hideCopyButton } 485label = "Hide Copy Button" 486labelPlacement = "end" 487set = { async ( checked ) => { 488await window . electron . setHideCopyButton ( checked ); 489setHideCopyButton ( checked ); 490}} 491/> 492< FormControl variant = "standard" style = {{ marginBottom :'8px' }}> 493< InputLabel id = "enforcer-setting-select-label" > 494SLP Enforcer { enforcerVersion } (logged to copy folder 495enforcer.csv) 496</ InputLabel > 497< Select 498labelId = "enforcer-setting-select-label" 499disabled = { hostFormat . enforcerSetting !== undefined } 500value = { enforcerSetting } 501onChange = { async ( event ) => { 502const newEnforcerSetting = event . target 503. value as EnforcerSetting ; 504await window . electron . setEnforcerSetting ( newEnforcerSetting ); 505setEnforcerSetting ( newEnforcerSetting ); 506}} 507> 508< MenuItem value = { EnforcerSetting . NONE }> Off </ MenuItem > 509< MenuItem value = { EnforcerSetting . LOG_ONLY }> Log Only </ MenuItem > 510< MenuItem value = { EnforcerSetting . POP_UP_GOOMWAVE }> 511Alert on Goomwave 512</ MenuItem > 513< MenuItem value = { EnforcerSetting . POP_UP_ALL }> 514Alert on All Violations 515</ MenuItem > 516</ Select > 517</ FormControl > 518< DialogContentText > 519File/Folder name format placeholders documented { ' ' } 520< Link 521href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/format.md` } 522target = "_blank" 523rel = "noreferrer" 524> 525here 526</ Link > 527. 528</ DialogContentText > 529< Stack alignItems = "end" direction = "row" gap = "8px" > 530< TextField 531fullWidth 532disabled = { Boolean ( hostFormat . fileNameFormat )} 533label = "File name format" 534onChange = {( event ) => { 535const newFileNameFormat = event . target . value ; 536if ( newFileNameFormat ) { 537setFileNameFormat ( newFileNameFormat . slice ( 9 )); 538} 539}} 540size = "small" 541value = { `{ordinal} ${ fileNameFormat } ` } 542variant = "standard" 543/> 544< DialogContentText paddingBottom = "5px" > .slp </ DialogContentText > 545< Button 546disabled = { Boolean ( hostFormat . fileNameFormat )} 547onClick = { async () => { 548setFileNameFormat ( 549await window . electron . resetFileNameFormat (), 550); 551}} 552variant = "contained" 553> 554Reset 555</ Button > 556</ Stack > 557< Stack alignItems = "end" direction = "row" gap = "8px" > 558< TextField 559fullWidth 560disabled = { Boolean ( hostFormat . folderNameFormat )} 561label = "Folder name format" 562onChange = {( event ) => { 563const newFolderNameFormat = event . target . value ; 564if ( newFolderNameFormat ) { 565setFolderNameFormat ( newFolderNameFormat ); 566} 567}} 568size = "small" 569value = { folderNameFormat } 570variant = "standard" 571/> 572< Button 573disabled = { Boolean ( hostFormat . folderNameFormat )} 574onClick = { async () => { 575setFolderNameFormat ( 576await window . electron . resetFolderNameFormat (), 577); 578}} 579variant = "contained" 580> 581Reset 582</ Button > 583</ Stack > 584</ Stack > 585{ needUpdate && ( 586< Alert 587severity = "warning" 588style = {{ marginTop :'8px' }} 589action = { 590< Button 591endIcon = {< CloudDownload />} 592variant = "contained" 593onClick = {() => { 594window . electron . update (); 595}} 596> 597Quit and download 598</ Button > 599} 600> 601Update available! Version { latestAppVersion } 602</ Alert > 603)} 604</ DialogContent > 605</ Dialog > 606</> 607); 608}