fix dialog clicking

This commit is contained in:
SpikeHD
2022-06-05 21:11:53 -07:00
parent e9a7852456
commit c06cf874b5
4 changed files with 23 additions and 1 deletions

View File

@@ -22,4 +22,9 @@ pub fn rename(path: String, new_name: String) {
#[tauri::command]
pub fn dir_exists(path: &str) -> bool {
return fs::metadata(&path).is_ok();
}
#[tauri::command]
pub fn dir_is_empty(path: &str) -> bool {
return fs::read_dir(&path).unwrap().count() == 0;
}

View File

@@ -56,6 +56,7 @@ fn main() {
unzip::unzip,
file_helpers::rename,
file_helpers::dir_exists,
file_helpers::dir_is_empty,
downloader::download_file,
downloader::stop_download,
lang::get_lang,

View File

@@ -16,7 +16,14 @@ export default class MiniDialog extends React.Component<IProps, never> {
}
componentDidMount() {
document.addEventListener('mousedown', this.props.closeFn)
document.addEventListener('mousedown', (evt) => {
const tgt = evt.target as HTMLElement
const isInside = tgt.closest('.MiniDialog') !== null
if (!isInside) {
this.props.closeFn()
}
})
}
componentWillUnmount() {

View File

@@ -149,6 +149,15 @@ export default class Downloads extends React.Component<IProps, IState> {
async downloadResources() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(RESOURCES_DOWNLOAD, folder + '\\resources.zip', async () => {
// Delete the existing folder if it exists
if (await invoke('dir_exists', {
path: folder + '\\resources'
})) {
await invoke('delete_dir', {
path: folder + '\\resources'
})
}
await unzip(folder + '\\resources.zip', folder + '\\', () => {
// Rename folder to resources
invoke('rename', {