From 90999d77a35ef6dd4e772d5d829d624c65a07adf Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 21 Sep 2023 13:07:14 -0700 Subject: [PATCH 1/2] Clean up conversion / stub folders whenever the app is closed --- src/main/main.ts | 31 +++++++++++++++++++++++++++++++ src/renderer/src/index.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/main.ts b/src/main/main.ts index 08b915698..ebee64770 100755 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,6 +1,8 @@ import { app, BrowserWindow, dialog, shell } from 'electron'; import { electronApp, optimizer, is } from '@electron-toolkit/utils' +import paths from '../../paths.config.json' + import main from '@electron/remote/main'; main.initialize() @@ -393,8 +395,37 @@ app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) initialize() }) + +const homeDirectory = app.getPath("home"); +const appDirectory = path.join(homeDirectory, paths.root) +const guidedProgressFilePath = path.join(appDirectory, ...paths.subfolders.progress); +const guidedConversionFolderPath = path.join(appDirectory, ...paths.subfolders.conversions); +const guidedStubFolderPath = path.join(appDirectory, ...paths.subfolders.stubs); + +function getEntries(path, type = 'isDirectory') { + return fs.readdirSync(path, { withFileTypes: true }) + .filter(dirent => dirent[type]()) + .map(dirent => dirent.name) +} + + +// This function removes all folders that don't have a corresponding pipeline (specifically DANDI temp folders—but also any folders left after a pipeline is deleted) +function deleteFoldersWithoutPipelines() { + const conversionDirectories = getEntries(guidedConversionFolderPath) + const stubDirectories = getEntries(guidedStubFolderPath) + + const allowedDirectories = getEntries(guidedProgressFilePath, 'isFile').map(name => name.slice(0, -'.json'.length)) + const conversionsToRemove = conversionDirectories.filter(name => !allowedDirectories.includes(name)) + const stubsToRemove = stubDirectories.filter(name => !allowedDirectories.includes(name)) + + conversionsToRemove.forEach(name => fs.rmSync(path.join(guidedConversionFolderPath, name), { recursive: true })) + stubsToRemove.forEach(name => fs.rmSync(path.join(guidedStubFolderPath, name), { recursive: true })) +} + + app.on('will-quit', async () => { try { + deleteFoldersWithoutPipelines() await exitPyProc() if (globals.mainWindow) { globals.mainWindow.close(); diff --git a/src/renderer/src/index.ts b/src/renderer/src/index.ts index c13b6f258..9fb9513d8 100644 --- a/src/renderer/src/index.ts +++ b/src/renderer/src/index.ts @@ -138,7 +138,7 @@ async function pythonServerClosed(message?: string) { allowEscapeKey: false, }); - if (isElectron) app.exit(); + if (isElectron) app.quit(); else location.reload() Swal.close(); From a3ee993aea276ca4d23f948e3013fbd0d66ebb72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:12:56 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/main/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/main.ts b/src/main/main.ts index ebee64770..227a80e45 100755 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -417,7 +417,7 @@ function deleteFoldersWithoutPipelines() { const allowedDirectories = getEntries(guidedProgressFilePath, 'isFile').map(name => name.slice(0, -'.json'.length)) const conversionsToRemove = conversionDirectories.filter(name => !allowedDirectories.includes(name)) const stubsToRemove = stubDirectories.filter(name => !allowedDirectories.includes(name)) - + conversionsToRemove.forEach(name => fs.rmSync(path.join(guidedConversionFolderPath, name), { recursive: true })) stubsToRemove.forEach(name => fs.rmSync(path.join(guidedStubFolderPath, name), { recursive: true })) }