validate url backgrounds

This commit is contained in:
SpikeHD
2022-06-01 19:20:43 -07:00
parent fe48eb3c67
commit e71ca9ff40
3 changed files with 21 additions and 3 deletions

View File

@@ -35,6 +35,8 @@ interface IState {
bgFile: string;
}
const DEFAULT_BG = 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png'
const downloadHandler = new DownloadHandler()
class App extends React.Component<IProps, IState> {
@@ -46,7 +48,7 @@ class App extends React.Component<IProps, IState> {
miniDownloadsOpen: false,
downloadsOpen: false,
gameDownloadsOpen: false,
bgFile: 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png',
bgFile: DEFAULT_BG,
}
listen('lang_error', (payload) => {
@@ -100,8 +102,13 @@ class App extends React.Component<IProps, IState> {
bgFile: convertFileSrc(custom_bg)
}, this.forceUpdate)
} else {
// Check if URL returns a valid image.
const isValid = await invoke('valid_url', {
url: custom_bg
})
this.setState({
bgFile: custom_bg
bgFile: isValid ? custom_bg : DEFAULT_BG
}, this.forceUpdate)
}
}