From 04a095bc95f9396415d1271ee648fb159c7df2f8 Mon Sep 17 00:00:00 2001 From: FTCHD Date: Sat, 1 Feb 2025 21:26:58 +0200 Subject: [PATCH] functional mounts on windows --- lib/menu.ts | 38 +++++++++++++++++++++++++++----------- src/pages/Mount.tsx | 28 +++++++++++++++++++++------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/menu.ts b/lib/menu.ts index 47739bb..1c9b8f1 100644 --- a/lib/menu.ts +++ b/lib/menu.ts @@ -1,9 +1,11 @@ import { Menu, MenuItem, PredefinedMenuItem, Submenu } from '@tauri-apps/api/menu' import { getCurrentWindow } from '@tauri-apps/api/window' import { ask, message, open } from '@tauri-apps/plugin-dialog' +import { exists, remove } from '@tauri-apps/plugin-fs' import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification' import { sendNotification } from '@tauri-apps/plugin-notification' import { revealItemInDir } from '@tauri-apps/plugin-opener' +import { platform } from '@tauri-apps/plugin-os' import { exit } from '@tauri-apps/plugin-process' import { isDirectoryEmpty } from './fs' import { deleteRemote, mountRemote } from './rclone/api' @@ -127,19 +129,33 @@ export async function buildMenu() { console.log('selectedPath', selectedPath) - // Check if directory is empty - const isEmpty = await isDirectoryEmpty(selectedPath) - if (!isEmpty) { - // await resetMainWindow() + const directoryExists = await exists(selectedPath) - await message( - 'The selected directory must be empty to mount a remote.', - { - title: 'Mount Error', - kind: 'error', - } - ) + const isPlatformWindows = platform() === 'windows' + if (directoryExists || isPlatformWindows) { + const isEmpty = await isDirectoryEmpty(selectedPath) + if (!isEmpty) { + // await resetMainWindow() + await message( + 'The selected directory must be empty to mount a remote.', + { + title: 'Mount Error', + kind: 'error', + } + ) + + return + } + + if (isPlatformWindows) { + await remove(selectedPath) + } + } else { + await message('The selected directory does not exist.', { + title: 'Mount Error', + kind: 'error', + }) return } diff --git a/src/pages/Mount.tsx b/src/pages/Mount.tsx index 3a4ec9d..fbeb803 100644 --- a/src/pages/Mount.tsx +++ b/src/pages/Mount.tsx @@ -1,6 +1,7 @@ import { Accordion, AccordionItem, Avatar, Button } from '@nextui-org/react' import { getCurrentWindow } from '@tauri-apps/api/window' import { message } from '@tauri-apps/plugin-dialog' +import { exists, remove } from '@tauri-apps/plugin-fs' import { revealItemInDir } from '@tauri-apps/plugin-opener' import { platform } from '@tauri-apps/plugin-os' import { @@ -110,19 +111,32 @@ export default function Mount() { _mountOptions.VolumeName = source!.split('/').pop()! } - // Check if directory is empty - const isEmpty = await isDirectoryEmpty(dest!) - if (!isEmpty) { - // await resetMainWindow() + const directoryExists = await exists(dest!) - await message('The selected directory must be empty to mount a remote.', { + const isPlatformWindows = platform() === 'windows' + if (directoryExists || isPlatformWindows) { + const isEmpty = await isDirectoryEmpty(dest!) + if (!isEmpty) { + // await resetMainWindow() + + await message('The selected directory must be empty to mount a remote.', { + title: 'Mount Error', + kind: 'error', + }) + + return + } + + if (isPlatformWindows) { + await remove(dest!) + } + } else { + await message('The selected directory does not exist.', { title: 'Mount Error', kind: 'error', }) - return } - await mountRemote({ remotePath: source!, mountPoint: dest!,