Cleanup command

Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com>
This commit is contained in:
FTCHD
2025-08-13 00:11:33 +02:00
parent 7e5d350676
commit ff75f1bc58
4 changed files with 69 additions and 2 deletions
+24 -1
View File
@@ -8,7 +8,7 @@ import { openPath } 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, unmountRemote } from './rclone/api'
import { cleanupRemote, deleteRemote, mountRemote, unmountRemote } from './rclone/api'
import { dialogGetMountPlugin, needsMountPlugin } from './rclone/mount'
import { usePersistedStore, useStore } from './store'
import { getLoadingTray, getMainTray, rebuildTrayMenu } from './tray'
@@ -259,6 +259,29 @@ async function parseRemotes(remotes: string[]) {
submenuItems.push(browseMenuItem)
}
if (!remoteConfig?.disabledActions?.includes('tray-cleanup')) {
const cleanupMenuItem = await MenuItem.new({
id: `cleanup-${remote}`,
text: 'Cleanup',
action: async () => {
try {
await cleanupRemote(remote)
await message(`Cleanup started for ${remote}`, {
title: 'Cleanup Started',
okLabel: 'OK',
})
} catch (error) {
await message(`Failed to start cleanup job, ${error}`, {
title: 'Cleanup Error',
kind: 'error',
okLabel: 'OK',
})
}
},
})
submenuItems.push(cleanupMenuItem)
}
if (!remoteConfig?.disabledActions?.includes('tray-remove')) {
const removeMenuItem = await MenuItem.new({
id: `remove-${remote}`,
+15
View File
@@ -109,6 +109,21 @@ export async function deleteRemote(remote: string) {
// console.log(JSON.stringify(r, null, 2))
}
export async function cleanupRemote(remote: string) {
console.log('[cleanupRemote]', remote)
const r = await fetch(`http://localhost:5572/operations/cleanup?fs=${remote}&_async=true`, {
method: 'POST',
headers: getAuthHeader(),
})
if (!r.ok) {
throw new Error('Failed to start cleanup job')
}
// console.log(JSON.stringify(r, null, 2))
}
export async function getMountPoints() {
console.log('[getMountPoints]')
+1 -1
View File
@@ -9,7 +9,7 @@ import type { ScheduledTask } from '../types/task'
const store = new LazyStore('store.json')
export interface RemoteConfig {
disabledActions?: ('tray' | 'tray-mount' | 'tray-browse' | 'tray-remove')[]
disabledActions?: ('tray' | 'tray-mount' | 'tray-browse' | 'tray-remove' | 'tray-cleanup')[]
defaultRemotePath?: string
defaultMountPoint?: string
+29
View File
@@ -255,6 +255,35 @@ export default function RemoteDefaultsDrawer({
<span className="font-mono text-blue-300">Browse</span>{' '}
option
</Checkbox>
<Checkbox
isSelected={
!config?.disabledActions?.includes('tray-cleanup')
}
onValueChange={(value) => {
if (value) {
setConfig((prev) => ({
...prev,
disabledActions:
prev?.disabledActions?.filter(
(action) =>
action !== 'tray-cleanup'
),
}))
} else {
setConfig((prev) => ({
...prev,
disabledActions: [
...(prev?.disabledActions || []),
'tray-cleanup',
],
}))
}
}}
>
Show{' '}
<span className="font-mono text-blue-300">Cleanup</span>{' '}
option
</Checkbox>
<Checkbox
isSelected={
!config?.disabledActions?.includes('tray-remove')