windows startup fixes #38
Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com>
This commit is contained in:
+44
-28
@@ -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<boolean>} True if rclone is installed and working
|
||||
|
||||
@@ -13,3 +13,5 @@ export const RCLONE_VFS_DEFAULTS = {
|
||||
'ChunkSize': '4M',
|
||||
'ChunkStreams': 16,
|
||||
}
|
||||
|
||||
export const RCLONE_CONF_REGEX = /\/rclone\.conf$/
|
||||
|
||||
+12
-11
@@ -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(
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user