windows startup fixes #38

Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com>
This commit is contained in:
FTCHD
2025-09-22 18:45:53 +02:00
parent f28a3b3ce1
commit 5122e46b74
4 changed files with 64 additions and 39 deletions
+44 -28
View File
@@ -1,7 +1,9 @@
import * as Sentry from '@sentry/browser'
import { appLocalDataDir, sep } from '@tauri-apps/api/path' 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 { fetch } from '@tauri-apps/plugin-http'
import { Command } from '@tauri-apps/plugin-shell' import { Command } from '@tauri-apps/plugin-shell'
import { RCLONE_CONF_REGEX } from './constants'
export async function getDefaultPaths() { export async function getDefaultPaths() {
console.log('[getDefaultPaths]') console.log('[getDefaultPaths]')
@@ -28,30 +30,15 @@ export async function getDefaultPaths() {
} }
} }
export async function getDefaultPath(type: 'system' | 'internal') { export async function getSystemConfigPath() {
console.log('[getDefaultPath]', type) console.log('[getDefaultPath] running system rclone')
const instance = Command.create('rclone-system', [
let instance = null 'rcd',
if (type === 'system') { '--rc-no-auth',
console.log('[getDefaultPath] running system rclone') '--rc-serve',
instance = Command.create('rclone-system', [ // '-rc-addr',
'rcd', // ':5572',
'--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',
])
}
if (!instance) { if (!instance) {
console.error('[getDefaultPath] failed to create rclone 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) console.log('[getConfigPath] configPath', configPath)
if (id == 'default') { if (id == 'default' && (await isSystemRcloneInstalled())) {
const system = await isSystemRcloneInstalled() const defaultPath = await getSystemConfigPath()
const defaultPath = await getDefaultPath(system ? 'system' : 'internal')
configPath = defaultPath configPath = defaultPath
console.log('[getConfigPath] configPath', configPath)
} }
if (validate) { if (validate) {
@@ -111,6 +98,35 @@ export async function getConfigPath({ id, validate = true }: { id: string; valid
return configPath 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 * Checks if rclone is installed and accessible from the system PATH
* @returns {Promise<boolean>} True if rclone is installed and working * @returns {Promise<boolean>} True if rclone is installed and working
+2
View File
@@ -13,3 +13,5 @@ export const RCLONE_VFS_DEFAULTS = {
'ChunkSize': '4M', 'ChunkSize': '4M',
'ChunkStreams': 16, 'ChunkStreams': 16,
} }
export const RCLONE_CONF_REGEX = /\/rclone\.conf$/
+12 -11
View File
@@ -12,14 +12,14 @@ import { Command } from '@tauri-apps/plugin-shell'
import { usePersistedStore, useStore } from '../store' import { usePersistedStore, useStore } from '../store'
import { openSmallWindow } from '../window' import { openSmallWindow } from '../window'
import { import {
createConfigFile,
getConfigPath, getConfigPath,
getDefaultPath, getSystemConfigPath,
isInternalRcloneInstalled, isInternalRcloneInstalled,
isSystemRcloneInstalled, isSystemRcloneInstalled,
shouldUpdateRclone, shouldUpdateRclone,
} from './common' } from './common'
import { RCLONE_CONF_REGEX } from './constants'
const RCLONE_CONF_REGEX = /\/rclone\.conf$/
export async function initRclone(args: string[]) { export async function initRclone(args: string[]) {
console.log('[initRclone]') console.log('[initRclone]')
@@ -93,16 +93,12 @@ export async function initRclone(args: string[]) {
const persistedState = usePersistedStore.getState() const persistedState = usePersistedStore.getState()
let configFiles = persistedState.configFiles || [] let configFiles = persistedState.configFiles || []
let activeConfigFile = persistedState.activeConfigFile let activeConfigFile = persistedState.activeConfigFile
const defaultPath = await getDefaultPath(system ? 'system' : 'internal')
console.log('[initRclone] defaultPath', defaultPath)
if (system) { if (system) {
const hasConfig = await exists(defaultPath).catch(() => false) const defaultPath = await getSystemConfigPath()
if (!hasConfig) { console.log('[initRclone] defaultPath', defaultPath)
// const data = new Uint8Array([32]) // ASCII code for space character
await writeFile(defaultPath, new Uint8Array([])) await createConfigFile(defaultPath)
}
} }
configFiles = configFiles.filter((config) => config.id !== 'default') configFiles = configFiles.filter((config) => config.id !== 'default')
@@ -125,6 +121,11 @@ export async function initRclone(args: string[]) {
usePersistedStore.setState({ activeConfigFile }) usePersistedStore.setState({ activeConfigFile })
} }
if (internal && activeConfigFile.id === 'default') {
const defaultInternalPath = await getConfigPath({ id: 'default', validate: false })
await createConfigFile(defaultInternalPath)
}
let configFolderPath = activeConfigFile.sync let configFolderPath = activeConfigFile.sync
? activeConfigFile.sync ? activeConfigFile.sync
: (await getConfigPath({ id: activeConfigFile.id!, validate: true })).replace( : (await getConfigPath({ id: activeConfigFile.id!, validate: true })).replace(
+6
View File
@@ -219,6 +219,9 @@ async function startRclone() {
} }
await childProcess.kill() await childProcess.kill()
await new Promise((resolve) => setTimeout(resolve, 1000))
await exit(0) await exit(0)
}) })
console.log('[startRclone] set listener for close-app') console.log('[startRclone] set listener for close-app')
@@ -241,6 +244,9 @@ async function startRclone() {
} }
await childProcess.kill() await childProcess.kill()
await new Promise((resolve) => setTimeout(resolve, 1000))
await relaunch() await relaunch()
}) })
console.log('[startRclone] set listener for relaunch-app') console.log('[startRclone] set listener for relaunch-app')