mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-15 08:34:43 +01:00
proper setting and getting local files
This commit is contained in:
@@ -20,6 +20,7 @@ import { getConfigOption, setConfigOption } from '../utils/configuration'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
import { appWindow } from '@tauri-apps/api/window'
|
||||
import { convertFileSrc } from '@tauri-apps/api/tauri'
|
||||
|
||||
interface IProps {
|
||||
[key: string]: never;
|
||||
@@ -83,7 +84,8 @@ class App extends React.Component<IProps, IState> {
|
||||
if(game_path) {
|
||||
// Get the bg by invoking, then set the background to that bg.
|
||||
const bgLoc: string = await invoke('get_bg_file', {
|
||||
bgPath: root_path
|
||||
bgPath: root_path,
|
||||
appdata: await dataDir()
|
||||
})
|
||||
|
||||
bgLoc && this.setState({
|
||||
@@ -91,7 +93,7 @@ class App extends React.Component<IProps, IState> {
|
||||
}, this.forceUpdate)
|
||||
}
|
||||
} else this.setState({
|
||||
bgFile: custom_bg
|
||||
bgFile: convertFileSrc(custom_bg)
|
||||
}, this.forceUpdate)
|
||||
|
||||
if (!cert_generated) {
|
||||
|
||||
@@ -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/`
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user