From 5122e46b74e6633b9a5419b57e7a232b9a01705e Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Mon, 22 Sep 2025 18:45:53 +0200 Subject: [PATCH] windows startup fixes #38 Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com> --- lib/rclone/common.ts | 72 +++++++++++++++++++++++++---------------- lib/rclone/constants.ts | 2 ++ lib/rclone/init.ts | 23 ++++++------- main.ts | 6 ++++ 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/lib/rclone/common.ts b/lib/rclone/common.ts index 818c7f5..04c29b7 100644 --- a/lib/rclone/common.ts +++ b/lib/rclone/common.ts @@ -1,7 +1,9 @@ +import * as Sentry from '@sentry/browser' import { appLocalDataDir, sep } from '@tauri-apps/api/path' -import { exists } from '@tauri-apps/plugin-fs' +import { exists, mkdir, writeFile } from '@tauri-apps/plugin-fs' import { fetch } from '@tauri-apps/plugin-http' import { Command } from '@tauri-apps/plugin-shell' +import { RCLONE_CONF_REGEX } from './constants' export async function getDefaultPaths() { console.log('[getDefaultPaths]') @@ -28,30 +30,15 @@ export async function getDefaultPaths() { } } -export async function getDefaultPath(type: 'system' | 'internal') { - console.log('[getDefaultPath]', type) - - let instance = null - if (type === 'system') { - console.log('[getDefaultPath] running system rclone') - instance = Command.create('rclone-system', [ - 'rcd', - '--rc-no-auth', - '--rc-serve', - // '-rc-addr', - // ':5572', - ]) - } - if (type === 'internal') { - console.log('[getDefaultPath] running internal rclone') - instance = Command.create('rclone-internal', [ - 'rcd', - '--rc-no-auth', - '--rc-serve', - // '-rc-addr', - // ':5572', - ]) - } +export async function getSystemConfigPath() { + console.log('[getDefaultPath] running system rclone') + const instance = Command.create('rclone-system', [ + 'rcd', + '--rc-no-auth', + '--rc-serve', + // '-rc-addr', + // ':5572', + ]) if (!instance) { console.error('[getDefaultPath] failed to create rclone instance') @@ -93,11 +80,11 @@ export async function getConfigPath({ id, validate = true }: { id: string; valid console.log('[getConfigPath] configPath', configPath) - if (id == 'default') { - const system = await isSystemRcloneInstalled() - const defaultPath = await getDefaultPath(system ? 'system' : 'internal') + if (id == 'default' && (await isSystemRcloneInstalled())) { + const defaultPath = await getSystemConfigPath() configPath = defaultPath + console.log('[getConfigPath] configPath', configPath) } if (validate) { @@ -111,6 +98,35 @@ export async function getConfigPath({ id, validate = true }: { id: string; valid return configPath } +export async function createConfigFile(path: string) { + console.log('[createConfigFile] path', path) + + const hasConfig = await exists(path).catch(() => false) + console.log('[createConfigFile] hasConfig', hasConfig) + if (!hasConfig) { + console.log('[createConfigFile] writing space character to default path') + await writeFile(path, new Uint8Array([32])) // ASCII code for space character + + if (!(await exists(path).catch(() => false))) { + console.log('[createConfigFile] failed to write space character to default path') + Sentry.captureException( + new Error('CONFIG_PATH: Failed to write space character to default path') + ) + const folderPath = path.replace(RCLONE_CONF_REGEX, '') + console.log('[createConfigFile] creating folder') + await mkdir(folderPath, { recursive: true }) + await writeFile(path, new Uint8Array([32])) + const existsFinally = await exists(path).catch(() => false) + console.log('[createConfigFile] existsFinally', existsFinally) + Sentry.captureException( + new Error( + 'CONFIG_PATH: Status after folder creation: ' + existsFinally ? 'true' : 'false' + ) + ) + } + } +} + /** * Checks if rclone is installed and accessible from the system PATH * @returns {Promise} True if rclone is installed and working diff --git a/lib/rclone/constants.ts b/lib/rclone/constants.ts index 15bf8bf..9610ac5 100644 --- a/lib/rclone/constants.ts +++ b/lib/rclone/constants.ts @@ -13,3 +13,5 @@ export const RCLONE_VFS_DEFAULTS = { 'ChunkSize': '4M', 'ChunkStreams': 16, } + +export const RCLONE_CONF_REGEX = /\/rclone\.conf$/ diff --git a/lib/rclone/init.ts b/lib/rclone/init.ts index b8025ef..59ac08c 100644 --- a/lib/rclone/init.ts +++ b/lib/rclone/init.ts @@ -12,14 +12,14 @@ import { Command } from '@tauri-apps/plugin-shell' import { usePersistedStore, useStore } from '../store' import { openSmallWindow } from '../window' import { + createConfigFile, getConfigPath, - getDefaultPath, + getSystemConfigPath, isInternalRcloneInstalled, isSystemRcloneInstalled, shouldUpdateRclone, } from './common' - -const RCLONE_CONF_REGEX = /\/rclone\.conf$/ +import { RCLONE_CONF_REGEX } from './constants' export async function initRclone(args: string[]) { console.log('[initRclone]') @@ -93,16 +93,12 @@ export async function initRclone(args: string[]) { const persistedState = usePersistedStore.getState() let configFiles = persistedState.configFiles || [] let activeConfigFile = persistedState.activeConfigFile - const defaultPath = await getDefaultPath(system ? 'system' : 'internal') - - console.log('[initRclone] defaultPath', defaultPath) if (system) { - const hasConfig = await exists(defaultPath).catch(() => false) - if (!hasConfig) { - // const data = new Uint8Array([32]) // ASCII code for space character - await writeFile(defaultPath, new Uint8Array([])) - } + const defaultPath = await getSystemConfigPath() + console.log('[initRclone] defaultPath', defaultPath) + + await createConfigFile(defaultPath) } configFiles = configFiles.filter((config) => config.id !== 'default') @@ -125,6 +121,11 @@ export async function initRclone(args: string[]) { usePersistedStore.setState({ activeConfigFile }) } + if (internal && activeConfigFile.id === 'default') { + const defaultInternalPath = await getConfigPath({ id: 'default', validate: false }) + await createConfigFile(defaultInternalPath) + } + let configFolderPath = activeConfigFile.sync ? activeConfigFile.sync : (await getConfigPath({ id: activeConfigFile.id!, validate: true })).replace( diff --git a/main.ts b/main.ts index 30ef422..53d94b0 100644 --- a/main.ts +++ b/main.ts @@ -219,6 +219,9 @@ async function startRclone() { } await childProcess.kill() + + await new Promise((resolve) => setTimeout(resolve, 1000)) + await exit(0) }) console.log('[startRclone] set listener for close-app') @@ -241,6 +244,9 @@ async function startRclone() { } await childProcess.kill() + + await new Promise((resolve) => setTimeout(resolve, 1000)) + await relaunch() }) console.log('[startRclone] set listener for relaunch-app')