proper setting and getting local files

This commit is contained in:
SpikeHD
2022-06-01 18:52:32 -07:00
parent a1f768140d
commit aedd7ecf3c
5 changed files with 34 additions and 19 deletions

View File

@@ -7,6 +7,7 @@ import { setConfigOption, getConfig, getConfigOption } from '../../../utils/conf
import Checkbox from '../common/Checkbox'
import Divider from './Divider'
import { invoke } from '@tauri-apps/api'
import { dataDir } from '@tauri-apps/api/path'
interface IProps {
closeFn: () => void;
@@ -82,12 +83,15 @@ export default class Options extends React.Component<IProps, IState> {
}
async setCustomBackground(value: string) {
setConfigOption('customBackground', value)
const filename = value.replace(/\\/g, '/').split('/').pop()
const localBgPath = (await dataDir() as string).replace(/\\/g, '/')
setConfigOption('customBackground', `${localBgPath}/cultivation/bg/${filename}`)
// Copy the file over to the local directory
invoke('copy_file', {
path: value.replace(/\\/g, '/'),
newPath: await invoke('get_local_bg_path')
newPath: `${localBgPath}cultivation/bg/`
})
}