diff --git a/lib/format.ts b/lib/format.ts index 6ec9728..9606db4 100644 --- a/lib/format.ts +++ b/lib/format.ts @@ -46,3 +46,19 @@ export function buildReadablePath(path: string, type: 'short' | 'long' = 'long') return `${path.split(':')[0]}:/.../${lastSegment}` } + +export function getConfigParentFolder(path: string) { + console.log('[getConfigParentFolder] path', path) + if (path.endsWith('\\rclone.conf')) { + console.log('[getConfigParentFolder] path ends with \\rclone.conf') + return path.slice(0, -11) + } + + if (path.endsWith('/rclone.conf')) { + console.log('[getConfigParentFolder] path ends with /rclone.conf') + return path.slice(0, -11) + } + + console.log('[getConfigParentFolder] path does not end with \\rclone.conf or /rclone.conf') + return path +} diff --git a/lib/rclone/common.ts b/lib/rclone/common.ts index 657d65b..984bd52 100644 --- a/lib/rclone/common.ts +++ b/lib/rclone/common.ts @@ -2,7 +2,8 @@ import { appLocalDataDir, sep } from '@tauri-apps/api/path' import { exists, mkdir, writeTextFile } from '@tauri-apps/plugin-fs' import { fetch } from '@tauri-apps/plugin-http' import { Command } from '@tauri-apps/plugin-shell' -import { DOUBLE_BACKSLASH_REGEX, RCLONE_CONF_REGEX } from './constants' +import { getConfigParentFolder } from '../format' +import { DOUBLE_BACKSLASH_REGEX } from './constants' export async function getDefaultPaths() { console.log('[getDefaultPaths]') @@ -115,7 +116,7 @@ export async function createConfigFile(path: string) { '[createConfigFile] failed to write space character to default path (1)', path ) - const folderPath = path.replace(RCLONE_CONF_REGEX, '') + const folderPath = getConfigParentFolder(path) console.log('[createConfigFile] creating folder', folderPath) await mkdir(folderPath, { recursive: true }) console.log('[createConfigFile] created folder', folderPath) diff --git a/lib/rclone/init.ts b/lib/rclone/init.ts index 8da8297..6984eb7 100644 --- a/lib/rclone/init.ts +++ b/lib/rclone/init.ts @@ -9,6 +9,7 @@ import { fetch } from '@tauri-apps/plugin-http' import { platform } from '@tauri-apps/plugin-os' import { exit } from '@tauri-apps/plugin-process' import { Command } from '@tauri-apps/plugin-shell' +import { getConfigParentFolder } from '../format' import { usePersistedStore, useStore } from '../store' import { openSmallWindow } from '../window' import { @@ -19,7 +20,6 @@ import { isSystemRcloneInstalled, shouldUpdateRclone, } from './common' -import { RCLONE_CONF_REGEX } from './constants' export async function initRclone(args: string[]) { console.log('[initRclone]') @@ -128,10 +128,7 @@ export async function initRclone(args: string[]) { let configFolderPath = activeConfigFile.sync ? activeConfigFile.sync - : (await getConfigPath({ id: activeConfigFile.id!, validate: true })).replace( - RCLONE_CONF_REGEX, - '' - ) + : getConfigParentFolder(await getConfigPath({ id: activeConfigFile.id!, validate: true })) console.log('[initRclone] configFolderPath', configFolderPath) @@ -143,9 +140,8 @@ export async function initRclone(args: string[]) { okLabel: 'OK', }) activeConfigFile = configFiles[0] - configFolderPath = (await getConfigPath({ id: 'default', validate: true })).replace( - RCLONE_CONF_REGEX, - '' + configFolderPath = getConfigParentFolder( + await getConfigPath({ id: 'default', validate: true }) ) usePersistedStore.setState({ activeConfigFile: configFiles[0] }) } diff --git a/lib/window.ts b/lib/window.ts index 3caa6e7..e7a64f5 100644 --- a/lib/window.ts +++ b/lib/window.ts @@ -67,6 +67,7 @@ export async function openFullWindow({ await w.center() await w.setZoom(1) await w.show() + await w.setFocus() return w } @@ -111,6 +112,7 @@ export async function openWindow({ await w.setDecorations(true) await w.setZoom(1) await w.show() + await w.setFocus() useStore.setState({ firstWindow: false }) @@ -150,6 +152,7 @@ export async function openSmallWindow({ await w.center() await w.setZoom(1) await w.show() + await w.setFocus() useStore.setState({ firstWindow: false })