From 54d400d67b00397c430a5f3eebc41b4226fbfa4a Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 19:04:21 -0700 Subject: [PATCH] differ between URL and file custom bg --- src/ui/App.tsx | 19 ++++++++++++++++--- src/ui/components/menu/Options.tsx | 29 ++++++++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index be28e0e..2d6cb6e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -92,9 +92,22 @@ class App extends React.Component { bgFile: bgLoc }, this.forceUpdate) } - } else this.setState({ - bgFile: convertFileSrc(custom_bg) - }, this.forceUpdate) + } else { + const isUrl = /^(?:http(s)?:\/\/)/gm.test(custom_bg) + + console.log(isUrl) + + + if (!isUrl) { + this.setState({ + bgFile: convertFileSrc(custom_bg) + }, this.forceUpdate) + } else { + this.setState({ + bgFile: custom_bg + }, this.forceUpdate) + } + } if (!cert_generated) { // Generate the certificate diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index 5f4a053..de66999 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -84,18 +84,25 @@ export default class Options extends React.Component { } async setCustomBackground(value: string) { - const filename = value.replace(/\\/g, '/').split('/').pop() - const localBgPath = (await dataDir() as string).replace(/\\/g, '/') + const isUrl = /^(?:http(s)?:\/\/)/gm.test(value) - await setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) - - // Copy the file over to the local directory - await invoke('copy_file', { - path: value.replace(/\\/g, '/'), - newPath: `${localBgPath}cultivation/bg/` - }) - - window.location.reload() + if (!isUrl) { + const filename = value.replace(/\\/g, '/').split('/').pop() + const localBgPath = (await dataDir() as string).replace(/\\/g, '/') + + await setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`) + + // Copy the file over to the local directory + await invoke('copy_file', { + path: value.replace(/\\/g, '/'), + newPath: `${localBgPath}cultivation/bg/` + }) + + window.location.reload() + } else { + await setConfigOption('customBackground', value) + window.location.reload() + } } render() {