fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
c6a7fa9
2.3.7
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 }} 160> 161< SettingsIcon /> 162</ Fab > 163</ Tooltip > 164< Dialog 165fullWidth 166open = { open } 167onClose = { async () => { 168try { 169await Promise . all ([ 170window . electron . setChallongeKey ( challongeApiKey ), 171window . electron . setStartggKey ( startggApiKey ), 172window . electron . setParryggKey ( parryggApiKey ), 173window . electron . setFileNameFormat ( fileNameFormat ), 174window . electron . setFolderNameFormat ( folderNameFormat ), 175]); 176} catch ( e :any ) { 177showErrorDialog ([ e instanceof Error ?e . message :e ]); 178} 179if ( shouldGetTournaments ) { 180if ( 181( mode === Mode . STARTGG && startggApiKey ) || 182( mode === Mode . CHALLONGE && challongeApiKey ) || 183( mode === Mode . PARRYGG && parryggApiKey ) 184) { 185try { 186setAdminedTournaments ( await window . electron . getTournaments ()); 187} catch ( e :any ) { 188showErrorDialog ([ e instanceof Error ?e . message :e ]); 189} finally { 190setShouldGetTournaments ( false ); 191} 192} else { 193setAdminedTournaments ([]); 194setShouldGetTournaments ( false ); 195} 196} 197setOpen ( false ); 198}} 199> 200< Stack 201alignItems = "center" 202direction = "row" 203justifyContent = "space-between" 204marginRight = "24px" 205> 206< DialogTitle > Settings </ DialogTitle > 207< Typography variant = "caption" > 208Replay Reporter for Slippi version { appVersion } 209</ Typography > 210</ Stack > 211< DialogContent sx = {{ pt :0 }}> 212< Stack > 213< FormControl > 214< FormLabel id = "mode-radio-group-label" > Mode </ FormLabel > 215< RadioGroup 216aria-labelledby = "mode-radio-group-label" 217name = "mode-radio-group" 218row 219value = { mode } 220onChange = { async ( event :ChangeEvent < HTMLInputElement >) => { 221const newMode = event . target . value as Mode ; 222await window . electron . setMode ( newMode ); 223setMode ( newMode ); 224setShouldGetTournaments ( true ); 225}} 226> 227< LabeledRadioButton label = "start.gg" value = { Mode . STARTGG } /> 228< LabeledRadioButton label = "Challonge" value = { Mode . CHALLONGE } /> 229< LabeledRadioButton label = "parry.gg" value = { Mode . PARRYGG } /> 230< LabeledRadioButton 231label = "Offline Mode" 232value = { Mode . OFFLINE_MODE } 233/> 234< LabeledRadioButton label = "Manual" value = { Mode . MANUAL } /> 235</ RadioGroup > 236</ FormControl > 237</ Stack > 238{ mode === Mode . STARTGG && ( 239<> 240< DialogContentText > 241Get your start.gg API key by clicking “Create new token” in the 242< br /> 243“Personal Access Tokens” tab of { ' ' } 244< Link 245href = "https://start.gg/admin/profile/developer" 246target = "_blank" 247rel = "noreferrer" 248> 249this page 250</ Link > 251. Keep it private! 252</ DialogContentText > 253< Stack alignItems = "center" direction = "row" gap = "8px" > 254< TextField 255fullWidth 256label = "start.gg API key (Keep it private!)" 257onChange = {( event ) => { 258setStartggApiKey ( event . target . value ); 259setShouldGetTournaments ( true ); 260}} 261size = "small" 262type = "password" 263value = { startggApiKey } 264variant = "standard" 265/> 266< Button 267disabled = { copied } 268endIcon = { copied ?undefined :< ContentCopy />} 269onClick = { async () => { 270await window . electron . copyToClipboard ( startggApiKey ); 271setCopied ( true ); 272setTimeout (() => setCopied ( false ), 5000 ); 273}} 274variant = "contained" 275> 276{ copied ?'Copied!' :'Copy' } 277</ Button > 278</ Stack > 279</> 280)} 281{ mode === Mode . CHALLONGE && ( 282<> 283< DialogContentText > 284Get your Challonge v1 API key on { ' ' } 285< Link 286href = "https://challonge.com/settings/developer" 287target = "_blank" 288rel = "noreferrer" 289> 290this page 291</ Link >{ ' ' } 292(you may need to click “Generate a new API key”). Keep it 293private! 294</ DialogContentText > 295< Stack alignItems = "center" direction = "row" gap = "8px" > 296< TextField 297fullWidth 298label = "Challonge v1 API key (Keep it private!)" 299onChange = {( event ) => { 300setChallongeApiKey ( event . target . value ); 301setShouldGetTournaments ( true ); 302}} 303size = "small" 304type = "password" 305value = { challongeApiKey } 306variant = "standard" 307/> 308< Button 309disabled = { copied } 310endIcon = { copied ?undefined :< ContentCopy />} 311onClick = { async () => { 312await window . electron . copyToClipboard ( challongeApiKey ); 313setCopied ( true ); 314setTimeout (() => setCopied ( false ), 5000 ); 315}} 316variant = "contained" 317> 318{ copied ?'Copied!' :'Copy' } 319</ Button > 320</ Stack > 321</> 322)} 323{ mode === Mode . PARRYGG && ( 324<> 325< DialogContentText > 326Get your parry.gg API key from { ' ' } 327< Link href = "https://parry.gg" target = "_blank" rel = "noreferrer" > 328parry.gg 329</ Link > 330. Keep it private! 331</ DialogContentText > 332< Stack alignItems = "center" direction = "row" gap = "8px" > 333< TextField 334fullWidth 335label = "parry.gg API key (Keep it private!)" 336onChange = {( event ) => { 337setParryggApiKey ( event . target . value ); 338setShouldGetTournaments ( true ); 339}} 340size = "small" 341type = "password" 342value = { parryggApiKey } 343variant = "standard" 344/> 345< Button 346disabled = { copied } 347endIcon = { copied ?undefined :< ContentCopy />} 348onClick = { async () => { 349await window . electron . copyToClipboard ( parryggApiKey ); 350setCopied ( true ); 351setTimeout (() => setCopied ( false ), 5000 ); 352}} 353variant = "contained" 354> 355{ copied ?'Copied!' :'Copy' } 356</ Button > 357</ Stack > 358</> 359)} 360< Stack > 361< LabeledCheckbox 362checked = { guidedMode } 363label = "Use walkthrough mode" 364labelPlacement = "end" 365set = { async ( checked ) => { 366await window . electron . setGuidedMode ( checked ); 367setGuidedMode ( checked ); 368}} 369/> 370< Stack 371direction = "row" 372justifyContent = "space-between" 373alignItems = "center" 374> 375< LabeledCheckbox 376checked = { trashDir . length > 0 } 377disabled = { ! trashDir } 378label = { 379trashDir 380 ?'Using trash folder:' 381 :'Deleting replays permanently' 382} 383labelPlacement = "end" 384set = { async ( checked ) => { 385if ( ! checked ) { 386await window . electron . clearTrashDir (); 387setTrashDir ( '' ); 388} 389}} 390style = {{ flexShrink :0 }} 391/> 392{ trashDir ?( 393< Typography 394overflow = "hidden" 395textAlign = "left" 396textOverflow = "ellipsis" 397style = {{ direction :'rtl' , opacity :'0.5' }} 398variant = "caption" 399whiteSpace = "nowrap" 400> 401{ trashDir } 402</ Typography > 403) :( 404< Button 405disabled = { choosingTrashDir } 406endIcon = { 407choosingTrashDir ?( 408< CircularProgress size = "24px" /> 409) :undefined 410} 411onClick = { async () => { 412setChoosingTrashDir ( true ); 413try { 414setTrashDir ( await window . electron . chooseTrashDir ()); 415} catch { 416// just catch 417} finally { 418setChoosingTrashDir ( false ); 419} 420}} 421variant = "contained" 422> 423Set trash folder 424</ Button > 425)} 426</ Stack > 427< LabeledCheckbox 428checked = { vlerkMode } 429label = { 430< span > 431Use "Vlerk mode "for post tournament supplemental 432reporting, { ' ' } 433< Link 434href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/vlerk.md` } 435target = "_blank" 436rel = "noreferrer" 437> 438see more details 439</ Link > 440</ span > 441} 442labelPlacement = "end" 443set = { async ( checked ) => { 444await window . electron . setVlerkMode ( checked ); 445setVlerkMode ( checked ); 446}} 447/> 448< LabeledCheckbox 449checked = { useLAN } 450label = "Use LAN" 451labelPlacement = "end" 452set = { async ( checked ) => { 453await window . electron . setUseLAN ( checked ); 454setUseLAN ( checked ); 455}} 456/> 457{( mode === Mode . STARTGG || mode === Mode . OFFLINE_MODE ) && ( 458< LabeledCheckbox 459disabled = { hostFormat . smuggleCostumeIndex !== undefined } 460checked = { smuggleCostumeIndex } 461label = { 462< span > 463Report character color, { ' ' } 464< Link 465href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/color.md` } 466target = "_blank" 467rel = "noreferrer" 468> 469see more details 470</ Link > 471</ span > 472} 473labelPlacement = "end" 474set = { async ( checked ) => { 475await window . electron . setSmuggleCostumeIndex ( checked ); 476setSmuggleCostumeIndex ( checked ); 477}} 478/> 479)} 480< LabeledCheckbox 481checked = { hideCopyButton } 482label = "Hide Copy Button" 483labelPlacement = "end" 484set = { async ( checked ) => { 485await window . electron . setHideCopyButton ( checked ); 486setHideCopyButton ( checked ); 487}} 488/> 489< FormControl variant = "standard" style = {{ marginBottom :'8px' }}> 490< InputLabel id = "enforcer-setting-select-label" > 491SLP Enforcer { enforcerVersion } (logged to copy folder 492enforcer.csv) 493</ InputLabel > 494< Select 495labelId = "enforcer-setting-select-label" 496disabled = { hostFormat . enforcerSetting !== undefined } 497value = { enforcerSetting } 498onChange = { async ( event ) => { 499const newEnforcerSetting = event . target 500. value as EnforcerSetting ; 501await window . electron . setEnforcerSetting ( newEnforcerSetting ); 502setEnforcerSetting ( newEnforcerSetting ); 503}} 504> 505< MenuItem value = { EnforcerSetting . NONE }> Off </ MenuItem > 506< MenuItem value = { EnforcerSetting . LOG_ONLY }> Log Only </ MenuItem > 507< MenuItem value = { EnforcerSetting . POP_UP_GOOMWAVE }> 508Alert on Goomwave 509</ MenuItem > 510< MenuItem value = { EnforcerSetting . POP_UP_ALL }> 511Alert on All Violations 512</ MenuItem > 513</ Select > 514</ FormControl > 515< DialogContentText > 516File/Folder name format placeholders documented { ' ' } 517< Link 518href = { `https://github.com/jmlee337/replay-manager-for-slippi/blob/ ${ appVersion } /src/docs/format.md` } 519target = "_blank" 520rel = "noreferrer" 521> 522here 523</ Link > 524. 525</ DialogContentText > 526< Stack alignItems = "end" direction = "row" gap = "8px" > 527< TextField 528fullWidth 529disabled = { Boolean ( hostFormat . fileNameFormat )} 530label = "File name format" 531onChange = {( event ) => { 532const newFileNameFormat = event . target . value ; 533if ( newFileNameFormat ) { 534setFileNameFormat ( newFileNameFormat . slice ( 9 )); 535} 536}} 537size = "small" 538value = { `{ordinal} ${ fileNameFormat } ` } 539variant = "standard" 540/> 541< DialogContentText paddingBottom = "5px" > .slp </ DialogContentText > 542< Button 543disabled = { Boolean ( hostFormat . fileNameFormat )} 544onClick = { async () => { 545setFileNameFormat ( 546await window . electron . resetFileNameFormat (), 547); 548}} 549variant = "contained" 550> 551Reset 552</ Button > 553</ Stack > 554< Stack alignItems = "end" direction = "row" gap = "8px" > 555< TextField 556fullWidth 557disabled = { Boolean ( hostFormat . folderNameFormat )} 558label = "Folder name format" 559onChange = {( event ) => { 560const newFolderNameFormat = event . target . value ; 561if ( newFolderNameFormat ) { 562setFolderNameFormat ( newFolderNameFormat ); 563} 564}} 565size = "small" 566value = { folderNameFormat } 567variant = "standard" 568/> 569< Button 570disabled = { Boolean ( hostFormat . folderNameFormat )} 571onClick = { async () => { 572setFolderNameFormat ( 573await window . electron . resetFolderNameFormat (), 574); 575}} 576variant = "contained" 577> 578Reset 579</ Button > 580</ Stack > 581</ Stack > 582{ needUpdate && ( 583< Alert 584severity = "warning" 585style = {{ marginTop :'8px' }} 586action = { 587< Button 588endIcon = {< CloudDownload />} 589variant = "contained" 590onClick = {() => { 591window . electron . update (); 592}} 593> 594Quit and download 595</ Button > 596} 597> 598Update available! Version { latestAppVersion } 599</ Alert > 600)} 601</ DialogContent > 602</ Dialog > 603</> 604); 605}